]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Pass host specific ABI opts from mkoffload.
authorPrathamesh Kulkarni <prathameshk@nvidia.com>
Tue, 10 Sep 2024 15:31:58 +0000 (21:01 +0530)
committerPrathamesh Kulkarni <prathameshk@nvidia.com>
Tue, 10 Sep 2024 15:43:33 +0000 (21:13 +0530)
The patch adds an option -foffload-abi-host-opts, which
is set by host in TARGET_OFFLOAD_OPTIONS, and mkoffload then passes its value
to host_compiler.

gcc/ChangeLog:
PR target/96265
* common.opt (foffload-abi-host-opts): New option.
* config/aarch64/aarch64.cc (aarch64_offload_options): Pass
-foffload-abi-host-opts.
* config/i386/i386-options.cc (ix86_offload_options): Likewise.
* config/rs6000/rs6000.cc (rs6000_offload_options): Likewise.
* config/nvptx/mkoffload.cc (offload_abi_host_opts): Define.
(compile_native): Append offload_abi_host_opts to argv_obstack.
(main): Handle option -foffload-abi-host-opts.
* config/gcn/mkoffload.cc (offload_abi_host_opts): Define.
(compile_native): Append offload_abi_host_opts to argv_obstack.
(main): Handle option -foffload-abi-host-opts.
* lto-wrapper.cc (merge_and_complain): Handle
-foffload-abi-host-opts.
(append_compiler_options): Likewise.
* opts.cc (common_handle_option): Likewise.

Signed-off-by: Prathamesh Kulkarni <prathameshk@nvidia.com>
gcc/common.opt
gcc/config/aarch64/aarch64.cc
gcc/config/gcn/mkoffload.cc
gcc/config/i386/i386-options.cc
gcc/config/nvptx/mkoffload.cc
gcc/config/rs6000/rs6000.cc
gcc/lto-wrapper.cc
gcc/opts.cc

index ea39f87ae716d8119292fed64cd0b2f414564dad..d270e524ff45f58531f30af19ad0ec434a1b7e32 100644 (file)
@@ -2361,6 +2361,10 @@ Enum(offload_abi) String(ilp32) Value(OFFLOAD_ABI_ILP32)
 EnumValue
 Enum(offload_abi) String(lp64) Value(OFFLOAD_ABI_LP64)
 
+foffload-abi-host-opts=
+Common Joined MissingArgError(option missing after %qs)
+-foffload-abi-host-opts=<options>      Specify host ABI options.
+
 fomit-frame-pointer
 Common Var(flag_omit_frame_pointer) Optimization
 When possible do not generate stack frames.
index 6a3f1a23a9f435b88e1d2d22da909e5423321940..6ccf08d1cc0a1aecfc72f95b105ace2c00b1a51d 100644 (file)
@@ -19000,9 +19000,9 @@ static char *
 aarch64_offload_options (void)
 {
   if (TARGET_ILP32)
-    return xstrdup ("-foffload-abi=ilp32");
+    return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-mabi=ilp32");
   else
-    return xstrdup ("-foffload-abi=lp64");
+    return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-mabi=lp64");
 }
 
 static struct machine_function *
index b8d981878edf7d9dd383d91ef7343776fdf7212a..345bbf7709c4dff3ca9e72743aef59643c152826 100644 (file)
@@ -133,6 +133,8 @@ static const char *gcn_dumpbase;
 static struct obstack files_to_cleanup;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
+const char *offload_abi_host_opts = NULL;
+
 uint32_t elf_arch = EF_AMDGPU_MACH_AMDGCN_GFX900;  // Default GPU architecture.
 uint32_t elf_flags = EF_AMDGPU_FEATURE_SRAMECC_UNSUPPORTED_V4;
 
@@ -819,17 +821,10 @@ compile_native (const char *infile, const char *outfile, const char *compiler,
   obstack_ptr_grow (&argv_obstack, gcn_dumpbase);
   obstack_ptr_grow (&argv_obstack, "-dumpbase-ext");
   obstack_ptr_grow (&argv_obstack, ".c");
-  switch (offload_abi)
-    {
-    case OFFLOAD_ABI_LP64:
-      obstack_ptr_grow (&argv_obstack, "-m64");
-      break;
-    case OFFLOAD_ABI_ILP32:
-      obstack_ptr_grow (&argv_obstack, "-m32");
-      break;
-    default:
-      gcc_unreachable ();
-    }
+  if (!offload_abi_host_opts)
+    fatal_error (input_location,
+                "%<-foffload-abi-host-opts%> not specified.");
+  obstack_ptr_grow (&argv_obstack, offload_abi_host_opts);
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
   obstack_ptr_grow (&argv_obstack, "-o");
@@ -998,6 +993,15 @@ main (int argc, char **argv)
                         "unrecognizable argument of option %<" STR "%>");
        }
 #undef STR
+      else if (startswith (argv[i], "-foffload-abi-host-opts="))
+       {
+         if (offload_abi_host_opts)
+           fatal_error (input_location,
+                        "%<-foffload-abi-host-opts%> specified "
+                        "multiple times");
+         offload_abi_host_opts
+           = argv[i] + strlen ("-foffload-abi-host-opts=");
+       }
       else if (strcmp (argv[i], "-fopenmp") == 0)
        fopenmp = true;
       else if (strcmp (argv[i], "-fopenacc") == 0)
