diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-05-16 17:55:18 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-05-20 16:37:20 -0700 |
commit | f26bdb539e8acef23e2a0370408521a6458001ee (patch) | |
tree | 858d012071872321fd2f4417bd10e90b6c414a33 /llvm/lib/IR/Value.cpp | |
parent | 770ba4f0516e9af7279767ae90e283c3755c0c97 (diff) | |
download | llvm-f26bdb539e8acef23e2a0370408521a6458001ee.zip llvm-f26bdb539e8acef23e2a0370408521a6458001ee.tar.gz llvm-f26bdb539e8acef23e2a0370408521a6458001ee.tar.bz2 |
Make Value::getPointerAlignment() return an Align, not a MaybeAlign.
If we don't know anything about the alignment of a pointer, Align(1) is
still correct: all pointers are at least 1-byte aligned.
Included in this patch is a bugfix for an issue discovered during this
cleanup: pointers with "dereferenceable" attributes/metadata were
assumed to be aligned according to the type of the pointer. This
wasn't intentional, as far as I can tell, so Loads.cpp was fixed to
stop making this assumption. Frontends may need to be updated. I
updated clang's handling of C++ references, and added a release note for
this.
Differential Revision: https://reviews.llvm.org/D80072
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 6655270..70d4012 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -738,16 +738,16 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, return DerefBytes; } -MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const { +Align 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(); + Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne(); switch (DL.getFunctionPtrAlignType()) { case DataLayout::FunctionPtrAlignType::Independent: return FunctionPtrAlign; case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign: - return std::max(FunctionPtrAlign, MaybeAlign(GO->getAlignment())); + return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne()); } llvm_unreachable("Unhandled FunctionPtrAlignType"); } @@ -760,13 +760,13 @@ MaybeAlign 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 MaybeAlign(DL.getPreferredAlignment(GVar)); + return Align(DL.getPreferredAlignment(GVar)); else return DL.getABITypeAlign(ObjectType); } } } - return Alignment; + return Alignment.valueOrOne(); } else if (const Argument *A = dyn_cast<Argument>(this)) { const MaybeAlign Alignment = A->getParamAlign(); if (!Alignment && A->hasStructRetAttr()) { @@ -775,25 +775,18 @@ MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const { if (EltTy->isSized()) return DL.getABITypeAlign(EltTy); } - return Alignment; + return Alignment.valueOrOne(); } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) { - const MaybeAlign Alignment = AI->getAlign(); - if (!Alignment) { - Type *AllocatedType = AI->getAllocatedType(); - if (AllocatedType->isSized()) - return MaybeAlign(DL.getPrefTypeAlignment(AllocatedType)); - } - return Alignment; + return AI->getAlign(); } else if (const auto *Call = dyn_cast<CallBase>(this)) { - const MaybeAlign Alignment = Call->getRetAlign(); + MaybeAlign Alignment = Call->getRetAlign(); if (!Alignment && Call->getCalledFunction()) - return MaybeAlign( - Call->getCalledFunction()->getAttributes().getRetAlignment()); - return Alignment; + Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment(); + return Alignment.valueOrOne(); } 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 MaybeAlign(CI->getLimitedValue()); + return Align(CI->getLimitedValue()); } } else if (auto *CstPtr = dyn_cast<Constant>(this)) { if (auto *CstInt = dyn_cast_or_null<ConstantInt>(ConstantExpr::getPtrToInt( @@ -807,7 +800,7 @@ MaybeAlign Value::getPointerAlignment(const DataLayout &DL) const { : Value::MaximumAlignment); } } - return llvm::None; + return Align(1); } const Value *Value::DoPHITranslation(const BasicBlock *CurBB, |