[clang] befb52d - [Clang] Remove use of 'temporary' toolchains for offload deduction (#131332)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 14 09:08:34 PDT 2025


Author: Joseph Huber
Date: 2025-03-14T11:08:31-05:00
New Revision: befb52db94cc63558981baac5e58d86ed2ec1f37

URL: https://github.com/llvm/llvm-project/commit/befb52db94cc63558981baac5e58d86ed2ec1f37
DIFF: https://github.com/llvm/llvm-project/commit/befb52db94cc63558981baac5e58d86ed2ec1f37.diff

LOG: [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: https://github.com/llvm/llvm-project/issues/131325

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/offload-Xarch.c

Removed: 
    


################################################################################
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