[llvm] 3bf8816 - [Offload] Fix entry global names on NVPTX target
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 06:42:14 PST 2024
Author: Joseph Huber
Date: 2024-02-05T08:42:02-06:00
New Revision: 3bf881635c9ca7398ba6a451e30a2156b22d59b5
URL: https://github.com/llvm/llvm-project/commit/3bf881635c9ca7398ba6a451e30a2156b22d59b5
DIFF: https://github.com/llvm/llvm-project/commit/3bf881635c9ca7398ba6a451e30a2156b22d59b5.diff
LOG: [Offload] Fix entry global names on NVPTX target
Summary:
The PTX language rejects globals with `.` in the name. We need to change
the global name if we are targeting NVPTX to prevent the toolchain from
complaining.
Added:
Modified:
llvm/lib/Frontend/Offloading/Utility.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Frontend/Offloading/Utility.cpp b/llvm/lib/Frontend/Offloading/Utility.cpp
index bd5b89b917706d..a3d24bfcc51510 100644
--- a/llvm/lib/Frontend/Offloading/Utility.cpp
+++ b/llvm/lib/Frontend/Offloading/Utility.cpp
@@ -33,16 +33,20 @@ std::pair<Constant *, GlobalVariable *>
offloading::getOffloadingEntryInitializer(Module &M, Constant *Addr,
StringRef Name, uint64_t Size,
int32_t Flags, int32_t Data) {
+ llvm::Triple Triple(M.getTargetTriple());
Type *Int8PtrTy = PointerType::getUnqual(M.getContext());
Type *Int32Ty = Type::getInt32Ty(M.getContext());
Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
Constant *AddrName = ConstantDataArray::getString(M.getContext(), Name);
+ StringRef Prefix = Triple.isNVPTX() ? "$omp_offloading$entry_name"
+ : ".omp_offloading.entry_name";
+
// Create the constant string used to look up the symbol in the device.
- auto *Str = new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
- GlobalValue::InternalLinkage, AddrName,
- ".omp_offloading.entry_name");
+ auto *Str =
+ new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
+ GlobalValue::InternalLinkage, AddrName, Prefix);
Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
// Construct the offloading entry.
@@ -65,10 +69,12 @@ void offloading::emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name,
auto [EntryInitializer, NameGV] =
getOffloadingEntryInitializer(M, Addr, Name, Size, Flags, Data);
+ StringRef Prefix =
+ Triple.isNVPTX() ? "$omp_offloading$entry." : ".omp_offloading.entry.";
auto *Entry = new GlobalVariable(
M, getEntryTy(M),
/*isConstant=*/true, GlobalValue::WeakAnyLinkage, EntryInitializer,
- ".omp_offloading.entry." + Name, nullptr, GlobalValue::NotThreadLocal,
+ Prefix + Name, nullptr, GlobalValue::NotThreadLocal,
M.getDataLayout().getDefaultGlobalsAddressSpace());
// The entry has to be created in the section the linker expects it to be.
More information about the llvm-commits
mailing list