@@ -8577,9 +8577,8 @@ OpenMPIRBuilder::createPlatformSpecificName(ArrayRef<StringRef> Parts) const {
85778577 Config.separator ());
85788578}
85798579
8580- GlobalVariable *
8581- OpenMPIRBuilder::getOrCreateInternalVariable (Type *Ty, const StringRef &Name,
8582- unsigned AddressSpace) {
8580+ GlobalVariable *OpenMPIRBuilder::getOrCreateInternalVariable (
8581+ Type *Ty, const StringRef &Name, std::optional<unsigned > AddressSpace) {
85838582 auto &Elem = *InternalVars.try_emplace (Name, nullptr ).first ;
85848583 if (Elem.second ) {
85858584 assert (Elem.second ->getValueType () == Ty &&
@@ -8590,24 +8589,17 @@ OpenMPIRBuilder::getOrCreateInternalVariable(Type *Ty, const StringRef &Name,
85908589 // create different versions of the function for different OMP internal
85918590 // variables.
85928591 const DataLayout &DL = M.getDataLayout ();
8593- // TODO: Investigate why AMDGPU expects AS 0 for globals even though the
8594- // default global AS is 1.
8595- // See double-target-call-with-declare-target.f90 and
8596- // declare-target-vars-in-target-region.f90 libomptarget
8597- // tests.
8598- unsigned AddressSpaceVal = AddressSpace ? AddressSpace
8599- : M.getTargetTriple ().isAMDGPU ()
8600- ? 0
8601- : DL.getDefaultGlobalsAddressSpace ();
8592+ unsigned AddressSpaceVal =
8593+ AddressSpace ? *AddressSpace : DL.getDefaultGlobalsAddressSpace ();
86028594 auto Linkage = this ->M .getTargetTriple ().getArch () == Triple::wasm32
86038595 ? GlobalValue::InternalLinkage
86048596 : GlobalValue::CommonLinkage;
86058597 auto *GV = new GlobalVariable (M, Ty, /* IsConstant=*/ false , Linkage,
86068598 Constant::getNullValue (Ty), Elem.first (),
86078599 /* InsertBefore=*/ nullptr ,
8608- GlobalValue::NotThreadLocal, AddressSpace );
8600+ GlobalValue::NotThreadLocal, AddressSpaceVal );
86098601 const llvm::Align TypeAlign = DL.getABITypeAlign (Ty);
8610- const llvm::Align PtrAlign = DL.getPointerABIAlignment (AddressSpace );
8602+ const llvm::Align PtrAlign = DL.getPointerABIAlignment (AddressSpaceVal );
86118603 GV->setAlignment (std::max (TypeAlign, PtrAlign));
86128604 Elem.second = GV;
86138605 }
0 commit comments