On 06/06/17 20:52, Andrew Stubbs wrote:
Thomas objects to the new option, and after talking with him the reasoning seems sound. GCC has been moving away from -mcpu in any case, so I guess I'll put -march and -mtune back, and use those for the same purpose.

I'll commit the patch with those changes soonish.

I've finally got around to pushing the patch.

It now uses -march to set the GPU name.

Andrew

Switch to HSACO2

2017-06-21  Andrew Stubbs  <a...@codesourcery.com>

	gcc/
	* config.gcc (amdgcn): Set default to "carrizo"
	* config/gcn/gcn-opts.h: New file.
	* config/gcn/gcn.c (output_file_start): Switch to HSACO version
	2 and auto-detection of GPU type (from -mcpu).
	(gcn_arch, gcn_tune): Remove.
	* config/gcn/gcn.h: Include gcn-opts.h.
	(enum processor_type): Move to gcn-opts.h.
	(LIBGCC_SPEC, ASM_SPEC, LINK_SPEC): Define.
	(gcn_arch, gcn_tune): Remove.
	* config/gcn/gcn.opt: Include gcn-opts.h.
	(gpu_type): New Enum.
	(march, mtune): New options.

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 32f0f4b..99c9c4a 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -3930,7 +3930,7 @@ case "${target}" in
 		for which in arch tune; do
 			eval "val=\$with_$which"
 			case ${val} in
-			"" | fiji)
+			"" | carrizo | fiji)
 				# OK
 				;;
 			*)
@@ -3939,6 +3939,7 @@ case "${target}" in
 				;;
 			esac
 		done
+		[ "x$with_arch" = x ] && with_arch=carrizo
 		;;
 
 	hppa*-*-*)
diff --git a/gcc/config/gcn/gcn-opts.h b/gcc/config/gcn/gcn-opts.h
new file mode 100644
index 0000000..d0586d6
--- /dev/null
+++ b/gcc/config/gcn/gcn-opts.h
@@ -0,0 +1,27 @@
+/* Copyright (C) 2016-2017 Free Software Foundation, Inc.
+
+   This file is free software; you can redistribute it and/or modify it under
+   the terms of the GNU General Public License as published by the Free
+   Software Foundation; either version 3 of the License, or (at your option)
+   any later version.
+
+   This file is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+   for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef GCN_OPTS_H
+#define GCN_OPTS_H
+
+/* Which processor to generate code or schedule for.  */
+enum processor_type
+{
+  PROCESSOR_CARRIZO,
+  PROCESSOR_FIJI
+};
+
+#endif
diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index eb6edd8..c80bdf5 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -60,11 +60,6 @@
 /* This file should be included last.  */
 #include "target-def.h"
 
-/* Which instruction set architecture to use.  */
-int gcn_arch;
-/* Which cpu are we tuning for.  */
-int gcn_tune;
-
 static REAL_VALUE_TYPE dconst4, dconst1over2pi;
 static bool ext_gcn_constants_init = 0;
 
@@ -2006,8 +2001,8 @@ static void
 output_file_start (void)
 {
   fprintf (asm_out_file, "\t.hsatext\n");
-  fprintf (asm_out_file, "\t.hsa_code_object_version 1,0\n");
-  fprintf (asm_out_file, "\t.hsa_code_object_isa 8,0,1,\"AMD\",\"AMDGPU\"\n");
+  fprintf (asm_out_file, "\t.hsa_code_object_version 2,0\n");
+  fprintf (asm_out_file, "\t.hsa_code_object_isa\n");  /* Autodetect.  */
   fprintf (asm_out_file, "\t.section\t.AMDGPU.config\n");
   fprintf (asm_out_file, "\t.hsatext\n");
 }
diff --git a/gcc/config/gcn/gcn.h b/gcc/config/gcn/gcn.h
index 903022f..3b41095 100644
--- a/gcc/config/gcn/gcn.h
+++ b/gcc/config/gcn/gcn.h
@@ -14,18 +14,22 @@
    along with GCC; see the file COPYING3.  If not see
    <http://www.gnu.org/licenses/>.  */
 
+#include "config/gcn/gcn-opts.h"
+
 
 /* FIXME */
 #define TARGET_CPU_CPP_BUILTINS()
 
-/* Which processor to generate code or schedule for.  */
-enum processor_type
-{
-  PROCESSOR_CARRIZO,
-};
+/* Temporarily disable libgcc until one actually exists.  */
+#undef  LIBGCC_SPEC
+#define LIBGCC_SPEC ""
+
+/* Use LLVM assembler options.  */
+#undef ASM_SPEC
+#define ASM_SPEC "-triple=amdgcn--amdhsa %{march=*:-mcpu=%*} -filetype=obj"
 
-extern GTY(()) int gcn_arch;
-extern GTY(()) int gcn_tune;
+#undef LINK_SPEC
+#define LINK_SPEC ""
 
 /* Support for a compile-time default architecture and tuning.  The rules are:
    --with-arch is ignored if -march is specified.
diff --git a/gcc/config/gcn/gcn.opt b/gcc/config/gcn/gcn.opt
index 8fc02b7..ffb5547 100644
--- a/gcc/config/gcn/gcn.opt
+++ b/gcc/config/gcn/gcn.opt
@@ -17,3 +17,24 @@
 ; You should have received a copy of the GNU General Public License
 ; along with GCC; see the file COPYING3.  If not see
 ; <http://www.gnu.org/licenses/>.
+
+HeaderInclude
+config/gcn/gcn-opts.h
+
+Enum
+Name(gpu_type) Type(enum processor_type)
+GCN GPU type to use:
+
+EnumValue
+Enum(gpu_type) String(carrizo) Value(PROCESSOR_CARRIZO)
+
+EnumValue
+Enum(gpu_type) String(fiji) Value(PROCESSOR_FIJI)
+
+march=
+Target RejectNegative Joined ToLower Enum(gpu_type) Var(gcn_arch) Init(PROCESSOR_CARRIZO)
+Specify the name of the target GPU.
+
+mtune=
+Target RejectNegative Joined ToLower Enum(gpu_type) Var(gcn_tune) Init(PROCESSOR_CARRIZO)
+Specify the name of the target GPU.

Reply via email to