@@ -665,61 +665,63 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
665
665
666
666
unsigned Value::getPointerAlignment (const DataLayout &DL) const {
667
667
assert (getType ()->isPointerTy () && " must be pointer" );
668
-
669
- unsigned Align = 0 ;
670
668
if (auto *GO = dyn_cast<GlobalObject>(this )) {
671
669
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 ;
674
672
switch (DL.getFunctionPtrAlignType ()) {
675
673
case DataLayout::FunctionPtrAlignType::Independent:
676
674
return Align;
677
675
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
678
676
return std::max (Align, GO->getAlignment ());
679
677
}
678
+ llvm_unreachable (" Unhandled FunctionPtrAlignType" );
680
679
}
681
- Align = GO->getAlignment ();
682
- if (Align == 0 ) {
680
+ const unsigned Align = GO->getAlignment ();
681
+ if (! Align) {
683
682
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
684
683
Type *ObjectType = GVar->getValueType ();
685
684
if (ObjectType->isSized ()) {
686
685
// If the object is defined in the current Module, we'll be giving
687
686
// it the preferred alignment. Otherwise, we have to assume that it
688
687
// may only have the minimum ABI alignment.
689
688
if (GVar->isStrongDefinitionForLinker ())
690
- Align = DL.getPreferredAlignment (GVar);
689
+ return DL.getPreferredAlignment (GVar);
691
690
else
692
- Align = DL.getABITypeAlignment (ObjectType);
691
+ return DL.getABITypeAlignment (ObjectType);
693
692
}
694
693
}
695
694
}
695
+ return Align;
696
696
} else if (const Argument *A = dyn_cast<Argument>(this )) {
697
- Align = A->getParamAlignment ();
698
-
697
+ const unsigned Align = A->getParamAlignment ();
699
698
if (!Align && A->hasStructRetAttr ()) {
700
699
// An sret parameter has at least the ABI alignment of the return type.
701
700
Type *EltTy = cast<PointerType>(A->getType ())->getElementType ();
702
701
if (EltTy->isSized ())
703
- Align = DL.getABITypeAlignment (EltTy);
702
+ return DL.getABITypeAlignment (EltTy);
704
703
}
704
+ return Align;
705
705
} 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) {
708
708
Type *AllocatedType = AI->getAllocatedType ();
709
709
if (AllocatedType->isSized ())
710
- Align = DL.getPrefTypeAlignment (AllocatedType);
710
+ return DL.getPrefTypeAlignment (AllocatedType);
711
711
}
712
+ return Align;
712
713
} 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 )) {
717
719
if (MDNode *MD = LI->getMetadata (LLVMContext::MD_align)) {
718
720
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand (0 ));
719
- Align = CI->getLimitedValue ();
721
+ return CI->getLimitedValue ();
720
722
}
721
-
722
- return Align ;
723
+ }
724
+ return 0 ;
723
725
}
724
726
725
727
const Value *Value::DoPHITranslation (const BasicBlock *CurBB,
0 commit comments