Skip to content

Commit 6200a56

Browse files
committed
[NFC] Rearrange Value::getPointerAlignment
Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67918 llvm-svn: 372987
1 parent ed97f80 commit 6200a56

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

llvm/lib/IR/Value.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -665,61 +665,63 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
665665

666666
unsigned Value::getPointerAlignment(const DataLayout &DL) const {
667667
assert(getType()->isPointerTy() && "must be pointer");
668-
669-
unsigned Align = 0;
670668
if (auto *GO = dyn_cast<GlobalObject>(this)) {
671669
if (isa<Function>(GO)) {
672-
MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
673-
unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0;
670+
const llvm::MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
671+
const unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0;
674672
switch (DL.getFunctionPtrAlignType()) {
675673
case DataLayout::FunctionPtrAlignType::Independent:
676674
return Align;
677675
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
678676
return std::max(Align, GO->getAlignment());
679677
}
678+
llvm_unreachable("Unhandled FunctionPtrAlignType");
680679
}
681-
Align = GO->getAlignment();
682-
if (Align == 0) {
680+
const unsigned Align = GO->getAlignment();
681+
if (!Align) {
683682
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
684683
Type *ObjectType = GVar->getValueType();
685684
if (ObjectType->isSized()) {
686685
// If the object is defined in the current Module, we'll be giving
687686
// it the preferred alignment. Otherwise, we have to assume that it
688687
// may only have the minimum ABI alignment.
689688
if (GVar->isStrongDefinitionForLinker())
690-
Align = DL.getPreferredAlignment(GVar);
689+
return DL.getPreferredAlignment(GVar);
691690
else
692-
Align = DL.getABITypeAlignment(ObjectType);
691+
return DL.getABITypeAlignment(ObjectType);
693692
}
694693
}
695694
}
695+
return Align;
696696
} else if (const Argument *A = dyn_cast<Argument>(this)) {
697-
Align = A->getParamAlignment();
698-
697+
const unsigned Align = A->getParamAlignment();
699698
if (!Align && A->hasStructRetAttr()) {
700699
// An sret parameter has at least the ABI alignment of the return type.
701700
Type *EltTy = cast<PointerType>(A->getType())->getElementType();
702701
if (EltTy->isSized())
703-
Align = DL.getABITypeAlignment(EltTy);
702+
return DL.getABITypeAlignment(EltTy);
704703
}
704+
return Align;
705705
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
706-
Align = AI->getAlignment();
707-
if (Align == 0) {
706+
const unsigned Align = AI->getAlignment();
707+
if (!Align) {
708708
Type *AllocatedType = AI->getAllocatedType();
709709
if (AllocatedType->isSized())
710-
Align = DL.getPrefTypeAlignment(AllocatedType);
710+
return DL.getPrefTypeAlignment(AllocatedType);
711711
}
712+
return Align;
712713
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
713-
Align = Call->getRetAlignment();
714-
if (Align == 0 && Call->getCalledFunction())
715-
Align = Call->getCalledFunction()->getAttributes().getRetAlignment();
716-
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this))
714+
const unsigned Align = Call->getRetAlignment();
715+
if (!Align && Call->getCalledFunction())
716+
return Call->getCalledFunction()->getAttributes().getRetAlignment();
717+
return Align;
718+
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
717719
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
718720
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
719-
Align = CI->getLimitedValue();
721+
return CI->getLimitedValue();
720722
}
721-
722-
return Align;
723+
}
724+
return 0;
723725
}
724726

725727
const Value *Value::DoPHITranslation(const BasicBlock *CurBB,

0 commit comments

Comments
 (0)