index f79257cc764182ecf7a3abf52e1b2a71f5d0c4b7..55e0210260f59fe821bf770e6f638e40824ff1d7 100644 (file)
@@ -3680,8 +3680,8 @@ char *
 ix86_offload_options (void)
 {
   if (TARGET_LP64)
-    return xstrdup ("-foffload-abi=lp64");
-  return xstrdup ("-foffload-abi=ilp32");
+    return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-m64");
+  return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-m32");
 }
 
 /* Handle "cdecl", "stdcall", "fastcall", "regparm", "thiscall",
index 503b1abcefdeebed01ee38a1256d2afd0599cc40..df16ee647364f4a0327730c926c94500d6c647ea 100644 (file)
@@ -61,6 +61,7 @@ static const char *omp_requires_file;
 static const char *ptx_dumpbase;
 
 enum offload_abi offload_abi = OFFLOAD_ABI_UNSET;
+const char *offload_abi_host_opts = NULL;
 
 /* Delete tempfiles.  */
 
@@ -607,17 +608,10 @@ compile_native (const char *infile, const char *outfile, const char *compiler,
   obstack_ptr_grow (&argv_obstack, ptx_dumpbase);
   obstack_ptr_grow (&argv_obstack, "-dumpbase-ext");
   obstack_ptr_grow (&argv_obstack, ".c");
-  switch (offload_abi)
-    {
-    case OFFLOAD_ABI_LP64:
-      obstack_ptr_grow (&argv_obstack, "-m64");
-      break;
-    case OFFLOAD_ABI_ILP32:
-      obstack_ptr_grow (&argv_obstack, "-m32");
-      break;
-    default:
-      gcc_unreachable ();
-    }
+  if (!offload_abi_host_opts)
+    fatal_error (input_location,
+                "%<-foffload-abi-host-opts%> not specified.");
+  obstack_ptr_grow (&argv_obstack, offload_abi_host_opts);
   obstack_ptr_grow (&argv_obstack, infile);
   obstack_ptr_grow (&argv_obstack, "-c");
   obstack_ptr_grow (&argv_obstack, "-o");
@@ -721,6 +715,15 @@ main (int argc, char **argv)
                         "unrecognizable argument of option " STR);
        }
 #undef STR
+      else if (startswith (argv[i], "-foffload-abi-host-opts="))
+       {
+         if (offload_abi_host_opts)
+           fatal_error (input_location,
+                        "%<-foffload-abi-host-opts%> specified "
+                        "multiple times");
+         offload_abi_host_opts
+           = argv[i] + strlen ("-foffload-abi-host-opts=");
+       }
       else if (strcmp (argv[i], "-fopenmp") == 0)
        fopenmp = true;
       else if (strcmp (argv[i], "-fopenacc") == 0)
index 08579bc83e6f4e429808f8e6e971297f5264d364..0bf8bae27f5d8b836983960e27f88164e32194db 100644 (file)
@@ -17330,9 +17330,9 @@ static char *
 rs6000_offload_options (void)
 {
   if (TARGET_64BIT)
-    return xstrdup ("-foffload-abi=lp64");
+    return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-m64");
   else
-    return xstrdup ("-foffload-abi=ilp32");
+    return xstrdup ("-foffload-abi=ilp32 -foffload-abi-host-opts=-m32");
 }
 
 \f
index 6d847e01a4ee5fa93790cac1843ba2ce4777452d..141856c9b67b5110e55241d6e7d2bb5caccad683 100644 (file)
@@ -484,6 +484,7 @@ merge_and_complain (vec<cl_decoded_option> &decoded_options,
  
 
        case OPT_foffload_abi_:
+       case OPT_foffload_abi_host_opts_:
          if (existing_opt == -1)
            decoded_options.safe_push (*foption);
          else if (foption->value != decoded_options[existing_opt].value)
@@ -745,6 +746,7 @@ append_compiler_options (obstack *argv_obstack, vec<cl_decoded_option> opts)
        case OPT_fopenacc:
        case OPT_fopenacc_dim_:
        case OPT_foffload_abi_:
+       case OPT_foffload_abi_host_opts_:
        case OPT_fcf_protection_:
        case OPT_fasynchronous_unwind_tables:
        case OPT_funwind_tables:
index d48a1ac6602c087db2a6aca29f6bc85c59ef7d79..acd53befdbfcddd889d7275706816b2706dbdf8c 100644 (file)
@@ -3070,11 +3070,14 @@ common_handle_option (struct gcc_options *opts,
       break;
 
     case OPT_foffload_abi_:
+    case OPT_foffload_abi_host_opts_:
 #ifdef ACCEL_COMPILER
       /* Handled in the 'mkoffload's.  */
 #else
-      error_at (loc, "%<-foffload-abi%> option can be specified only for "
-               "offload compiler");
+      error_at (loc,
+               "%qs option can be specified only for offload compiler",
+               (code == OPT_foffload_abi_) ? "-foffload-abi"
+                                           : "-foffload-abi-host-opts");
 #endif
       break;