@@ -2851,7 +2851,8 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
2851
2851
GlobalDecl (cast<FunctionDecl>(VD)),
2852
2852
/* ForVTable=*/ false );
2853
2853
else
2854
- Aliasee = GetOrCreateLLVMGlobal (AA->getAliasee (), DeclTy, 0 , nullptr );
2854
+ Aliasee = GetOrCreateLLVMGlobal (AA->getAliasee (), DeclTy, LangAS::Default,
2855
+ nullptr );
2855
2856
2856
2857
auto *F = cast<llvm::GlobalValue>(Aliasee);
2857
2858
F->setLinkage (llvm::Function::ExternalWeakLinkage);
@@ -3824,10 +3825,11 @@ bool CodeGenModule::isTypeConstant(QualType Ty, bool ExcludeCtor) {
3824
3825
// / mangled name but some other type.
3825
3826
llvm::Constant *
3826
3827
CodeGenModule::GetOrCreateLLVMGlobal (StringRef MangledName, llvm::Type *Ty,
3827
- unsigned AddrSpace, const VarDecl *D,
3828
+ LangAS AddrSpace, const VarDecl *D,
3828
3829
ForDefinition_t IsForDefinition) {
3829
3830
// Lookup the entry, lazily creating it if necessary.
3830
3831
llvm::GlobalValue *Entry = GetGlobalValue (MangledName);
3832
+ unsigned TargetAS = getContext ().getTargetAddressSpace (AddrSpace);
3831
3833
if (Entry) {
3832
3834
if (WeakRefReferences.erase (Entry)) {
3833
3835
if (D && !D->hasAttr <WeakAttr>())
@@ -3841,7 +3843,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
3841
3843
if (LangOpts.OpenMP && !LangOpts.OpenMPSimd && D)
3842
3844
getOpenMPRuntime ().registerTargetGlobalVariable (D, Entry);
3843
3845
3844
- if (Entry->getValueType () == Ty && Entry->getAddressSpace () == AddrSpace )
3846
+ if (Entry->getValueType () == Ty && Entry->getAddressSpace () == TargetAS )
3845
3847
return Entry;
3846
3848
3847
3849
// If there are two attempts to define the same mangled name, issue an
@@ -3865,24 +3867,23 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
3865
3867
}
3866
3868
3867
3869
// Make sure the result is of the correct type.
3868
- if (Entry->getType ()->getAddressSpace () != AddrSpace ) {
3870
+ if (Entry->getType ()->getAddressSpace () != TargetAS ) {
3869
3871
return llvm::ConstantExpr::getAddrSpaceCast (Entry,
3870
- Ty->getPointerTo (AddrSpace ));
3872
+ Ty->getPointerTo (TargetAS ));
3871
3873
}
3872
3874
3873
3875
// (If global is requested for a definition, we always need to create a new
3874
3876
// global, not just return a bitcast.)
3875
3877
if (!IsForDefinition)
3876
- return llvm::ConstantExpr::getBitCast (Entry, Ty->getPointerTo (AddrSpace ));
3878
+ return llvm::ConstantExpr::getBitCast (Entry, Ty->getPointerTo (TargetAS ));
3877
3879
}
3878
3880
3879
3881
auto DAddrSpace = GetGlobalVarAddressSpace (D);
3880
- auto TargetAddrSpace = getContext ().getTargetAddressSpace (DAddrSpace);
3881
3882
3882
3883
auto *GV = new llvm::GlobalVariable (
3883
3884
getModule (), Ty, false , llvm::GlobalValue::ExternalLinkage, nullptr ,
3884
3885
MangledName, nullptr , llvm::GlobalVariable::NotThreadLocal,
3885
- TargetAddrSpace );
3886
+ getContext (). getTargetAddressSpace (DAddrSpace) );
3886
3887
3887
3888
// If we already created a global with the same mangled name (but different
3888
3889
// type) before, take its name and remove it from its parent.
@@ -4005,10 +4006,10 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Type *Ty,
4005
4006
LangAS ExpectedAS =
4006
4007
D ? D->getType ().getAddressSpace ()
4007
4008
: (LangOpts.OpenCL ? LangAS::opencl_global : LangAS::Default);
4008
- assert (getContext ().getTargetAddressSpace (ExpectedAS) == AddrSpace );
4009
+ assert (getContext ().getTargetAddressSpace (ExpectedAS) == TargetAS );
4009
4010
if (DAddrSpace != ExpectedAS) {
4010
4011
return getTargetCodeGenInfo ().performAddrSpaceCast (
4011
- *this , GV, DAddrSpace, ExpectedAS, Ty->getPointerTo (AddrSpace ));
4012
+ *this , GV, DAddrSpace, ExpectedAS, Ty->getPointerTo (TargetAS ));
4012
4013
}
4013
4014
4014
4015
return GV;
@@ -4098,8 +4099,7 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
4098
4099
Ty = getTypes ().ConvertTypeForMem (ASTTy);
4099
4100
4100
4101
StringRef MangledName = getMangledName (D);
4101
- return GetOrCreateLLVMGlobal (MangledName, Ty,
4102
- getContext ().getTargetAddressSpace (ASTTy), D,
4102
+ return GetOrCreateLLVMGlobal (MangledName, Ty, ASTTy.getAddressSpace (), D,
4103
4103
IsForDefinition);
4104
4104
}
4105
4105
@@ -4108,10 +4108,8 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
4108
4108
llvm::Constant *
4109
4109
CodeGenModule::CreateRuntimeVariable (llvm::Type *Ty,
4110
4110
StringRef Name) {
4111
- auto AddrSpace =
4112
- getContext ().getLangOpts ().OpenCL
4113
- ? getContext ().getTargetAddressSpace (LangAS::opencl_global)
4114
- : 0 ;
4111
+ LangAS AddrSpace = getContext ().getLangOpts ().OpenCL ? LangAS::opencl_global
4112
+ : LangAS::Default;
4115
4113
auto *Ret = GetOrCreateLLVMGlobal (Name, Ty, AddrSpace, nullptr );
4116
4114
setDSOLocal (cast<llvm::GlobalValue>(Ret->stripPointerCasts ()));
4117
4115
return Ret;
@@ -4528,8 +4526,8 @@ void CodeGenModule::EmitExternalVarDeclaration(const VarDecl *D) {
4528
4526
if (getCodeGenOpts ().hasReducedDebugInfo ()) {
4529
4527
QualType ASTTy = D->getType ();
4530
4528
llvm::Type *Ty = getTypes ().ConvertTypeForMem (D->getType ());
4531
- llvm::Constant *GV = GetOrCreateLLVMGlobal (
4532
- D->getName (), Ty, getContext (). getTargetAddressSpace (ASTTy ), D);
4529
+ llvm::Constant *GV =
4530
+ GetOrCreateLLVMGlobal ( D->getName (), Ty, ASTTy. getAddressSpace ( ), D);
4533
4531
DI->EmitExternalVariable (
4534
4532
cast<llvm::GlobalVariable>(GV->stripPointerCasts ()), D);
4535
4533
}
@@ -4901,7 +4899,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
4901
4899
/* ForVTable=*/ false );
4902
4900
LT = getFunctionLinkage (GD);
4903
4901
} else {
4904
- Aliasee = GetOrCreateLLVMGlobal (AA->getAliasee (), DeclTy, 0 ,
4902
+ Aliasee = GetOrCreateLLVMGlobal (AA->getAliasee (), DeclTy, LangAS::Default ,
4905
4903
/* D=*/ nullptr );
4906
4904
if (const auto *VD = dyn_cast<VarDecl>(GD.getDecl ()))
4907
4905
LT = getLLVMLinkageVarDefinition (VD, D->getType ().isConstQualified ());
0 commit comments