summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2016-02-24 12:25:10 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2016-02-24 12:25:10 +0000
commitae51afc5c7b01c331bf240323a79597cc961ae27 (patch)
treedf5668bf9da2e997791319197a5dcf32c47733c3 /llvm/lib/Analysis/ValueTracking.cpp
parent92a8dedaaa5d8948a1313db22c50a189b0fbe967 (diff)
downloadbcm5719-llvm-ae51afc5c7b01c331bf240323a79597cc961ae27.tar.gz
bcm5719-llvm-ae51afc5c7b01c331bf240323a79597cc961ae27.zip
NFC. Move getAlignment helper function from ValueTracking to Value class.
Reviewed By: reames, hfinkel Differential Revision: http://reviews.llvm.org/D16144 llvm-svn: 261735
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp44
1 files changed, 2 insertions, 42 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index fafbcef2497..617083a15d0 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1569,46 +1569,6 @@ static void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero,
}
}
-static unsigned getAlignment(const Value *V, const DataLayout &DL) {
- unsigned Align = 0;
- if (auto *GO = dyn_cast<GlobalObject>(V)) {
- Align = GO->getAlignment();
- if (Align == 0) {
- if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
- Type *ObjectType = GVar->getValueType();
- if (ObjectType->isSized()) {
- // If the object is defined in the current Module, we'll be giving
- // it the preferred alignment. Otherwise, we have to assume that it
- // may only have the minimum ABI alignment.
- if (GVar->isStrongDefinitionForLinker())
- Align = DL.getPreferredAlignment(GVar);
- else
- Align = DL.getABITypeAlignment(ObjectType);
- }
- }
- }
- } else if (const Argument *A = dyn_cast<Argument>(V)) {
- Align = A->getType()->isPointerTy() ? A->getParamAlignment() : 0;
-
- if (!Align && 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())
- Align = DL.getABITypeAlignment(EltTy);
- }
- } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(V))
- Align = AI->getAlignment();
- else if (auto CS = ImmutableCallSite(V))
- Align = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
- else if (const LoadInst *LI = dyn_cast<LoadInst>(V))
- if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
- ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
- Align = CI->getLimitedValue();
- }
-
- return Align;
-}
-
/// Determine which bits of V are known to be either zero or one and return
/// them in the KnownZero/KnownOne bit sets.
///
@@ -1691,7 +1651,7 @@ void computeKnownBits(Value *V, APInt &KnownZero, APInt &KnownOne,
// Aligned pointers have trailing zeros - refine KnownZero set
if (V->getType()->isPointerTy()) {
- unsigned Align = getAlignment(V, Q.DL);
+ unsigned Align = V->getPointerAlignment(Q.DL);
if (Align)
KnownZero |= APInt::getLowBitsSet(BitWidth, countTrailingZeros(Align));
}
@@ -3206,7 +3166,7 @@ static bool isDereferenceableFromAttribute(const Value *V, const DataLayout &DL,
static bool isAligned(const Value *Base, APInt Offset, unsigned Align,
const DataLayout &DL) {
- APInt BaseAlign(Offset.getBitWidth(), getAlignment(Base, DL));
+ APInt BaseAlign(Offset.getBitWidth(), Base->getPointerAlignment(DL));
if (!BaseAlign) {
Type *Ty = Base->getType()->getPointerElementType();
OpenPOWER on IntegriCloud