[clang] [Clang] Remove use of 'temporary' toolchains for offload deduction (PR #131332)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 14 06:18:54 PDT 2025
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/131332
Summary:
We neededa 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: https://github.com/llvm/llvm-project/issues/131325
>From 14c03c20afdee22630a2600c06bb653be4eeaaa4 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 14 Mar 2025 08:16:24 -0500
Subject: [PATCH] [Clang] Remove use of 'temporary' toolchains for offload
deduction
Summary:
We neededa 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: https://github.com/llvm/llvm-project/issues/131325
---
clang/lib/Driver/Driver.cpp | 24 ++++++++----------------
clang/test/Driver/offload-Xarch.c | 2 --
2 files changed, 8 insertions(+), 18 deletions(-)
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ba0a7c2180867..848b27012976d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1040,23 +1040,15 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
// We need to temporarily create these toolchains so that we can access
// tools for inferring architectures.
llvm::DenseSet<StringRef> Archs;
- if (NVPTXTriple) {
- auto TempTC = std::make_unique<toolchains::CudaToolChain>(
- *this, *NVPTXTriple, *HostTC, C.getInputArgs());
- for (StringRef Arch : getOffloadArchs(
- C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
- Archs.insert(Arch);
- }
- if (AMDTriple) {
- auto TempTC = std::make_unique<toolchains::AMDGPUOpenMPToolChain>(
- *this, *AMDTriple, *HostTC, C.getInputArgs());
- for (StringRef Arch : getOffloadArchs(
- C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
- Archs.insert(Arch);
- }
- if (!AMDTriple && !NVPTXTriple) {
+ for (const std::optional<llvm::Triple> &TT : {NVPTXTriple, AMDTriple}) {
+ if (!TT)
+ continue;
+
+ auto &TC =
+ getOffloadToolChain(C.getInputArgs(), Action::OFK_OpenMP, *TT,
+ C.getDefaultToolChain().getTriple());
for (StringRef Arch :
- getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, nullptr, true))
+ getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, &TC, true))
Archs.insert(Arch);
}
diff --git a/clang/test/Driver/offload-Xarch.c b/clang/test/Driver/offload-Xarch.c
index 0f8f40a5cbd74..8856dac198465 100644
--- a/clang/test/Driver/offload-Xarch.c
+++ b/clang/test/Driver/offload-Xarch.c
@@ -1,5 +1,3 @@
-// UNSUPPORTED: target={{.*darwin.*}}
-
// RUN: %clang --target=x86_64-unknown-linux-gnu -x cuda %s -Xarch_nvptx64 -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
// RUN: %clang -x cuda %s -Xarch_device -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
// RUN: %clang -x hip %s -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
More information about the cfe-commits
mailing list