Skip to content

Commit 3bf8816

Browse files
committed
[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.
1 parent d15c454 commit 3bf8816

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/lib/Frontend/Offloading/Utility.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ std::pair<Constant *, GlobalVariable *>
3333
offloading::getOffloadingEntryInitializer(Module &M, Constant *Addr,
3434
StringRef Name, uint64_t Size,
3535
int32_t Flags, int32_t Data) {
36+
llvm::Triple Triple(M.getTargetTriple());
3637
Type *Int8PtrTy = PointerType::getUnqual(M.getContext());
3738
Type *Int32Ty = Type::getInt32Ty(M.getContext());
3839
Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext());
3940

4041
Constant *AddrName = ConstantDataArray::getString(M.getContext(), Name);
4142

43+
StringRef Prefix = Triple.isNVPTX() ? "$omp_offloading$entry_name"
44+
: ".omp_offloading.entry_name";
45+
4246
// Create the constant string used to look up the symbol in the device.
43-
auto *Str = new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
44-
GlobalValue::InternalLinkage, AddrName,
45-
".omp_offloading.entry_name");
47+
auto *Str =
48+
new GlobalVariable(M, AddrName->getType(), /*isConstant=*/true,
49+
GlobalValue::InternalLinkage, AddrName, Prefix);
4650
Str->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
4751

4852
// Construct the offloading entry.
@@ -65,10 +69,12 @@ void offloading::emitOffloadingEntry(Module &M, Constant *Addr, StringRef Name,
6569
auto [EntryInitializer, NameGV] =
6670
getOffloadingEntryInitializer(M, Addr, Name, Size, Flags, Data);
6771

72+
StringRef Prefix =
73+
Triple.isNVPTX() ? "$omp_offloading$entry." : ".omp_offloading.entry.";
6874
auto *Entry = new GlobalVariable(
6975
M, getEntryTy(M),
7076
/*isConstant=*/true, GlobalValue::WeakAnyLinkage, EntryInitializer,
71-
".omp_offloading.entry." + Name, nullptr, GlobalValue::NotThreadLocal,
77+
Prefix + Name, nullptr, GlobalValue::NotThreadLocal,
7278
M.getDataLayout().getDefaultGlobalsAddressSpace());
7379

7480
// The entry has to be created in the section the linker expects it to be.

0 commit comments

Comments
 (0)