Skip to content

Commit 1172712

Browse files
committed
[NFC] Replace some deprecated getAlignment() calls with getAlign()
Reviewed By: gchatelet Differential Revision: https://reviews.llvm.org/D115370
1 parent 0ec5f1e commit 1172712

File tree

13 files changed

+53
-44
lines changed

13 files changed

+53
-44
lines changed

llvm/include/llvm/Analysis/MemoryBuiltins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class ObjectSizeOffsetVisitor
241241
APInt Zero;
242242
SmallPtrSet<Instruction *, 8> SeenInsts;
243243

244-
APInt align(APInt Size, uint64_t Align);
244+
APInt align(APInt Size, MaybeAlign Align);
245245

246246
SizeOffsetType unknown() {
247247
return std::make_pair(APInt(), APInt());

llvm/lib/Analysis/MemoryBuiltins.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ STATISTIC(ObjectVisitorArgument,
592592
STATISTIC(ObjectVisitorLoad,
593593
"Number of load instructions with unsolved size and offset");
594594

595-
APInt ObjectSizeOffsetVisitor::align(APInt Size, uint64_t Alignment) {
595+
APInt ObjectSizeOffsetVisitor::align(APInt Size, MaybeAlign Alignment) {
596596
if (Options.RoundToAlign && Alignment)
597-
return APInt(IntTyBits, alignTo(Size.getZExtValue(), Align(Alignment)));
597+
return APInt(IntTyBits, alignTo(Size.getZExtValue(), Alignment));
598598
return Size;
599599
}
600600

@@ -669,7 +669,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) {
669669

670670
APInt Size(IntTyBits, DL.getTypeAllocSize(I.getAllocatedType()));
671671
if (!I.isArrayAllocation())
672-
return std::make_pair(align(Size, I.getAlignment()), Zero);
672+
return std::make_pair(align(Size, I.getAlign()), Zero);
673673

674674
Value *ArraySize = I.getArraySize();
675675
if (const ConstantInt *C = dyn_cast<ConstantInt>(ArraySize)) {
@@ -679,8 +679,8 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitAllocaInst(AllocaInst &I) {
679679

680680
bool Overflow;
681681
Size = Size.umul_ov(NumElems, Overflow);
682-
return Overflow ? unknown() : std::make_pair(align(Size, I.getAlignment()),
683-
Zero);
682+
return Overflow ? unknown()
683+
: std::make_pair(align(Size, I.getAlign()), Zero);
684684
}
685685
return unknown();
686686
}
@@ -694,7 +694,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) {
694694
}
695695

696696
APInt Size(IntTyBits, DL.getTypeAllocSize(MemoryTy));
697-
return std::make_pair(align(Size, A.getParamAlignment()), Zero);
697+
return std::make_pair(align(Size, A.getParamAlign()), Zero);
698698
}
699699

700700
SizeOffsetType ObjectSizeOffsetVisitor::visitCallBase(CallBase &CB) {
@@ -800,7 +800,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable(GlobalVariable &GV){
800800
return unknown();
801801

802802
APInt Size(IntTyBits, DL.getTypeAllocSize(GV.getValueType()));
803-
return std::make_pair(align(Size, GV.getAlignment()), Zero);
803+
return std::make_pair(align(Size, GV.getAlign()), Zero);
804804
}
805805

806806
SizeOffsetType ObjectSizeOffsetVisitor::visitIntToPtrInst(IntToPtrInst&) {

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Align AsmPrinter::getGVAlignment(const GlobalObject *GV, const DataLayout &DL,
180180
Alignment = InAlign;
181181

182182
// If the GV has a specified alignment, take it into account.
183-
const MaybeAlign GVAlign(GV->getAlignment());
183+
const MaybeAlign GVAlign(GV->getAlign());
184184
if (!GVAlign)
185185
return Alignment;
186186

llvm/lib/IR/AsmWriter.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,8 +3524,8 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
35243524
}
35253525

35263526
maybePrintComdat(Out, *GV);
3527-
if (GV->getAlignment())
3528-
Out << ", align " << GV->getAlignment();
3527+
if (MaybeAlign A = GV->getAlign())
3528+
Out << ", align " << A->value();
35293529

35303530
SmallVector<std::pair<unsigned, MDNode *>, 4> MDs;
35313531
GV->getAllMetadata(MDs);
@@ -3753,8 +3753,8 @@ void AssemblyWriter::printFunction(const Function *F) {
37533753
Out << '"';
37543754
}
37553755
maybePrintComdat(Out, *F);
3756-
if (F->getAlignment())
3757-
Out << " align " << F->getAlignment();
3756+
if (MaybeAlign A = F->getAlign())
3757+
Out << " align " << A->value();
37583758
if (F->hasGC())
37593759
Out << " gc \"" << F->getGC() << '"';
37603760
if (F->hasPrefixData()) {
@@ -4235,8 +4235,8 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
42354235
Out << ", ";
42364236
writeOperand(AI->getArraySize(), true);
42374237
}
4238-
if (AI->getAlignment()) {
4239-
Out << ", align " << AI->getAlignment();
4238+
if (MaybeAlign A = AI->getAlign()) {
4239+
Out << ", align " << A->value();
42404240
}
42414241

42424242
unsigned AddrSpace = AI->getType()->getAddressSpace();
@@ -4306,13 +4306,13 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
43064306
if (const LoadInst *LI = dyn_cast<LoadInst>(&I)) {
43074307
if (LI->isAtomic())
43084308
writeAtomic(LI->getContext(), LI->getOrdering(), LI->getSyncScopeID());
4309-
if (LI->getAlignment())
4310-
Out << ", align " << LI->getAlignment();
4309+
if (MaybeAlign A = LI->getAlign())
4310+
Out << ", align " << A->value();
43114311
} else if (const StoreInst *SI = dyn_cast<StoreInst>(&I)) {
43124312
if (SI->isAtomic())
43134313
writeAtomic(SI->getContext(), SI->getOrdering(), SI->getSyncScopeID());
4314-
if (SI->getAlignment())
4315-
Out << ", align " << SI->getAlignment();
4314+
if (MaybeAlign A = SI->getAlign())
4315+
Out << ", align " << A->value();
43164316
} else if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(&I)) {
43174317
writeAtomicCmpXchg(CXI->getContext(), CXI->getSuccessOrdering(),
43184318
CXI->getFailureOrdering(), CXI->getSyncScopeID());

llvm/lib/IR/Globals.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void GlobalObject::setAlignment(MaybeAlign Align) {
126126

127127
void GlobalObject::copyAttributesFrom(const GlobalObject *Src) {
128128
GlobalValue::copyAttributesFrom(Src);
129-
setAlignment(MaybeAlign(Src->getAlignment()));
129+
setAlignment(Src->getAlign());
130130
setSection(Src->getSection());
131131
}
132132

@@ -249,7 +249,7 @@ bool GlobalObject::canIncreaseAlignment() const {
249249
// alignment specified. (If it is assigned a section, the global
250250
// could be densely packed with other objects in the section, and
251251
// increasing the alignment could cause padding issues.)
252-
if (hasSection() && getAlignment() > 0)
252+
if (hasSection() && getAlign().hasValue())
253253
return false;
254254

255255
// On ELF platforms, we're further restricted in that we can't

llvm/lib/IR/Value.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ Align Value::getPointerAlignment(const DataLayout &DL) const {
928928
}
929929
llvm_unreachable("Unhandled FunctionPtrAlignType");
930930
}
931-
const MaybeAlign Alignment(GO->getAlignment());
931+
const MaybeAlign Alignment(GO->getAlign());
932932
if (!Alignment) {
933933
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
934934
Type *ObjectType = GVar->getValueType();

llvm/lib/IR/Verifier.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,13 @@ void Verifier::visitGlobalValue(const GlobalValue &GV) {
621621
Assert(!GV.isDeclaration() || GV.hasValidDeclarationLinkage(),
622622
"Global is external, but doesn't have external or weak linkage!", &GV);
623623

624-
if (const GlobalObject *GO = dyn_cast<GlobalObject>(&GV))
625-
Assert(GO->getAlignment() <= Value::MaximumAlignment,
626-
"huge alignment values are unsupported", GO);
624+
if (const GlobalObject *GO = dyn_cast<GlobalObject>(&GV)) {
625+
626+
if (MaybeAlign A = GO->getAlign()) {
627+
Assert(A->value() <= Value::MaximumAlignment,
628+
"huge alignment values are unsupported", GO);
629+
}
630+
}
627631
Assert(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
628632
"Only global variables can have appending linkage!", &GV);
629633

@@ -3735,8 +3739,10 @@ void Verifier::visitLoadInst(LoadInst &LI) {
37353739
PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
37363740
Assert(PTy, "Load operand must be a pointer.", &LI);
37373741
Type *ElTy = LI.getType();
3738-
Assert(LI.getAlignment() <= Value::MaximumAlignment,
3739-
"huge alignment values are unsupported", &LI);
3742+
if (MaybeAlign A = LI.getAlign()) {
3743+
Assert(A->value() <= Value::MaximumAlignment,
3744+
"huge alignment values are unsupported", &LI);
3745+
}
37403746
Assert(ElTy->isSized(), "loading unsized types is not allowed", &LI);
37413747
if (LI.isAtomic()) {
37423748
Assert(LI.getOrdering() != AtomicOrdering::Release &&
@@ -3761,8 +3767,10 @@ void Verifier::visitStoreInst(StoreInst &SI) {
37613767
Type *ElTy = SI.getOperand(0)->getType();
37623768
Assert(PTy->isOpaqueOrPointeeTypeMatches(ElTy),
37633769
"Stored value type does not match pointer operand type!", &SI, ElTy);
3764-
Assert(SI.getAlignment() <= Value::MaximumAlignment,
3765-
"huge alignment values are unsupported", &SI);
3770+
if (MaybeAlign A = SI.getAlign()) {
3771+
Assert(A->value() <= Value::MaximumAlignment,
3772+
"huge alignment values are unsupported", &SI);
3773+
}
37663774
Assert(ElTy->isSized(), "storing unsized types is not allowed", &SI);
37673775
if (SI.isAtomic()) {
37683776
Assert(SI.getOrdering() != AtomicOrdering::Acquire &&
@@ -3818,8 +3826,10 @@ void Verifier::visitAllocaInst(AllocaInst &AI) {
38183826
"Cannot allocate unsized type", &AI);
38193827
Assert(AI.getArraySize()->getType()->isIntegerTy(),
38203828
"Alloca array size must have integer type", &AI);
3821-
Assert(AI.getAlignment() <= Value::MaximumAlignment,
3822-
"huge alignment values are unsupported", &AI);
3829+
if (MaybeAlign A = AI.getAlign()) {
3830+
Assert(A->value() <= Value::MaximumAlignment,
3831+
"huge alignment values are unsupported", &AI);
3832+
}
38233833

38243834
if (AI.isSwiftError()) {
38253835
verifySwiftErrorValue(&AI);

llvm/lib/Linker/IRMover.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ GlobalVariable *IRLinker::copyGlobalVariableProto(const GlobalVariable *SGVar) {
646646
/*init*/ nullptr, SGVar->getName(),
647647
/*insertbefore*/ nullptr, SGVar->getThreadLocalMode(),
648648
SGVar->getAddressSpace());
649-
NewDGV->setAlignment(MaybeAlign(SGVar->getAlignment()));
649+
NewDGV->setAlignment(SGVar->getAlign());
650650
NewDGV->copyAttributesFrom(SGVar);
651651
return NewDGV;
652652
}
@@ -877,7 +877,7 @@ IRLinker::linkAppendingVarProto(GlobalVariable *DstGV,
877877
if (DstGV->isConstant() != SrcGV->isConstant())
878878
return stringErr("Appending variables linked with different const'ness!");
879879

880-
if (DstGV->getAlignment() != SrcGV->getAlignment())
880+
if (DstGV->getAlign() != SrcGV->getAlign())
881881
return stringErr(
882882
"Appending variables with different alignment need to be linked!");
883883

llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ bool AMDGPUPromoteAllocaImpl::handleAlloca(AllocaInst &I, bool SufficientLDS) {
939939
GlobalVariable::NotThreadLocal,
940940
AMDGPUAS::LOCAL_ADDRESS);
941941
GV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
942-
GV->setAlignment(MaybeAlign(I.getAlignment()));
942+
GV->setAlignment(I.getAlign());
943943

944944
Value *TCntY, *TCntZ;
945945

llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,10 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
10981098
O << " .attribute(.managed)";
10991099
}
11001100

1101-
if (GVar->getAlignment() == 0)
1102-
O << " .align " << (int)DL.getPrefTypeAlignment(ETy);
1101+
if (MaybeAlign A = GVar->getAlign())
1102+
O << " .align " << A->value();
11031103
else
1104-
O << " .align " << GVar->getAlignment();
1104+
O << " .align " << (int)DL.getPrefTypeAlignment(ETy);
11051105

11061106
if (ETy->isFloatingPointTy() || ETy->isPointerTy() ||
11071107
(ETy->isIntegerTy() && ETy->getScalarSizeInBits() <= 64)) {
@@ -1290,10 +1290,10 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
12901290

12911291
O << ".";
12921292
emitPTXAddressSpace(GVar->getType()->getAddressSpace(), O);
1293-
if (GVar->getAlignment() == 0)
1294-
O << " .align " << (int)DL.getPrefTypeAlignment(ETy);
1293+
if (MaybeAlign A = GVar->getAlign())
1294+
O << " .align " << A->value();
12951295
else
1296-
O << " .align " << GVar->getAlignment();
1296+
O << " .align " << (int)DL.getPrefTypeAlignment(ETy);
12971297

12981298
// Special case for i128
12991299
if (ETy->isIntegerTy(128)) {

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ void DevirtModule::rebuildGlobal(VTableBits &B) {
17441744
GlobalVariable::PrivateLinkage, NewInit, "", B.GV);
17451745
NewGV->setSection(B.GV->getSection());
17461746
NewGV->setComdat(B.GV->getComdat());
1747-
NewGV->setAlignment(MaybeAlign(B.GV->getAlignment()));
1747+
NewGV->setAlignment(B.GV->getAlign());
17481748

17491749
// Copy the original vtable's metadata to the anonymous global, adjusting
17501750
// offsets as required.

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static bool isDereferenceableForAllocaSize(const Value *V, const AllocaInst *AI,
163163
uint64_t AllocaSize = DL.getTypeStoreSize(AI->getAllocatedType());
164164
if (!AllocaSize)
165165
return false;
166-
return isDereferenceableAndAlignedPointer(V, Align(AI->getAlignment()),
166+
return isDereferenceableAndAlignedPointer(V, AI->getAlign(),
167167
APInt(64, AllocaSize), DL);
168168
}
169169

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3887,8 +3887,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
38873887
&I, IRB, IRB.getInt8Ty(), Align(1), /*isStore*/ true);
38883888

38893889
Value *PoisonValue = IRB.getInt8(PoisonStack ? ClPoisonStackPattern : 0);
3890-
IRB.CreateMemSet(ShadowBase, PoisonValue, Len,
3891-
MaybeAlign(I.getAlignment()));
3890+
IRB.CreateMemSet(ShadowBase, PoisonValue, Len, I.getAlign());
38923891
}
38933892

38943893
if (PoisonStack && MS.TrackOrigins) {

0 commit comments

Comments
 (0)