aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2019-10-15 13:58:22 +0000
committerGuillaume Chatelet <gchatelet@google.com>2019-10-15 13:58:22 +0000
commitbae629b96622962245aad7b7dfcbce915d9c02a2 (patch)
treeb0cd530f717f9ae39b5f659af7ecfd670398b92a /llvm/lib/IR/Value.cpp
parent86d0f8b148bd8da755cee615725e1488bbe6946e (diff)
downloadllvm-bae629b96622962245aad7b7dfcbce915d9c02a2.zip
llvm-bae629b96622962245aad7b7dfcbce915d9c02a2.tar.gz
llvm-bae629b96622962245aad7b7dfcbce915d9c02a2.tar.bz2
[Alignment][NFC] Value::getPointerAlignment returns MaybeAlign
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, jdoerfert Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68398 llvm-svn: 374889
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index c44d4b4..3c8a5b5 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -671,22 +671,21 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
return DerefBytes;
}
-unsigned Value::getPointerAlignment(const DataLayout &DL) const {
+MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const {
assert(getType()->isPointerTy() && "must be pointer");
if (auto *GO = dyn_cast<GlobalObject>(this)) {
if (isa<Function>(GO)) {
const MaybeAlign FunctionPtrAlign = DL.getFunctionPtrAlign();
- const unsigned Align = FunctionPtrAlign ? FunctionPtrAlign->value() : 0;
switch (DL.getFunctionPtrAlignType()) {
case DataLayout::FunctionPtrAlignType::Independent:
- return Align;
+ return FunctionPtrAlign;
case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
- return std::max(Align, GO->getAlignment());
+ return std::max(FunctionPtrAlign, MaybeAlign(GO->getAlignment()));
}
llvm_unreachable("Unhandled FunctionPtrAlignType");
}
- const unsigned Align = GO->getAlignment();
- if (!Align) {
+ const MaybeAlign Alignment(GO->getAlignment());
+ if (!Alignment) {
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
Type *ObjectType = GVar->getValueType();
if (ObjectType->isSized()) {
@@ -694,42 +693,43 @@ unsigned Value::getPointerAlignment(const DataLayout &DL) const {
// it the preferred alignment. Otherwise, we have to assume that it
// may only have the minimum ABI alignment.
if (GVar->isStrongDefinitionForLinker())
- return DL.getPreferredAlignment(GVar);
+ return MaybeAlign(DL.getPreferredAlignment(GVar));
else
- return DL.getABITypeAlignment(ObjectType);
+ return Align(DL.getABITypeAlignment(ObjectType));
}
}
}
- return Align;
+ return Alignment;
} else if (const Argument *A = dyn_cast<Argument>(this)) {
- const unsigned Align = A->getParamAlignment();
- if (!Align && A->hasStructRetAttr()) {
+ const MaybeAlign Alignment(A->getParamAlignment());
+ if (!Alignment && A->hasStructRetAttr()) {
// An sret parameter has at least the ABI alignment of the return type.
Type *EltTy = cast<PointerType>(A->getType())->getElementType();
if (EltTy->isSized())
- return DL.getABITypeAlignment(EltTy);
+ return Align(DL.getABITypeAlignment(EltTy));
}
- return Align;
+ return Alignment;
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
- const unsigned Align = AI->getAlignment();
- if (!Align) {
+ const MaybeAlign Alignment(AI->getAlignment());
+ if (!Alignment) {
Type *AllocatedType = AI->getAllocatedType();
if (AllocatedType->isSized())
- return DL.getPrefTypeAlignment(AllocatedType);
+ return MaybeAlign(DL.getPrefTypeAlignment(AllocatedType));
}
- return Align;
+ return Alignment;
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
- const unsigned Align = Call->getRetAlignment();
- if (!Align && Call->getCalledFunction())
- return Call->getCalledFunction()->getAttributes().getRetAlignment();
- return Align;
+ const MaybeAlign Alignment(Call->getRetAlignment());
+ if (!Alignment && Call->getCalledFunction())
+ return MaybeAlign(
+ Call->getCalledFunction()->getAttributes().getRetAlignment());
+ return Alignment;
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
- return CI->getLimitedValue();
+ return MaybeAlign(CI->getLimitedValue());
}
}
- return 0;
+ return llvm::None;
}
const Value *Value::DoPHITranslation(const BasicBlock *CurBB,