aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2024-02-05 08:36:44 -0600
committerJoseph Huber <huberjn@outlook.com>2024-02-05 08:42:02 -0600
commit3bf881635c9ca7398ba6a451e30a2156b22d59b5 (patch)
tree03dfad2edb121e7fcba24b66ce2847fff32647cd
parentd15c454bedc05775b5080e1d2130b0554d5e5a81 (diff)
downloadllvm-3bf881635c9ca7398ba6a451e30a2156b22d59b5.zip
llvm-3bf881635c9ca7398ba6a451e30a2156b22d59b5.tar.gz
llvm-3bf881635c9ca7398ba6a451e30a2156b22d59b5.tar.bz2
[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.
-rw-r--r--llvm/lib/Frontend/Offloading/Utility.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Frontend/Offloading/Utility.cpp b/llvm/lib/Frontend/Offloading/Utility.cpp
index bd5b89b..a3d24bf 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.