[nvptx] Pass host specific ABI opts from mkoffload. The patch adds an option -foffload-abi-host-opts, which is set by host in TARGET_OFFLOAD_OPTIONS, and mkoffload then passes it's value to host_compiler. gcc/ChangeLog: * common.opt (foffload-abi-host-opts): New option. * config/aarch64/aarch64.cc (aarch64_offload_options): Set -foffload-abi-host-opts if -foffload-abi=lp64. * config/i386/i386-opts.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 host_abi_opts to argv_obstack if offload_abi == OFFLOAD_ABI_LP64. * config/gcn/mkoffload.cc (offload_abi_host_opts): Define. (compile_native): Append host_abi_opts to argv_obstack if offload_abi == OFFLOAD_ABI_LP64. (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 diff --git a/gcc/common.opt b/gcc/common.opt index ea39f87ae71..8e14787d2e8 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -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 Driver Joined MissingArgError(option missing after %qs) +-foffload-abi-host-opts= Specify host ABI options. + fomit-frame-pointer Common Var(flag_omit_frame_pointer) Optimization When possible do not generate stack frames. diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 6a3f1a23a9f..57198df8044 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -19002,7 +19002,7 @@ aarch64_offload_options (void) if (TARGET_ILP32) return xstrdup ("-foffload-abi=ilp32"); else - return xstrdup ("-foffload-abi=lp64"); + return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-mabi=lp64"); } static struct machine_function * diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc index b8d981878ed..d608580a1e1 100644 --- a/gcc/config/gcn/mkoffload.cc +++ b/gcc/config/gcn/mkoffload.cc @@ -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,16 +821,12 @@ 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) + if (offload_abi == OFFLOAD_ABI_LP64) { - 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"); @@ -998,6 +996,14 @@ 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) diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index f79257cc764..3c5443ab67f 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3680,7 +3680,7 @@ char * ix86_offload_options (void) { if (TARGET_LP64) - return xstrdup ("-foffload-abi=lp64"); + return xstrdup ("-foffload-abi=lp64 -foffload-abi-host-opts=-m64"); return xstrdup ("-foffload-abi=ilp32"); } diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc index 503b1abcefd..95ef54b85e9 100644 --- a/gcc/config/nvptx/mkoffload.cc +++ b/gcc/config/nvptx/mkoffload.cc @@ -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,16 +608,12 @@ 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) + if (offload_abi == OFFLOAD_ABI_LP64) { - 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"); @@ -721,6 +718,14 @@ 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) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 08579bc83e6..fe03fd30fd7 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -17330,7 +17330,7 @@ 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"); } diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc index c07765b37a2..7de045da9b9 100644 --- a/gcc/lto-wrapper.cc +++ b/gcc/lto-wrapper.cc @@ -484,6 +484,7 @@ merge_and_complain (vec &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 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: diff --git a/gcc/opts.cc b/gcc/opts.cc index fc6abf6f582..c554e2fdd2c 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -3070,11 +3070,12 @@ 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", arg); #endif break;