From: Guillaume Chatelet Date: Fri, 13 Jan 2023 15:01:09 +0000 (+0000) Subject: [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment X-Git-Tag: upstream/17.0.6~21035 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bf5c17ed0f402f603782d28264dab1157994c43d;p=platform%2Fupstream%2Fllvm.git [clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignment --- diff --git a/clang/include/clang/AST/CharUnits.h b/clang/include/clang/AST/CharUnits.h index ee0d402..c063544 100644 --- a/clang/include/clang/AST/CharUnits.h +++ b/clang/include/clang/AST/CharUnits.h @@ -64,9 +64,9 @@ namespace clang { return CharUnits(Quantity); } - /// fromAlign - Construct a CharUnits quantity from an llvm::Align + /// fromQuantity - Construct a CharUnits quantity from an llvm::Align /// quantity. - static CharUnits fromAlign(llvm::Align Quantity) { + static CharUnits fromQuantity(llvm::Align Quantity) { return CharUnits(Quantity.value()); } diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp index 1a4be44..6e4a0db 100644 --- a/clang/lib/CodeGen/CGBlocks.cpp +++ b/clang/lib/CodeGen/CGBlocks.cpp @@ -522,7 +522,7 @@ static void initializeForBlockHeader(CodeGenModule &CGM, CGBlockInfo &info, for (auto *I : Helper->getCustomFieldTypes()) /* custom fields */ { // TargetOpenCLBlockHelp needs to make sure the struct is packed. // If necessary, add padding fields to the custom fields. - unsigned Align = CGM.getDataLayout().getABITypeAlignment(I); + unsigned Align = CGM.getDataLayout().getABITypeAlign(I).value(); if (BlockAlign < Align) BlockAlign = Align; assert(Offset % Align == 0); @@ -2672,7 +2672,7 @@ const BlockByrefInfo &CodeGenFunction::getBlockByrefInfo(const VarDecl *D) { size = varOffset; // Conversely, we might have to prevent LLVM from inserting padding. - } else if (CGM.getDataLayout().getABITypeAlignment(varTy) > + } else if (CGM.getDataLayout().getABITypeAlign(varTy) > uint64_t(varAlign.getQuantity())) { packed = true; } diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index b8de9fb..276d91f 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1149,7 +1149,7 @@ static Address CreateTempAllocaForCoercion(CodeGenFunction &CGF, llvm::Type *Ty, const Twine &Name = "tmp") { // Don't use an alignment that's worse than what LLVM would prefer. auto PrefAlign = CGF.CGM.getDataLayout().getPrefTypeAlign(Ty); - CharUnits Align = std::max(MinAlign, CharUnits::fromAlign(PrefAlign)); + CharUnits Align = std::max(MinAlign, CharUnits::fromQuantity(PrefAlign)); return CGF.CreateTempAlloca(Ty, Align, Name + ".coerce"); } @@ -5166,7 +5166,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, // Materialize to a temporary. addr = CreateTempAlloca( RV.getScalarVal()->getType(), - CharUnits::fromAlign(std::max(layout->getAlignment(), scalarAlign)), + CharUnits::fromQuantity(std::max(layout->getAlignment(), scalarAlign)), "tmp", /*ArraySize=*/nullptr, &AllocaAddr); tempSize = EmitLifetimeStart(scalarSize, AllocaAddr.getPointer()); diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index ad7871d..ca665db 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -123,7 +123,7 @@ llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(llvm::Type *Ty, Address CodeGenFunction::CreateDefaultAlignTempAlloca(llvm::Type *Ty, const Twine &Name) { CharUnits Align = - CharUnits::fromAlign(CGM.getDataLayout().getPrefTypeAlign(Ty)); + CharUnits::fromQuantity(CGM.getDataLayout().getPrefTypeAlign(Ty)); return CreateTempAlloca(Ty, Align, Name); } diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 7dc1052..8e74f02 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/lib/CodeGen/CGExprConstant.cpp @@ -46,7 +46,7 @@ struct ConstantAggregateBuilderUtils { CharUnits getAlignment(const llvm::Constant *C) const { return CharUnits::fromQuantity( - CGM.getDataLayout().getABITypeAlignment(C->getType())); + CGM.getDataLayout().getABITypeAlign(C->getType())); } CharUnits getSize(llvm::Type *Ty) const { diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index ce31d67..c739d374 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -6208,8 +6208,7 @@ void CGObjCNonFragileABIMac::AddModuleClassList( llvm::GlobalVariable *GV = new llvm::GlobalVariable( CGM.getModule(), Init->getType(), false, llvm::GlobalValue::PrivateLinkage, Init, SymbolName); - GV->setAlignment( - llvm::Align(CGM.getDataLayout().getABITypeAlignment(Init->getType()))); + GV->setAlignment(CGM.getDataLayout().getABITypeAlign(Init->getType())); GV->setSection(SectionName); CGM.addCompilerUsedGlobal(GV); } @@ -6441,8 +6440,7 @@ CGObjCNonFragileABIMac::BuildClassObject(const ObjCInterfaceDecl *CI, if (CGM.getTriple().isOSBinFormatMachO()) GV->setSection("__DATA, __objc_data"); - GV->setAlignment(llvm::Align( - CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassnfABITy))); + GV->setAlignment(CGM.getDataLayout().getABITypeAlign(ObjCTypes.ClassnfABITy)); if (!CGM.getTriple().isOSBinFormatCOFF()) if (HiddenVisibility) GV->setVisibility(llvm::GlobalValue::HiddenVisibility); @@ -6903,8 +6901,8 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const ObjCInterfaceDecl *ID, llvm::GlobalVariable *IvarOffsetGV = ObjCIvarOffsetVariable(ID, Ivar); IvarOffsetGV->setInitializer( llvm::ConstantInt::get(ObjCTypes.IvarOffsetVarTy, Offset)); - IvarOffsetGV->setAlignment(llvm::Align( - CGM.getDataLayout().getABITypeAlignment(ObjCTypes.IvarOffsetVarTy))); + IvarOffsetGV->setAlignment( + CGM.getDataLayout().getABITypeAlign(ObjCTypes.IvarOffsetVarTy)); if (!CGM.getTriple().isOSBinFormatCOFF()) { // FIXME: This matches gcc, but shouldn't the visibility be set on the use @@ -7132,8 +7130,8 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( ProtocolRef); if (!CGM.getTriple().isOSBinFormatMachO()) PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef)); - PTGV->setAlignment(llvm::Align( - CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ProtocolnfABIPtrTy))); + PTGV->setAlignment( + CGM.getDataLayout().getABITypeAlign(ObjCTypes.ProtocolnfABIPtrTy)); PTGV->setSection(GetSectionName("__objc_protolist", "coalesced,no_dead_strip")); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index 6f85bca..596f0bd 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -162,7 +162,7 @@ struct CGRecordLowering { return CharUnits::fromQuantity(DataLayout.getTypeAllocSize(Type)); } CharUnits getAlignment(llvm::Type *Type) { - return CharUnits::fromQuantity(DataLayout.getABITypeAlignment(Type)); + return CharUnits::fromQuantity(DataLayout.getABITypeAlign(Type)); } bool isZeroInitializable(const FieldDecl *FD) { return Types.isZeroInitializable(FD->getType()); diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp index ebac919..d0c8e35 100644 --- a/clang/lib/CodeGen/CGVTT.cpp +++ b/clang/lib/CodeGen/CGVTT.cpp @@ -114,7 +114,7 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) { llvm::ArrayType *ArrayType = llvm::ArrayType::get(CGM.Int8PtrTy, Builder.getVTTComponents().size()); - unsigned Align = CGM.getDataLayout().getABITypeAlignment(CGM.Int8PtrTy); + llvm::Align Align = CGM.getDataLayout().getABITypeAlign(CGM.Int8PtrTy); llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable( Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align); diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 354a3f9..a0b5d9e 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -909,7 +909,7 @@ llvm::GlobalVariable *CodeGenVTables::GenerateConstructionVTable( if (Linkage == llvm::GlobalVariable::AvailableExternallyLinkage) Linkage = llvm::GlobalVariable::InternalLinkage; - unsigned Align = CGM.getDataLayout().getABITypeAlignment(VTType); + llvm::Align Align = CGM.getDataLayout().getABITypeAlign(VTType); // Create the variable that will hold the construction vtable. llvm::GlobalVariable *VTable = diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 66f6058..5282874 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -4850,7 +4850,7 @@ DominatingLLVMValue::save(CodeGenFunction &CGF, llvm::Value *value) { if (!needsSaving(value)) return saved_type(value, false); // Otherwise, we need an alloca. - auto align = CharUnits::fromAlign( + auto align = CharUnits::fromQuantity( CGF.CGM.getDataLayout().getPrefTypeAlign(value->getType())); Address alloca = CGF.CreateTempAlloca(value->getType(), align, "cond-cleanup.save"); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b85d892..6e37676 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4565,7 +4565,7 @@ CodeGenModule::GetAddrOfGlobal(GlobalDecl GD, ForDefinition_t IsForDefinition) { llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable( StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, - unsigned Alignment) { + llvm::Align Alignment) { llvm::GlobalVariable *GV = getModule().getNamedGlobal(Name); llvm::GlobalVariable *OldGV = nullptr; @@ -4601,7 +4601,7 @@ llvm::GlobalVariable *CodeGenModule::CreateOrReplaceCXXRuntimeVariable( !GV->hasAvailableExternallyLinkage()) GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); - GV->setAlignment(llvm::MaybeAlign(Alignment)); + GV->setAlignment(Alignment); return GV; } diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 4595dd5..d23f5a9 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -880,7 +880,7 @@ public: llvm::GlobalVariable * CreateOrReplaceCXXRuntimeVariable(StringRef Name, llvm::Type *Ty, llvm::GlobalValue::LinkageTypes Linkage, - unsigned Alignment); + llvm::Align Alignment); llvm::Function *CreateGlobalInitOrCleanUpFunction( llvm::FunctionType *ty, const Twine &name, const CGFunctionInfo &FI, diff --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp b/clang/lib/CodeGen/ConstantInitBuilder.cpp index 18068a1..3cf69f3 100644 --- a/clang/lib/CodeGen/ConstantInitBuilder.cpp +++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp @@ -209,8 +209,7 @@ ConstantAggregateBuilderBase::addPlaceholderWithSize(llvm::Type *type) { // Advance the offset past that field. auto &layout = Builder.CGM.getDataLayout(); if (!Packed) - offset = offset.alignTo(CharUnits::fromQuantity( - layout.getABITypeAlignment(type))); + offset = offset.alignTo(CharUnits::fromQuantity(layout.getABITypeAlign(type))); offset += CharUnits::fromQuantity(layout.getTypeStoreSize(type)); CachedOffsetEnd = Builder.Buffer.size(); @@ -249,8 +248,8 @@ CharUnits ConstantAggregateBuilderBase::getOffsetFromGlobalTo(size_t end) const{ "cannot compute offset when a placeholder is present"); llvm::Type *elementType = element->getType(); if (!Packed) - offset = offset.alignTo(CharUnits::fromQuantity( - layout.getABITypeAlignment(elementType))); + offset = offset.alignTo( + CharUnits::fromQuantity(layout.getABITypeAlign(elementType))); offset += CharUnits::fromQuantity(layout.getTypeStoreSize(elementType)); } while (++cacheEnd != end); } diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp index 62561c9..1840303 100644 --- a/clang/lib/CodeGen/ItaniumCXXABI.cpp +++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -1883,7 +1883,7 @@ llvm::GlobalVariable *ItaniumCXXABI::getAddrOfVTable(const CXXRecordDecl *RD, VTable = CGM.CreateOrReplaceCXXRuntimeVariable( Name, VTableType, llvm::GlobalValue::ExternalLinkage, - getContext().toCharUnitsFromBits(PAlign).getQuantity()); + getContext().toCharUnitsFromBits(PAlign).getAsAlign()); VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); // In MS C++ if you have a class with virtual functions in which you are using @@ -2368,8 +2368,8 @@ void ItaniumCXXABI::EmitGuardedInit(CodeGenFunction &CGF, guardAlignment = CGF.getSizeAlign(); } else { guardTy = CGF.Int64Ty; - guardAlignment = CharUnits::fromQuantity( - CGM.getDataLayout().getABITypeAlignment(guardTy)); + guardAlignment = + CharUnits::fromQuantity(CGM.getDataLayout().getABITypeAlign(guardTy)); } } llvm::PointerType *guardPtrTy = guardTy->getPointerTo( @@ -3181,7 +3181,7 @@ llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName( auto Align = CGM.getContext().getTypeAlignInChars(CGM.getContext().CharTy); llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable( - Name, Init->getType(), Linkage, Align.getQuantity()); + Name, Init->getType(), Linkage, Align.getAsAlign()); GV->setInitializer(Init); diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp index 81a383c..ae785cc 100644 --- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp +++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp @@ -2123,7 +2123,7 @@ MicrosoftCXXABI::getAddrOfVBTable(const VPtrInfo &VBT, const CXXRecordDecl *RD, CharUnits Alignment = CGM.getContext().getTypeAlignInChars(CGM.getContext().IntTy); llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable( - Name, VBTableType, Linkage, Alignment.getQuantity()); + Name, VBTableType, Linkage, Alignment.getAsAlign()); GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); if (RD->hasAttr()) diff --git a/clang/lib/CodeGen/SwiftCallingConv.cpp b/clang/lib/CodeGen/SwiftCallingConv.cpp index e1bb98d..d4c6c96 100644 --- a/clang/lib/CodeGen/SwiftCallingConv.cpp +++ b/clang/lib/CodeGen/SwiftCallingConv.cpp @@ -590,9 +590,8 @@ SwiftAggLowering::getCoerceAndExpandTypes() const { hasPadding = true; } - if (!packed && !entry.Begin.isMultipleOf( - CharUnits::fromQuantity( - CGM.getDataLayout().getABITypeAlignment(entry.Type)))) + if (!packed && !entry.Begin.isMultipleOf(CharUnits::fromQuantity( + CGM.getDataLayout().getABITypeAlign(entry.Type)))) packed = true; elts.push_back(entry.Type); @@ -662,7 +661,7 @@ CharUnits swiftcall::getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type) { if (!isPowerOf2(size)) { size = 1ULL << (llvm::findLastSet(size, llvm::ZB_Undefined) + 1); } - assert(size >= CGM.getDataLayout().getABITypeAlignment(type)); + assert(CGM.getDataLayout().getABITypeAlign(type) <= size); return CharUnits::fromQuantity(size); } diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index e07ff8a..4c3bdbc 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -3592,7 +3592,7 @@ GetX86_64ByValArgumentPair(llvm::Type *Lo, llvm::Type *Hi, // (e.g. i32 and i32) then the resultant struct type ({i32,i32}) won't have // the second element at offset 8. Check for this: unsigned LoSize = (unsigned)TD.getTypeAllocSize(Lo); - unsigned HiAlign = TD.getABITypeAlignment(Hi); + llvm::Align HiAlign = TD.getABITypeAlign(Hi); unsigned HiStart = llvm::alignTo(LoSize, HiAlign); assert(HiStart != 0 && HiStart <= 8 && "Invalid x86-64 argument pair!"); @@ -4169,13 +4169,13 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, // FIXME: Our choice of alignment here and below is probably pessimistic. llvm::Value *V = CGF.Builder.CreateAlignedLoad( TyLo, CGF.Builder.CreateBitCast(RegLoAddr, PTyLo), - CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(TyLo))); + CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyLo))); CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0)); // Copy the second element. V = CGF.Builder.CreateAlignedLoad( TyHi, CGF.Builder.CreateBitCast(RegHiAddr, PTyHi), - CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(TyHi))); + CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi))); CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1)); RegAddr = CGF.Builder.CreateElementBitCast(Tmp, LTy); @@ -11204,7 +11204,7 @@ ABIArgInfo RISCVABIInfo::coerceAndExpandFPCCEligibleStruct( } CharUnits Field2Align = - CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(Field2Ty)); + CharUnits::fromQuantity(getDataLayout().getABITypeAlign(Field2Ty)); CharUnits Field1End = Field1Off + CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty)); CharUnits Field2OffNoPadNoPack = Field1End.alignTo(Field2Align); @@ -11967,7 +11967,7 @@ ABIArgInfo LoongArchABIInfo::coerceAndExpandFARsEligibleStruct( } CharUnits Field2Align = - CharUnits::fromQuantity(getDataLayout().getABITypeAlignment(Field2Ty)); + CharUnits::fromQuantity(getDataLayout().getABITypeAlign(Field2Ty)); CharUnits Field1End = Field1Off + CharUnits::fromQuantity(getDataLayout().getTypeStoreSize(Field1Ty));