Re: [committed] amdgcn: Fix attributes for LLVM-12 [PR 100208]

2021-07-29 Thread Andrew Stubbs

On 29/07/2021 08:34, Richard Biener wrote:

On Wed, Jul 28, 2021 at 3:04 PM Andrew Stubbs  wrote:


This patch follows up my previous patch and supports more variants of
LLVM 12.

There are still other incompatibilities with LLVM 12, but this at least
the ELF attributes should now automatically tune to any LLVM 9, 10, or
12 assembler (It would be nice if one set of options would just work
everywhere, but no).

LLVM 11 was not tested, but is broken in other ways in any case. LLVM 13
(dev) needs more work.

Unfortunately, the need for configure tests and the CLI instability
within the LLVM 12 release branch means that GCC probably needs to be
rebuilt whenever LLVM is upgraded, even for minor versions.


Is it possible to handle some incompatibilities with command line arguments
to llvm-mc in a wrapper script that could dispatch based on the
installed llvm-mc
version?  Or maybe some specs magic that passes down -mllvm-mc-version=XYZ
from a %{llvm-mc-version} specs handler that somehow queries the installed
llvm-mc?  Or is the llvm-mc version not enough to decide things?  I realize this
still needs adjustments for each new llvm-mc version that pops up.


Hopefully things will stabilize and all this will become overkill, but 
if not then we may have to consider some of those ideas.


Andrew



[OG11, committed] amdgcn: Fix attributes for LLVM-12 [PR 100208]

2021-07-29 Thread Andrew Stubbs

Now backported to devel/omp/gcc-11.

Andrew

On 28/07/2021 14:03, Andrew Stubbs wrote:
This patch follows up my previous patch and supports more variants of 
LLVM 12.


There are still other incompatibilities with LLVM 12, but this at least 
the ELF attributes should now automatically tune to any LLVM 9, 10, or 
12 assembler (It would be nice if one set of options would just work 
everywhere, but no).


LLVM 11 was not tested, but is broken in other ways in any case. LLVM 13 
(dev) needs more work.


Unfortunately, the need for configure tests and the CLI instability 
within the LLVM 12 release branch means that GCC probably needs to be 
rebuilt whenever LLVM is upgraded, even for minor versions.


Andrew




Re: [committed] amdgcn: Fix attributes for LLVM-12 [PR 100208]

2021-07-29 Thread Richard Biener via Gcc-patches
On Wed, Jul 28, 2021 at 3:04 PM Andrew Stubbs  wrote:
>
> This patch follows up my previous patch and supports more variants of
> LLVM 12.
>
> There are still other incompatibilities with LLVM 12, but this at least
> the ELF attributes should now automatically tune to any LLVM 9, 10, or
> 12 assembler (It would be nice if one set of options would just work
> everywhere, but no).
>
> LLVM 11 was not tested, but is broken in other ways in any case. LLVM 13
> (dev) needs more work.
>
> Unfortunately, the need for configure tests and the CLI instability
> within the LLVM 12 release branch means that GCC probably needs to be
> rebuilt whenever LLVM is upgraded, even for minor versions.

Is it possible to handle some incompatibilities with command line arguments
to llvm-mc in a wrapper script that could dispatch based on the
installed llvm-mc
version?  Or maybe some specs magic that passes down -mllvm-mc-version=XYZ
from a %{llvm-mc-version} specs handler that somehow queries the installed
llvm-mc?  Or is the llvm-mc version not enough to decide things?  I realize this
still needs adjustments for each new llvm-mc version that pops up.

Richard.

> Andrew


[committed] amdgcn: Fix attributes for LLVM-12 [PR 100208]

2021-07-28 Thread Andrew Stubbs
This patch follows up my previous patch and supports more variants of 
LLVM 12.


There are still other incompatibilities with LLVM 12, but this at least 
the ELF attributes should now automatically tune to any LLVM 9, 10, or 
12 assembler (It would be nice if one set of options would just work 
everywhere, but no).


LLVM 11 was not tested, but is broken in other ways in any case. LLVM 13 
(dev) needs more work.


Unfortunately, the need for configure tests and the CLI instability 
within the LLVM 12 release branch means that GCC probably needs to be 
rebuilt whenever LLVM is upgraded, even for minor versions.


Andrew
amdgcn: Fix attributes for LLVM-12 [PR 100208]

This should work for a wider range of LLVM 12 variants now.
More work required for LLVM 13 though.

gcc/ChangeLog:

PR target/100208
* config.in: Regenerate.
* config/gcn/gcn-hsa.h (A_FIJI): New define.
(A_900): New define.
(A_906): New define.
(A_908): New define.
(ASM_SPEC): Use A_FIJI, A_900, A_906 and A_908.
* config/gcn/gcn.c (output_file_start): Adjust attributes according
to the assembler capabilities.
* config/gcn/mkoffload.c (main): Likewise.
* configure: Regenerate.
* configure.ac: Add tests for LLVM assembler attribute features.

