Skip to content

Commit befb52d

Browse files
authored
[Clang] Remove use of 'temporary' toolchains for offload deduction (#131332)
Summary: We need a toolchain to get the GPU architectures when compiling with OpenMP. This kind of breaks the toolchain model because these are cached all over the place. Instead of making a new one, just create both of them unconditionally. It's not like this is saving any work since we still needed to create both toolchains in the earlier case. Fixes: #131325
1 parent 999700c commit befb52d

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,23 +1040,15 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
10401040
// We need to temporarily create these toolchains so that we can access
10411041
// tools for inferring architectures.
10421042
llvm::DenseSet<StringRef> Archs;
1043-
if (NVPTXTriple) {
1044-
auto TempTC = std::make_unique<toolchains::CudaToolChain>(
1045-
*this, *NVPTXTriple, *HostTC, C.getInputArgs());
1046-
for (StringRef Arch : getOffloadArchs(
1047-
C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
1048-
Archs.insert(Arch);
1049-
}
1050-
if (AMDTriple) {
1051-
auto TempTC = std::make_unique<toolchains::AMDGPUOpenMPToolChain>(
1052-
*this, *AMDTriple, *HostTC, C.getInputArgs());
1053-
for (StringRef Arch : getOffloadArchs(
1054-
C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
1055-
Archs.insert(Arch);
1056-
}
1057-
if (!AMDTriple && !NVPTXTriple) {
1043+
for (const std::optional<llvm::Triple> &TT : {NVPTXTriple, AMDTriple}) {
1044+
if (!TT)
1045+
continue;
1046+
1047+
auto &TC =
1048+
getOffloadToolChain(C.getInputArgs(), Action::OFK_OpenMP, *TT,
1049+
C.getDefaultToolChain().getTriple());
10581050
for (StringRef Arch :
1059-
getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, nullptr, true))
1051+
getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, &TC, true))
10601052
Archs.insert(Arch);
10611053
}
10621054

clang/test/Driver/offload-Xarch.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// UNSUPPORTED: target={{.*darwin.*}}
2-
31
// RUN: %clang --target=x86_64-unknown-linux-gnu -x cuda %s -Xarch_nvptx64 -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
42
// RUN: %clang -x cuda %s -Xarch_device -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
53
// RUN: %clang -x hip %s -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s

0 commit comments

Comments
 (0)