[clang] Avoid duplicating ProgramAddressSpace in TargetInfo. NFCI
This value was added to clang/Basic in D111566, but is only used during codegen, where we can use the LLVM IR DataLayout instead. I noticed this because the downstream CHERI targets would have to also set this value for AArch64/RISC-V/MIPS. Instead of duplicating more information between LLVM IR and Clang, this patch moves getTargetAddressSpace(QualType T) to CodeGenTypes, where we can consult the DataLayout. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138296
This commit is contained in:
parent
a11faeed44
commit
f3a17d0595
|
@ -2810,8 +2810,6 @@ public:
|
|||
/// long double and double on AArch64 will return 0).
|
||||
int getFloatingTypeSemanticOrder(QualType LHS, QualType RHS) const;
|
||||
|
||||
unsigned getTargetAddressSpace(QualType T) const;
|
||||
|
||||
unsigned getTargetAddressSpace(LangAS AS) const;
|
||||
|
||||
LangAS getLangASForBuiltinAddressSpace(unsigned AS) const;
|
||||
|
|
|
@ -232,7 +232,6 @@ protected:
|
|||
unsigned char RegParmMax, SSERegParmMax;
|
||||
TargetCXXABI TheCXXABI;
|
||||
const LangASMap *AddrSpaceMap;
|
||||
unsigned ProgramAddrSpace;
|
||||
|
||||
mutable StringRef PlatformName;
|
||||
mutable VersionTuple PlatformMinVersion;
|
||||
|
@ -822,9 +821,6 @@ public:
|
|||
return getTypeWidth(IntMaxType);
|
||||
}
|
||||
|
||||
/// Return the address space for functions for the given target.
|
||||
unsigned getProgramAddressSpace() const { return ProgramAddrSpace; }
|
||||
|
||||
// Return the size of unwind_word for this target.
|
||||
virtual unsigned getUnwindWordWidth() const {
|
||||
return getPointerWidth(LangAS::Default);
|
||||
|
|
|
@ -12227,16 +12227,6 @@ uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const {
|
|||
return getTargetInfo().getNullPointerValue(AS);
|
||||
}
|
||||
|
||||
unsigned ASTContext::getTargetAddressSpace(QualType T) const {
|
||||
// Return the address space for the type. If the type is a
|
||||
// function type without an address space qualifier, the
|
||||
// program address space is used. Otherwise, the target picks
|
||||
// the best address space based on the type information
|
||||
return T->isFunctionType() && !T.hasAddressSpace()
|
||||
? getTargetInfo().getProgramAddressSpace()
|
||||
: getTargetAddressSpace(T.getAddressSpace());
|
||||
}
|
||||
|
||||
unsigned ASTContext::getTargetAddressSpace(LangAS AS) const {
|
||||
if (isTargetAddressSpace(AS))
|
||||
return toTargetAddressSpace(AS);
|
||||
|
|
|
@ -155,8 +155,6 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Triple(T) {
|
|||
MaxOpenCLWorkGroupSize = 1024;
|
||||
|
||||
MaxBitIntWidth.reset();
|
||||
|
||||
ProgramAddrSpace = 0;
|
||||
}
|
||||
|
||||
// Out of line virtual dtor for TargetInfo.
|
||||
|
|
|
@ -55,7 +55,6 @@ public:
|
|||
Int16Type = SignedInt;
|
||||
Char32Type = UnsignedLong;
|
||||
SigAtomicType = SignedChar;
|
||||
ProgramAddrSpace = 1;
|
||||
resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
|
||||
}
|
||||
|
||||
|
|
|
@ -1635,7 +1635,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
|
|||
// sret things on win32 aren't void, they return the sret pointer.
|
||||
QualType ret = FI.getReturnType();
|
||||
llvm::Type *ty = ConvertType(ret);
|
||||
unsigned addressSpace = Context.getTargetAddressSpace(ret);
|
||||
unsigned addressSpace = CGM.getTypes().getTargetAddressSpace(ret);
|
||||
resultType = llvm::PointerType::get(ty, addressSpace);
|
||||
} else {
|
||||
resultType = llvm::Type::getVoidTy(getLLVMContext());
|
||||
|
@ -1659,7 +1659,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI) {
|
|||
if (IRFunctionArgs.hasSRetArg()) {
|
||||
QualType Ret = FI.getReturnType();
|
||||
llvm::Type *Ty = ConvertType(Ret);
|
||||
unsigned AddressSpace = Context.getTargetAddressSpace(Ret);
|
||||
unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(Ret);
|
||||
ArgTypes[IRFunctionArgs.getSRetArgNo()] =
|
||||
llvm::PointerType::get(Ty, AddressSpace);
|
||||
}
|
||||
|
@ -2385,7 +2385,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
|
|||
if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
|
||||
RetAttrs.addDereferenceableAttr(
|
||||
getMinimumObjectSize(PTy).getQuantity());
|
||||
if (getContext().getTargetAddressSpace(PTy) == 0 &&
|
||||
if (getTypes().getTargetAddressSpace(PTy) == 0 &&
|
||||
!CodeGenOpts.NullPointerIsValid)
|
||||
RetAttrs.addAttribute(llvm::Attribute::NonNull);
|
||||
if (PTy->isObjectType()) {
|
||||
|
@ -2434,7 +2434,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
|
|||
FI.arg_begin()->type.castAs<PointerType>()->getPointeeType();
|
||||
|
||||
if (!CodeGenOpts.NullPointerIsValid &&
|
||||
getContext().getTargetAddressSpace(FI.arg_begin()->type) == 0) {
|
||||
getTypes().getTargetAddressSpace(FI.arg_begin()->type) == 0) {
|
||||
Attrs.addAttribute(llvm::Attribute::NonNull);
|
||||
Attrs.addDereferenceableAttr(getMinimumObjectSize(ThisTy).getQuantity());
|
||||
} else {
|
||||
|
@ -2561,7 +2561,7 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
|
|||
if (!PTy->isIncompleteType() && PTy->isConstantSizeType())
|
||||
Attrs.addDereferenceableAttr(
|
||||
getMinimumObjectSize(PTy).getQuantity());
|
||||
if (getContext().getTargetAddressSpace(PTy) == 0 &&
|
||||
if (getTypes().getTargetAddressSpace(PTy) == 0 &&
|
||||
!CodeGenOpts.NullPointerIsValid)
|
||||
Attrs.addAttribute(llvm::Attribute::NonNull);
|
||||
if (PTy->isObjectType()) {
|
||||
|
@ -2883,7 +2883,7 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
|
|||
llvm::Align Alignment =
|
||||
CGM.getNaturalTypeAlignment(ETy).getAsAlign();
|
||||
AI->addAttrs(llvm::AttrBuilder(getLLVMContext()).addAlignmentAttr(Alignment));
|
||||
if (!getContext().getTargetAddressSpace(ETy) &&
|
||||
if (!getTypes().getTargetAddressSpace(ETy) &&
|
||||
!CGM.getCodeGenOpts().NullPointerIsValid)
|
||||
AI->addAttr(llvm::Attribute::NonNull);
|
||||
}
|
||||
|
|
|
@ -1149,7 +1149,7 @@ llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
|
|||
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
||||
auto Align = getTypeAlignIfRequired(Ty, CGM.getContext());
|
||||
Optional<unsigned> DWARFAddressSpace = CGM.getTarget().getDWARFAddressSpace(
|
||||
CGM.getContext().getTargetAddressSpace(PointeeTy));
|
||||
CGM.getTypes().getTargetAddressSpace(PointeeTy));
|
||||
|
||||
SmallVector<llvm::Metadata *, 4> Annots;
|
||||
auto *BTFAttrTy = dyn_cast<BTFTagAttributedType>(PointeeTy);
|
||||
|
@ -4454,7 +4454,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
|
|||
|
||||
auto Align = getDeclAlignIfRequired(VD, CGM.getContext());
|
||||
|
||||
unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(VD->getType());
|
||||
unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->getType());
|
||||
AppendAddressSpaceXDeref(AddressSpace, Expr);
|
||||
|
||||
// If this is implicit parameter of CXXThis or ObjCSelf kind, then give it an
|
||||
|
@ -4615,7 +4615,7 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const BindingDecl *BD,
|
|||
return nullptr;
|
||||
|
||||
auto Align = getDeclAlignIfRequired(BD, CGM.getContext());
|
||||
unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(BD->getType());
|
||||
unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->getType());
|
||||
|
||||
SmallVector<uint64_t, 3> Expr;
|
||||
AppendAddressSpaceXDeref(AddressSpace, Expr);
|
||||
|
@ -5294,8 +5294,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
|
|||
auto Align = getDeclAlignIfRequired(D, CGM.getContext());
|
||||
|
||||
SmallVector<uint64_t, 4> Expr;
|
||||
unsigned AddressSpace =
|
||||
CGM.getContext().getTargetAddressSpace(D->getType());
|
||||
unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->getType());
|
||||
if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
|
||||
if (D->hasAttr<CUDASharedAttr>())
|
||||
AddressSpace =
|
||||
|
|
|
@ -195,7 +195,7 @@ void CodeGenFunction::EmitCXXGlobalVarDeclInit(const VarDecl &D,
|
|||
// For example, in the above CUDA code, the static local variable s has a
|
||||
// "shared" address space qualifier, but the constructor of StructWithCtor
|
||||
// expects "this" in the "generic" address space.
|
||||
unsigned ExpectedAddrSpace = getContext().getTargetAddressSpace(T);
|
||||
unsigned ExpectedAddrSpace = getTypes().getTargetAddressSpace(T);
|
||||
unsigned ActualAddrSpace = GV->getAddressSpace();
|
||||
llvm::Constant *DeclPtr = GV;
|
||||
if (ActualAddrSpace != ExpectedAddrSpace) {
|
||||
|
|
|
@ -2747,7 +2747,7 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
|
|||
getContext().getDeclAlign(VD));
|
||||
llvm::Type *VarTy = getTypes().ConvertTypeForMem(VD->getType());
|
||||
auto *PTy = llvm::PointerType::get(
|
||||
VarTy, getContext().getTargetAddressSpace(VD->getType()));
|
||||
VarTy, getTypes().getTargetAddressSpace(VD->getType()));
|
||||
Addr = Builder.CreatePointerBitCastOrAddrSpaceCast(Addr, PTy, VarTy);
|
||||
} else {
|
||||
// Should we be using the alignment of the constant pointer we emitted?
|
||||
|
|
|
@ -3133,7 +3133,7 @@ CGOpenMPRuntimeGPU::getParameterAddress(CodeGenFunction &CGF,
|
|||
const Type *NonQualTy = QC.strip(NativeParamType);
|
||||
QualType NativePointeeTy = cast<ReferenceType>(NonQualTy)->getPointeeType();
|
||||
unsigned NativePointeeAddrSpace =
|
||||
CGF.getContext().getTargetAddressSpace(NativePointeeTy);
|
||||
CGF.getTypes().getTargetAddressSpace(NativePointeeTy);
|
||||
QualType TargetTy = TargetParam->getType();
|
||||
llvm::Value *TargetAddr = CGF.EmitLoadOfScalar(
|
||||
LocalAddr, /*Volatile=*/false, TargetTy, SourceLocation());
|
||||
|
|
|
@ -3196,7 +3196,7 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) {
|
|||
// See if there is already something with the target's name in the module.
|
||||
llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee());
|
||||
if (Entry) {
|
||||
unsigned AS = getContext().getTargetAddressSpace(VD->getType());
|
||||
unsigned AS = getTypes().getTargetAddressSpace(VD->getType());
|
||||
auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
|
||||
return ConstantAddress(Ptr, DeclTy, Alignment);
|
||||
}
|
||||
|
@ -3761,7 +3761,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
|
|||
if (getTarget().supportsIFunc()) {
|
||||
ResolverType = llvm::FunctionType::get(
|
||||
llvm::PointerType::get(DeclTy,
|
||||
Context.getTargetAddressSpace(FD->getType())),
|
||||
getTypes().getTargetAddressSpace(FD->getType())),
|
||||
false);
|
||||
}
|
||||
else {
|
||||
|
@ -3899,8 +3899,8 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
|
|||
// cpu_dispatch will be emitted in this translation unit.
|
||||
if (getTarget().supportsIFunc() && !FD->isCPUSpecificMultiVersion()) {
|
||||
llvm::Type *ResolverType = llvm::FunctionType::get(
|
||||
llvm::PointerType::get(
|
||||
DeclTy, getContext().getTargetAddressSpace(FD->getType())),
|
||||
llvm::PointerType::get(DeclTy,
|
||||
getTypes().getTargetAddressSpace(FD->getType())),
|
||||
false);
|
||||
llvm::Constant *Resolver = GetOrCreateLLVMFunction(
|
||||
MangledName + ".resolver", ResolverType, GlobalDecl{},
|
||||
|
|
|
@ -655,7 +655,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
|||
const ReferenceType *RTy = cast<ReferenceType>(Ty);
|
||||
QualType ETy = RTy->getPointeeType();
|
||||
llvm::Type *PointeeType = ConvertTypeForMem(ETy);
|
||||
unsigned AS = Context.getTargetAddressSpace(ETy);
|
||||
unsigned AS = getTargetAddressSpace(ETy);
|
||||
ResultType = llvm::PointerType::get(PointeeType, AS);
|
||||
break;
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
|
|||
llvm::Type *PointeeType = ConvertTypeForMem(ETy);
|
||||
if (PointeeType->isVoidTy())
|
||||
PointeeType = llvm::Type::getInt8Ty(getLLVMContext());
|
||||
unsigned AS = Context.getTargetAddressSpace(ETy);
|
||||
unsigned AS = getTargetAddressSpace(ETy);
|
||||
ResultType = llvm::PointerType::get(PointeeType, AS);
|
||||
break;
|
||||
}
|
||||
|
@ -958,3 +958,13 @@ bool CodeGenTypes::isZeroInitializable(QualType T) {
|
|||
bool CodeGenTypes::isZeroInitializable(const RecordDecl *RD) {
|
||||
return getCGRecordLayout(RD).isZeroInitializable();
|
||||
}
|
||||
|
||||
unsigned CodeGenTypes::getTargetAddressSpace(QualType T) const {
|
||||
// Return the address space for the type. If the type is a
|
||||
// function type without an address space qualifier, the
|
||||
// program address space is used. Otherwise, the target picks
|
||||
// the best address space based on the type information
|
||||
return T->isFunctionType() && !T.hasAddressSpace()
|
||||
? getDataLayout().getProgramAddressSpace()
|
||||
: getContext().getTargetAddressSpace(T.getAddressSpace());
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ public: // These are internal details of CGT that shouldn't be used externally.
|
|||
bool isRecordBeingLaidOut(const Type *Ty) const {
|
||||
return RecordsBeingLaidOut.count(Ty);
|
||||
}
|
||||
|
||||
unsigned getTargetAddressSpace(QualType T) const;
|
||||
};
|
||||
|
||||
} // end namespace CodeGen
|
||||
|
|
Loading…
Reference in New Issue