https://github.com/a4lg created https://github.com/llvm/llvm-project/pull/170590

This PR adds new AMD's ROCm distribution ― TheRock-based device library path to 
Clang.

>From bb52fec29c048eb85dd600e7f208a6db8c8f349f Mon Sep 17 00:00:00 2001
From: Tsukasa OI <[email protected]>
Date: Thu, 4 Dec 2025 00:04:52 +0000
Subject: [PATCH 1/2] [Clang][AMDGPU] Fix a typo

---
 clang/test/Driver/hip-device-libs.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/hip-device-libs.hip 
b/clang/test/Driver/hip-device-libs.hip
index effce40d67ebd..b3c43b8277c4a 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -9,7 +9,7 @@
 // RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FLUSHD,ROCMDIR
 
 
-// Test subtarget with flushing off by ddefault.
+// Test subtarget with flushing off by default.
 // RUN: %clang -### --target=x86_64-linux-gnu \
 // RUN:  --cuda-gpu-arch=gfx900 \
 // RUN:  --rocm-path=%S/Inputs/rocm \

>From b4267236e93c761771f8dffc3d3e061a4246b353 Mon Sep 17 00:00:00 2001
From: Tsukasa OI <[email protected]>
Date: Thu, 4 Dec 2025 00:03:10 +0000
Subject: [PATCH 2/2] [Clang][AMDGPU] Search TheRock-based device libraries

TheRock has slightly different path (relative to ROCM_PATH)
for device libraries.  This commit adds search path for device libraries
on a TheRock-based distribution.

Signed-off-by: Tsukasa OI <[email protected]>
---
 clang/lib/Driver/ToolChains/AMDGPU.cpp                 | 10 ++++++++--
 clang/test/Driver/Inputs/rocm-therock/include          |  1 +
 clang/test/Driver/Inputs/rocm-therock/lib/llvm/amdgcn  |  1 +
 .../test/Driver/Inputs/rocm-therock/share/hip/version  |  1 +
 clang/test/Driver/hip-device-libs.hip                  |  8 ++++++++
 5 files changed, 19 insertions(+), 2 deletions(-)
 create mode 120000 clang/test/Driver/Inputs/rocm-therock/include
 create mode 120000 clang/test/Driver/Inputs/rocm-therock/lib/llvm/amdgcn
 create mode 120000 clang/test/Driver/Inputs/rocm-therock/share/hip/version

diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 87ccd40372681..69ada73342127 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -436,15 +436,21 @@ void RocmInstallationDetector::detectDeviceLibrary() {
   if (HasDeviceLibrary)
     return;
 
-  // Find device libraries in a legacy ROCm directory structure
-  // ${ROCM_ROOT}/amdgcn/bitcode/*
+  // Find device libraries in a ROCm directory structure
   auto &ROCmDirs = getInstallationPathCandidates();
   for (const auto &Candidate : ROCmDirs) {
+    // Legacy: ${ROCM_PATH}/amdgcn/bitcode/*
     LibDevicePath = Candidate.Path;
     llvm::sys::path::append(LibDevicePath, "amdgcn", "bitcode");
     HasDeviceLibrary = CheckDeviceLib(LibDevicePath, Candidate.StrictChecking);
     if (HasDeviceLibrary)
       return;
+    // TheRock: ${ROCM_PATH}/lib/llvm/amdgcn/bitcode/*
+    LibDevicePath = Candidate.Path;
+    llvm::sys::path::append(LibDevicePath, "lib", "llvm", "amdgcn", "bitcode");
+    HasDeviceLibrary = CheckDeviceLib(LibDevicePath, Candidate.StrictChecking);
+    if (HasDeviceLibrary)
+      return;
   }
 }
 
diff --git a/clang/test/Driver/Inputs/rocm-therock/include 
b/clang/test/Driver/Inputs/rocm-therock/include
new file mode 120000
index 0000000000000..13265e5ed3db8
--- /dev/null
+++ b/clang/test/Driver/Inputs/rocm-therock/include
@@ -0,0 +1 @@
+../rocm/include
\ No newline at end of file
diff --git a/clang/test/Driver/Inputs/rocm-therock/lib/llvm/amdgcn 
b/clang/test/Driver/Inputs/rocm-therock/lib/llvm/amdgcn
new file mode 120000
index 0000000000000..79d18ba840474
--- /dev/null
+++ b/clang/test/Driver/Inputs/rocm-therock/lib/llvm/amdgcn
@@ -0,0 +1 @@
+../../../rocm/amdgcn
\ No newline at end of file
diff --git a/clang/test/Driver/Inputs/rocm-therock/share/hip/version 
b/clang/test/Driver/Inputs/rocm-therock/share/hip/version
new file mode 120000
index 0000000000000..62ff49a023cb9
--- /dev/null
+++ b/clang/test/Driver/Inputs/rocm-therock/share/hip/version
@@ -0,0 +1 @@
+../../../rocm/bin/.hipVersion
\ No newline at end of file
diff --git a/clang/test/Driver/hip-device-libs.hip 
b/clang/test/Driver/hip-device-libs.hip
index b3c43b8277c4a..f5813c06ae600 100644
--- a/clang/test/Driver/hip-device-libs.hip
+++ b/clang/test/Driver/hip-device-libs.hip
@@ -85,6 +85,13 @@
 // RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
 // RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FLUSHD,ROCMDIR
 
+// Test TheRock toolchain layout
+// RUN: %clang -### --target=x86_64-linux-gnu \
+// RUN:   --offload-arch=gfx803 -nogpuinc \
+// RUN:   --rocm-path=%S/Inputs/rocm-therock \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip \
+// RUN: 2>&1 | FileCheck %s --check-prefixes=ALL,FLUSHD,ROCMDIR-THEROCK
+
 // Test finding device lib in resource dir
 // RUN: %clang -### --target=x86_64-linux-gnu \
 // RUN:   --offload-arch=gfx803 -nogpuinc \
@@ -210,6 +217,7 @@
 
 // RESDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|\\\\)rocm_resource_dir(/|\\\\)lib(64)?(/|\\\\)amdgcn(/|\\\\).*]]ocml.bc"
 // ROCMDIR-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|\\\\)rocm(/|\\\\)amdgcn(/|\\\\).*]]ocml.bc"
+// ROCMDIR-THEROCK-SAME: "-mlink-builtin-bitcode" 
"[[DEVICELIB_DIR:[^"]+(/|\\\\)rocm-therock(/|\\\\)lib(/|\\\\)llvm(/|\\\\)amdgcn(/|\\\\).*]]ocml.bc"
 
 // ALL-SAME: "-mlink-builtin-bitcode" "[[DEVICELIB_DIR]]ockl.bc"
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to