Skip to content

Commit

Permalink
[Offload] Fix entry global names on NVPTX target
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Feb 5, 2024
1 parent d15c454 commit 3bf8816
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions llvm/lib/Frontend/Offloading/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 3bf8816

Please sign in to comment.