https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/211675

>From 16c4019f304741e84be3ab544c08a680e33c086d Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" <[email protected]>
Date: Fri, 14 Aug 2026 20:31:37 -0400
Subject: [PATCH] [HIP] Link profile runtime in device-only lld path

HIP device-only code object links can use the direct lld path in HIPAMD.cpp. 
That path did not add the profile runtime, so device-only builds with profile 
generation missed libclang_rt.profile.a.

Add the normal profile runtime handling to this linker path and cover it with a 
driver test.
---
 clang/lib/Driver/ToolChains/HIPAMD.cpp         |  1 +
 clang/test/Driver/hip-profile-rocm-runtime.hip | 13 ++++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index 245cf642cf853..4af0fe038c90d 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -133,6 +133,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, 
const JobAction &JA,
   LldArgs.append({"-o", Output.getFilename()});
   for (auto Input : Inputs)
     LldArgs.push_back(Input.getFilename());
+  TC.addProfileRTLibs(Args, LldArgs);
 
   // Look for archive of bundled bitcode in arguments, and add temporary files
   // for the extracted archive of bitcode to inputs.
diff --git a/clang/test/Driver/hip-profile-rocm-runtime.hip 
b/clang/test/Driver/hip-profile-rocm-runtime.hip
index fc82db4fc13c0..b267fa382b2be 100644
--- a/clang/test/Driver/hip-profile-rocm-runtime.hip
+++ b/clang/test/Driver/hip-profile-rocm-runtime.hip
@@ -1,11 +1,11 @@
 // REQUIRES: x86-registered-target, amdgpu-registered-target
 // UNSUPPORTED: system-windows
 
-// Build a fake resource dir containing both the base profile runtime and the
-// ROCm device-profile runtime so the driver's existence check passes.
-// RUN: rm -rf %t && mkdir -p %t/lib/x86_64-unknown-linux
+// Build a fake resource dir containing host and device profile runtimes.
+// RUN: rm -rf %t && mkdir -p %t/lib/x86_64-unknown-linux 
%t/lib/amdgcn-amd-amdhsa
 // RUN: touch %t/lib/x86_64-unknown-linux/libclang_rt.profile.a
 // RUN: touch %t/lib/x86_64-unknown-linux/libclang_rt.profile_rocm.a
+// RUN: touch %t/lib/amdgcn-amd-amdhsa/libclang_rt.profile.a
 // RUN: touch %t.o
 
 // HIP host link with PGO links clang_rt.profile_rocm.
@@ -31,3 +31,10 @@
 // RUN:   | FileCheck -check-prefix=HOST-PGO %s
 // HOST-PGO: "{{.*}}libclang_rt.profile.a"
 // HOST-PGO-NOT: libclang_rt.profile_rocm.a
+
+// HIP device-only link with PGO links the device profile runtime.
+// RUN: %clang -### -x hip --offload-device-only --target=x86_64-unknown-linux 
\
+// RUN: --offload-arch=gfx90a -fprofile-generate -resource-dir=%t \
+// RUN: -nogpuinc -nogpulib %s 2>&1 \
+// RUN: | FileCheck -check-prefix=HIP-DEVICE-PGO %s
+// HIP-DEVICE-PGO: "{{.*}}lld" 
{{.*}}"{{.*}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}libclang_rt.profile.a"

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

Reply via email to