[clang] 4638ae3 - [OpenMP] Use the new OpenMP device static library when doing LTO
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Fri May 13 11:39:29 PDT 2022
Author: Joseph Huber
Date: 2022-05-13T14:38:55-04:00
New Revision: 4638ae3a8575d988df856116102c1ccd15583c00
URL: https://github.com/llvm/llvm-project/commit/4638ae3a8575d988df856116102c1ccd15583c00
DIFF: https://github.com/llvm/llvm-project/commit/4638ae3a8575d988df856116102c1ccd15583c00.diff
LOG: [OpenMP] Use the new OpenMP device static library when doing LTO
The previous patches allowed us to create a static library containing
all the device code. This patch uses that library to perform the device
runtime linking late when performing LTO. This in addition to
simplifying the libraries, allows us to transparently handle the runtime
library as-needed without needing Clang to manually pass the necessary
library in the linker wrapper job.
Depends on D125315
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D125333
Added:
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/openmp-offload-gpu-new.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 69f950942632..eec3c7b4ed21 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8331,28 +8331,6 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
"=" + *(FeatureIt + 1)));
}
- // Pass in the bitcode library to be linked during LTO.
- for (auto &I :
- llvm::make_range(OpenMPTCRange.first, OpenMPTCRange.second)) {
- const ToolChain *TC = I.second;
- if (!(TC->getTriple().isNVPTX() || TC->getTriple().isAMDGPU()))
- continue;
-
- const Driver &TCDriver = TC->getDriver();
- const ArgList &TCArgs = C.getArgsForToolChain(TC, "", Action::OFK_OpenMP);
- StringRef Arch = TCArgs.getLastArgValue(options::OPT_march_EQ);
-
- ArgStringList BitcodeLibrary;
- addOpenMPDeviceRTL(TCDriver, TCArgs, BitcodeLibrary, Arch,
- TC->getTriple());
-
- if (!BitcodeLibrary.empty())
- CmdArgs.push_back(Args.MakeArgString(
- "-target-library=" +
- Action::GetOffloadKindName(Action::OFK_OpenMP) + "-" +
- TC->getTripleString() + "-" + Arch + "=" + BitcodeLibrary.back()));
- }
-
// Pass in the optimization level to use for LTO.
if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
StringRef OOpt;
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b646a1ddaf03..28299f73ec94 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -736,6 +736,9 @@ bool tools::addOpenMPRuntime(ArgStringList &CmdArgs, const ToolChain &TC,
if (IsOffloadingHost)
CmdArgs.push_back("-lomptarget");
+ if (IsOffloadingHost && TC.getDriver().isUsingLTO(/* IsOffload */ true))
+ CmdArgs.push_back("-lomptarget.devicertl");
+
addArchSpecificRPath(TC, Args, CmdArgs);
if (RTKind == Driver::OMPRT_OMP)
diff --git a/clang/test/Driver/openmp-offload-gpu-new.c b/clang/test/Driver/openmp-offload-gpu-new.c
index 3e7bc4fb11ee..cd8dfc452615 100644
--- a/clang/test/Driver/openmp-offload-gpu-new.c
+++ b/clang/test/Driver/openmp-offload-gpu-new.c
@@ -94,3 +94,8 @@
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \
// RUN: --offload-device-only -E -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY-PP
// CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.*]]"], output: "-"
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=sm_52 -nogpulib \
+// RUN: -foffload-lto %s 2>&1 | FileCheck --check-prefix=CHECK-LTO-LIBRARY %s
+
+// CHECK-LTO-LIBRARY: {{.*}}-lomptarget{{.*}}-lomptarget.devicertl
More information about the cfe-commits
mailing list