llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Yaxun (Sam) Liu (yxsamliu)

<details>
<summary>Changes</summary>

HIP device-only code object builds can need the AMDGPU profile runtime when 
device PGO is enabled. The driver already emits the device instrumentation, but 
this path did not add libclang_rt.profile.a to the direct lld link.

Keep LTO enabled for this case because the AMDGPU profile runtime is bitcode. 
Also add the profile runtime archive to the HIPAMD device link command.

Add driver coverage for --cuda-device-only with the new offload driver and 
-fprofile-generate.

---
Full diff: https://github.com/llvm/llvm-project/pull/211675.diff


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+1) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+1) 
- (modified) clang/test/Driver/hip-profile-rocm-runtime.hip (+12-1) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 5893f6f6b2915..b5ce9e0fda9a2 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -1282,6 +1282,7 @@ LTOKind AMDGPUToolChain::getLTOMode(const ArgList &Args,
                                     Action::OffloadKind Kind) const {
   if (getTriple().isAMDGCN() && getDriver().offloadDeviceOnly() &&
       !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false) &&
+      !ToolChain::needsProfileRT(Args) &&
       !Args.hasArg(options::OPT_foffload_lto, options::OPT_foffload_lto_EQ))
     return LTOK_None;
   return ToolChain::getLTOMode(Args, Kind);
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cpp
index 245cf642cf853..fb608bc1bb63b 100644
--- a/clang/lib/Driver/ToolChains/HIPAMD.cpp
+++ b/clang/lib/Driver/ToolChains/HIPAMD.cpp
@@ -141,6 +141,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, 
const JobAction &JA,
                              TargetID, /*IsBitCodeSDL=*/true);
 
   LldArgs.push_back("--no-whole-archive");
+  TC.addProfileRTLibs(Args, LldArgs);
 
   const char *Lld = 
Args.MakeArgStringRef(getToolChain().GetProgramPath("lld"));
   C.addCommand(std::make_unique<Command>(JA, *this, 
ResponseFileSupport::None(),
diff --git a/clang/test/Driver/hip-profile-rocm-runtime.hip 
b/clang/test/Driver/hip-profile-rocm-runtime.hip
index fc82db4fc13c0..c46560e97e506 100644
--- a/clang/test/Driver/hip-profile-rocm-runtime.hip
+++ b/clang/test/Driver/hip-profile-rocm-runtime.hip
@@ -3,9 +3,10 @@
 
 // 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
+// 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 +32,13 @@
 // RUN:   | FileCheck -check-prefix=HOST-PGO %s
 // HOST-PGO: "{{.*}}libclang_rt.profile.a"
 // HOST-PGO-NOT: libclang_rt.profile_rocm.a
+
+// HIP device-only code object builds with PGO link the AMDGPU profile runtime.
+// RUN: %clang -### -x hip --cuda-device-only \
+// RUN:   --target=x86_64-unknown-linux --offload-arch=gfx906 \
+// RUN:   -fprofile-generate -resource-dir=%t -nogpuinc -nogpulib %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=HIP-DEVICE-PGO %s
+// HIP-DEVICE-PGO-DAG: "-emit-llvm-bc"
+// HIP-DEVICE-PGO-DAG: "-flto=full"
+// HIP-DEVICE-PGO: "{{.*}}lld"
+// HIP-DEVICE-PGO-SAME: "--no-whole-archive" 
"{{.*}}lib{{/|\\\\}}amdgcn-amd-amdhsa{{/|\\\\}}libclang_rt.profile.a"

``````````

</details>


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

Reply via email to