diff options
author | Duncan Sands <baldrick@free.fr> | 2008-10-01 15:25:41 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-10-01 15:25:41 +0000 |
commit | 5d0392c6b370758750b397e254a6c6f028479969 (patch) | |
tree | e20efed1bfb1a39e5a9854393af376de2006eb48 /lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 38ac062c2f4de93cd4351693f084f0c4474be02c (diff) |
Factorize code: remove variants of "strip off
pointer bitcasts and GEP's", and centralize the
logic in Value::getUnderlyingObject. The
difference with stripPointerCasts is that
stripPointerCasts only strips GEPs if all
indices are zero, while getUnderlyingObject
strips GEPs no matter what the indices are.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56922 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | lib/Analysis/BasicAliasAnalysis.cpp | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index aa47fb3be5..22b73b2840 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -76,30 +76,6 @@ static bool AddressMightEscape(const Value *V) { return false; } -/// getUnderlyingObject - This traverses the use chain to figure out what object -/// the specified value points to. If the value points to, or is derived from, -/// a unique object or an argument, return it. This returns: -/// Arguments, GlobalVariables, Functions, Allocas, Mallocs. -static const Value *getUnderlyingObject(const Value *V) { - if (!isa<PointerType>(V->getType())) return V; - - // If we are at some type of object, return it. GlobalValues and Allocations - // have unique addresses. - if (isa<GlobalValue>(V) || isa<AllocationInst>(V) || isa<Argument>(V)) - return V; - - // Traverse through different addressing mechanisms... - if (const Instruction *I = dyn_cast<Instruction>(V)) { - if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) - return getUnderlyingObject(I->getOperand(0)); - } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { - if (CE->getOpcode() == Instruction::BitCast || - CE->getOpcode() == Instruction::GetElementPtr) - return getUnderlyingObject(CE->getOperand(0)); - } - return V; -} - static const User *isGEP(const Value *V) { if (isa<GetElementPtrInst>(V) || (isa<ConstantExpr>(V) && @@ -314,7 +290,7 @@ ImmutablePass *llvm::createBasicAliasAnalysisPass() { /// global) or not. bool BasicAliasAnalysis::pointsToConstantMemory(const Value *P) { if (const GlobalVariable *GV = - dyn_cast<GlobalVariable>(getUnderlyingObject(P))) + dyn_cast<GlobalVariable>(P->getUnderlyingObject())) return GV->isConstant(); return false; } @@ -327,7 +303,7 @@ bool BasicAliasAnalysis::pointsToConstantMemory(const Value *P) { AliasAnalysis::ModRefResult BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) { if (!isa<Constant>(P)) { - const Value *Object = getUnderlyingObject(P); + const Value *Object = P->getUnderlyingObject(); // If this is a tail call and P points to a stack location, we know that // the tail call cannot access or modify the local stack. @@ -390,8 +366,8 @@ BasicAliasAnalysis::alias(const Value *V1, unsigned V1Size, return alias(V1, V1Size, I->getOperand(0), V2Size); // Figure out what objects these things are pointing to if we can... - const Value *O1 = getUnderlyingObject(V1); - const Value *O2 = getUnderlyingObject(V2); + const Value *O1 = V1->getUnderlyingObject(); + const Value *O2 = V2->getUnderlyingObject(); if (O1 != O2) { // If V1/V2 point to two different objects we know that we have no alias. |