From 0420738bf55dfd0302ca318299a19905a27f7c18 Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Wed, 9 Aug 2017 15:27:39 +0000 Subject: [PATCH] [OpenMP] Add flag for disabling the default generation of relocatable OpenMP target code for NVIDIA GPUs. Summary: Previously we have added the "-c" flag which gets passed to PTXAS by default to generate relocatable OpenMP target code by default. This set of flags exposes control over this behaviour. Reviewers: arpith-jacob, caomhin, carlo.bertolli, ABataev, Hahnfeld, jlebar, hfinkel, tstellar Reviewed By: ABataev Subscribers: Hahnfeld, rengolin, cfe-commits Differential Revision: https://reviews.llvm.org/D29659 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310484 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Options.td | 4 ++++ lib/Driver/ToolChains/Cuda.cpp | 5 ++++- test/Driver/openmp-offload.c | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index d866c16dbb..c86941181b 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1311,6 +1311,10 @@ def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, Flags<[DriverOp 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">; diff --git a/lib/Driver/ToolChains/Cuda.cpp b/lib/Driver/ToolChains/Cuda.cpp index 927704a685..1ff41ce66d 100644 --- a/lib/Driver/ToolChains/Cuda.cpp +++ b/lib/Driver/ToolChains/Cuda.cpp @@ -292,7 +292,10 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA, 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_fopenmp_relocatable_target, + options::OPT_fnoopenmp_relocatable_target, + /*Default=*/ true)) CmdArgs.push_back("-c"); const char *Exec; diff --git a/test/Driver/openmp-offload.c b/test/Driver/openmp-offload.c index af50d156d7..cd2ca3e3d6 100644 --- a/test/Driver/openmp-offload.c +++ b/test/Driver/openmp-offload.c @@ -695,3 +695,20 @@ // RUN: | FileCheck -check-prefix=CHK-PTXAS-DEFAULT %s // CHK-PTXAS-DEFAULT: ptxas{{.*}}" "-c" + +/// ########################################################################### + +/// 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-NORELO %s + +// CHK-PTXAS-NORELO-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-RELO %s + +// CHK-PTXAS-RELO: ptxas{{.*}}" "-c" -- 2.40.0