Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1213,6 +1213,10 @@ HelpText<"Specify comma-separated list of triples OpenMP offloading targets to be supported">; def fopenmp_dump_offload_linker_script : Flag<["-"], "fopenmp-dump-offload-linker-script">, Group, Flags<[NoArgumentUnused]>; +def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">, Group, Flags<[CC1Option, NoArgumentUnused]>, + HelpText<"OpenMP target code is compiled as relocatable using the -c flag. For OpenMP targets the code is relocatable by default.">; +def fnoopenmp_relocatable_target : Flag<["-"], "fnoopenmp-relocatable-target">, Group, Flags<[CC1Option, NoArgumentUnused]>, + HelpText<"Do not compile OpenMP target code as relocatable.">; def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, Group; def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, Group; def force__cpusubtype__ALL : Flag<["-"], "force_cpusubtype_ALL">; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -12211,7 +12211,9 @@ CmdArgs.push_back(Args.MakeArgString(A)); // In OpenMP we need to generate relocatable code. - if (JA.isOffloading(Action::OFK_OpenMP)) + if (JA.isOffloading(Action::OFK_OpenMP) && + !Args.hasFlag(options::OPT_fnoopenmp_relocatable_target, + options::OPT_fopenmp_relocatable_target, false)) CmdArgs.push_back("-c"); const char *Exec; Index: test/Driver/openmp-offload.c =================================================================== --- test/Driver/openmp-offload.c +++ test/Driver/openmp-offload.c @@ -610,6 +610,23 @@ /// ########################################################################### +/// PTXAS is passed -c flag by default when offloading to an NVIDIA device using OpenMP - disable it. +// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -fnoopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-PTXAS-C %s + +// CHK-PTXAS-C-NOT: ptxas{{.*}}" "-c" + +/// ########################################################################### + +/// PTXAS is passed -c flag by default when offloading to an NVIDIA device using OpenMP +/// Check that the flag is passed when -fopenmp-relocatable-target is used. +// RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -fopenmp-relocatable-target -save-temps -no-canonical-prefixes %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-PTXAS-C-RELO %s + +// CHK-PTXAS-C-RELO: ptxas{{.*}}" "-c" + +/// ########################################################################### + /// Check that CLANG forwards the -v flag to PTXAS. // RUN: %clang -### -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -save-temps -no-canonical-prefixes -v %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-VERBOSE %s