[clang] [HIP][Clang][CodeGen] Handle hip bin symbols properly. (PR #107458)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 5 13:23:50 PDT 2024
https://github.com/jofrn updated https://github.com/llvm/llvm-project/pull/107458
>From 99c7e926632b9ca52c18689fdab3a3358de5a3b6 Mon Sep 17 00:00:00 2001
From: jofernau <Joe.Fernau at amd.com>
Date: Thu, 5 Sep 2024 16:05:21 -0400
Subject: [PATCH 1/2] [HIP][Clang][CodeGen] Handle hip bin symbols properly.
Remove '_' in fatbin symbol suffix when missing TU hash ID. Internalize gpubin symbol so that it is not unresolved at link-time.
---
clang/lib/CodeGen/CGCUDANV.cpp | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 59c5927717933d..66a874c8c567e7 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -840,8 +840,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
FatBinStr = new llvm::GlobalVariable(
CGM.getModule(), CGM.Int8Ty,
/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
- "__hip_fatbin_" + CGM.getContext().getCUIDHash(), nullptr,
- llvm::GlobalVariable::NotThreadLocal);
+ "__hip_fatbin" +
+ (CGM.getLangOpts().CUID.empty() ? ""
+ : "_" + CGM.getContext().getCUIDHash()),
+ nullptr, llvm::GlobalVariable::NotThreadLocal);
cast<llvm::GlobalVariable>(FatBinStr)->setSection(FatbinConstantName);
}
@@ -894,8 +896,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
// thread safety of the loaded program. Therefore we can assume sequential
// execution of constructor functions here.
if (IsHIP) {
- auto Linkage = CudaGpuBinary ? llvm::GlobalValue::InternalLinkage
- : llvm::GlobalValue::ExternalLinkage;
+ auto Linkage = llvm::GlobalValue::InternalLinkage;
llvm::BasicBlock *IfBlock =
llvm::BasicBlock::Create(Context, "if", ModuleCtorFunc);
llvm::BasicBlock *ExitBlock =
@@ -905,10 +906,7 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
GpuBinaryHandle = new llvm::GlobalVariable(
TheModule, PtrTy, /*isConstant=*/false, Linkage,
/*Initializer=*/
- CudaGpuBinary ? llvm::ConstantPointerNull::get(PtrTy) : nullptr,
- CudaGpuBinary
- ? "__hip_gpubin_handle"
- : "__hip_gpubin_handle_" + CGM.getContext().getCUIDHash());
+ llvm::ConstantPointerNull::get(PtrTy), "__hip_gpubin_handle");
GpuBinaryHandle->setAlignment(CGM.getPointerAlign().getAsAlign());
// Prevent the weak symbol in different shared libraries being merged.
if (Linkage != llvm::GlobalValue::InternalLinkage)
>From 938a1897fd886167bc27e5ff4e27c9f2c2418fb5 Mon Sep 17 00:00:00 2001
From: jofernau <Joe.Fernau at amd.com>
Date: Thu, 5 Sep 2024 16:23:21 -0400
Subject: [PATCH 2/2] Format
---
clang/lib/CodeGen/CGCUDANV.cpp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 66a874c8c567e7..8a2f61ae264274 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -840,10 +840,10 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
FatBinStr = new llvm::GlobalVariable(
CGM.getModule(), CGM.Int8Ty,
/*isConstant=*/true, llvm::GlobalValue::ExternalLinkage, nullptr,
- "__hip_fatbin" +
- (CGM.getLangOpts().CUID.empty() ? ""
- : "_" + CGM.getContext().getCUIDHash()),
- nullptr, llvm::GlobalVariable::NotThreadLocal);
+ "__hip_fatbin" + (CGM.getLangOpts().CUID.empty()
+ ? ""
+ : "_" + CGM.getContext().getCUIDHash()),
+ nullptr, llvm::GlobalVariable::NotThreadLocal);
cast<llvm::GlobalVariable>(FatBinStr)->setSection(FatbinConstantName);
}
More information about the cfe-commits
mailing list