[NFC] Rearrange Value::getPointerAlignment

Reviewers: courbet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67918

llvm-svn: 372987
This commit is contained in:
Guillaume Chatelet 2019-09-26 15:13:05 +00:00
parent ed97f8042b
commit 6200a5689a
1 changed files with 23 additions and 21 deletions

View File

@ -665,21 +665,20 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
unsigned Value::getPointerAlignment(const DataLayout &DL) const { unsigned Value::getPointerAlignment(const DataLayout &DL) const {
assert(getType()->isPointerTy() && "must be pointer"); assert(getType()->isPointerTy() && "must be pointer");
unsigned Align = 0;
if (auto *GO = dyn_cast<GlobalObject>(this)) { if (auto *GO = dyn_cast<GlobalObject>(this)) {
if (isa<Function>(GO)) { if (isa<Function>(GO)) {
MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign(); const llvm::MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0; const unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0;
switch (DL.getFunctionPtrAlignType()) { switch (DL.getFunctionPtrAlignType()) {
case DataLayout::FunctionPtrAlignType::Independent: case DataLayout::FunctionPtrAlignType::Independent:
return Align; return Align;
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign: case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
return std::max(Align, GO->getAlignment()); return std::max(Align, GO->getAlignment());
} }
llvm_unreachable("Unhandled FunctionPtrAlignType");
} }
Align = GO->getAlignment(); const unsigned Align = GO->getAlignment();
if (Align == 0) { if (!Align) {
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) { if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
Type *ObjectType = GVar->getValueType(); Type *ObjectType = GVar->getValueType();
if (ObjectType->isSized()) { if (ObjectType->isSized()) {
@ -687,39 +686,42 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const {
// it the preferred alignment. Otherwise, we have to assume that it // it the preferred alignment. Otherwise, we have to assume that it
// may only have the minimum ABI alignment. // may only have the minimum ABI alignment.
if (GVar->isStrongDefinitionForLinker()) if (GVar->isStrongDefinitionForLinker())
Align = DL.getPreferredAlignment(GVar); return DL.getPreferredAlignment(GVar);
else else
Align = DL.getABITypeAlignment(ObjectType); return DL.getABITypeAlignment(ObjectType);
} }
} }
} }
return Align;
} else if (const Argument *A = dyn_cast<Argument>(this)) { } else if (const Argument *A = dyn_cast<Argument>(this)) {
Align = A->getParamAlignment(); const unsigned Align = A->getParamAlignment();
if (!Align && A->hasStructRetAttr()) { if (!Align && A->hasStructRetAttr()) {
// An sret parameter has at least the ABI alignment of the return type. // An sret parameter has at least the ABI alignment of the return type.
Type *EltTy = cast<PointerType>(A->getType())->getElementType(); Type *EltTy = cast<PointerType>(A->getType())->getElementType();
if (EltTy->isSized()) if (EltTy->isSized())
Align = DL.getABITypeAlignment(EltTy); return DL.getABITypeAlignment(EltTy);
} }
return Align;
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) { } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
Align = AI->getAlignment(); const unsigned Align = AI->getAlignment();
if (Align == 0) { if (!Align) {
Type *AllocatedType = AI->getAllocatedType(); Type *AllocatedType = AI->getAllocatedType();
if (AllocatedType->isSized()) if (AllocatedType->isSized())
Align = DL.getPrefTypeAlignment(AllocatedType); return DL.getPrefTypeAlignment(AllocatedType);
} }
return Align;
} else if (const auto *Call = dyn_cast<CallBase>(this)) { } else if (const auto *Call = dyn_cast<CallBase>(this)) {
Align = Call->getRetAlignment(); const unsigned Align = Call->getRetAlignment();
if (Align == 0 && Call->getCalledFunction()) if (!Align && Call->getCalledFunction())
Align = Call->getCalledFunction()->getAttributes().getRetAlignment(); return Call->getCalledFunction()->getAttributes().getRetAlignment();
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) return Align;
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) { if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0)); ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
Align = CI->getLimitedValue(); return CI->getLimitedValue();
} }
}
return Align; return 0;
} }
const Value *Value::DoPHITranslation(const BasicBlock *CurBB, const Value *Value::DoPHITranslation(const BasicBlock *CurBB,