diff --git a/gcc/config.in b/gcc/config.in
index 2abac530c64..affaff2e33c 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1449,6 +1449,30 @@
 #endif
 
 
+/* Define if your assembler allows -mattr=+sram-ecc for fiji. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GCN_SRAM_ECC_FIJI
+#endif
+
+
+/* Define if your assembler allows -mattr=+sram-ecc for gfx900. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GCN_SRAM_ECC_GFX900
+#endif
+
+
+/* Define if your assembler allows -mattr=+sram-ecc for gfx906. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GCN_SRAM_ECC_GFX906
+#endif
+
+
+/* Define if your assembler allows -mattr=+sram-ecc for gfx908. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_GCN_SRAM_ECC_GFX908
+#endif
+
+
 /* Define to 1 if you have the `getchar_unlocked' function. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_GETCHAR_UNLOCKED
diff --git a/gcc/config/gcn/gcn-hsa.h b/gcc/config/gcn/gcn-hsa.h
index 724e9a381ba..fc99c8db752 100644
--- a/gcc/config/gcn/gcn-hsa.h
+++ b/gcc/config/gcn/gcn-hsa.h
@@ -75,6 +75,28 @@ extern unsigned int gcn_local_sym_hash (const char *name);
supported for gcn.  */
 #define GOMP_SELF_SPECS ""
 
+#ifdef HAVE_GCN_SRAM_ECC_FIJI
+#define A_FIJI
+#else
+#define A_FIJI "!march=*:;march=fiji:;"
+#endif
+#ifdef HAVE_GCN_SRAM_ECC_GFX900
+#define A_900
+#else
+#define A_900 "march=gfx900:;"
+#endif
+#ifdef HAVE_GCN_SRAM_ECC_GFX906
+#define A_906
+#else
+#define A_906 "march=gfx906:;"
+#endif
+#ifdef HAVE_GCN_SRAM_ECC_GFX908
+#define A_908
+#else
+#define A_908 "march=gfx908:;"
+#endif
+
+/* These targets can't have SRAM-ECC, even if a broken assembler allows it.  */
 #define DRIVER_SELF_SPECS \
   "%{march=fiji|march=gfx900|march=gfx906:%{!msram-ecc=*:-msram-ecc=off}}"
 
@@ -83,7 +105,8 @@ extern unsigned int gcn_local_sym_hash (const char *name);
  "%:last_arg(%{march=*:-mcpu=%*}) " \
  "-mattr=%{mxnack:+xnack;:-xnack} " \
  /* FIXME: support "any" when we move to HSACOv4.  */ \
- "-mattr=%{!msram-ecc=off:+sram-ecc;:-sram-ecc} " \
+ "-mattr=%{" A_FIJI A_900 A_906 A_908 \
+   "!msram-ecc=off:+sram-ecc;:-sram-ecc} " \
  "-filetype=obj"
 #define LINK_SPEC "--pie --export-dynamic"
 #define LIB_SPEC  "-lc"
diff --git a/gcc/config/gcn/gcn.c b/gcc/config/gcn/gcn.c
index 385b90c4b00..d25c4e54e16 100644
--- a/gcc/config/gcn/gcn.c
+++ b/gcc/config/gcn/gcn.c
@@ -5181,18 +5181,39 @@ static void
 output_file_start (void)
 {
   const char *cpu;
+  bool use_sram = flag_sram_ecc;
   switch (gcn_arch)
 {
-case PROCESSOR_FIJI: cpu = "gfx803"; break;
-case PROCESSOR_VEGA10: cpu = "gfx900"; break;
-case PROCESSOR_VEGA20: cpu = "gfx906"; break;
-case PROCESSOR_GFX908: cpu = "gfx908"; break;
+case PROCESSOR_FIJI:
+  cpu = "gfx803";
+#ifndef HAVE_GCN_SRAM_ECC_FIJI
+  use_sram = false;
+#endif
+  break;
+case PROCESSOR_VEGA10:
+  cpu = "gfx900";
+#ifndef HAVE_GCN_SRAM_ECC_GFX900
+  use_sram = false;
+#endif
+  break;
+case PROCESSOR_VEGA20:
+  cpu = "gfx906";
+#ifndef HAVE_GCN_SRAM_ECC_GFX906
+  use_sram = false;
+#endif
+  break;
+case PROCESSOR_GFX908:
+  cpu = "gfx908";
+#ifndef HAVE_GCN_SRAM_ECC_GFX908
+  use_sram = false;
+#endif
+  break;
 default: gcc_unreachable ();
 }
 
   const char *xnack = (flag_xnack ? "+xnack" : "");
   /* FIXME: support "any" when we move to HSACOv4.  */
-  const char *sram_ecc = (flag_sram_ecc ? "+sram-ecc" : "");
+  const char *sram_ecc = (use_sram ? "+sram-ecc" : "");
 
   fprintf(asm_out_file, "\t.amdgcn_target \"amdgcn-unknown-amdhsa--%s%s%s\"\n",
  cpu, xnack, sram_ecc);
diff