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 | d65a4daeead235fbe3a66b9afcf8044df7f53bff (patch) | |
| tree | 6bc0bc389541126b281b3a13ab60e2ee07d3bb9f /llvm/lib/Analysis | |
| parent | 94798d31ddf28976048688699de008397b5e0d2a (diff) | |
| download | bcm5719-llvm-d65a4daeead235fbe3a66b9afcf8044df7f53bff.tar.gz bcm5719-llvm-d65a4daeead235fbe3a66b9afcf8044df7f53bff.zip | |
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.
llvm-svn: 56922
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 32 | ||||
| -rw-r--r-- | llvm/lib/Analysis/IPA/GlobalsModRef.cpp | 31 |
2 files changed, 8 insertions, 55 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index aa47fb3be50..22b73b28400 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/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. diff --git a/llvm/lib/Analysis/IPA/GlobalsModRef.cpp b/llvm/lib/Analysis/IPA/GlobalsModRef.cpp index 74327d5c60b..99e9d215b01 100644 --- a/llvm/lib/Analysis/IPA/GlobalsModRef.cpp +++ b/llvm/lib/Analysis/IPA/GlobalsModRef.cpp @@ -157,29 +157,6 @@ static RegisterAnalysisGroup<AliasAnalysis> Y(X); Pass *llvm::createGlobalsModRefPass() { return new GlobalsModRef(); } -/// 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 global object, return it. -static Value *getUnderlyingObject(Value *V) { - if (!isa<PointerType>(V->getType())) return V; - - // If we are at some type of object... return it. - if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) return GV; - - // Traverse through different addressing mechanisms. - if (Instruction *I = dyn_cast<Instruction>(V)) { - if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) - return getUnderlyingObject(I->getOperand(0)); - } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { - if (CE->getOpcode() == Instruction::BitCast || - CE->getOpcode() == Instruction::GetElementPtr) - return getUnderlyingObject(CE->getOperand(0)); - } - - // Otherwise, we don't know what this is, return it as the base pointer. - return V; -} - /// AnalyzeGlobals - Scan through the users of all of the internal /// GlobalValue's in the program. If none of them have their "address taken" /// (really, their address passed to something nontrivial), record this fact, @@ -304,7 +281,7 @@ bool GlobalsModRef::AnalyzeIndirectGlobalMemory(GlobalValue *GV) { continue; // Check the value being stored. - Value *Ptr = getUnderlyingObject(SI->getOperand(0)); + Value *Ptr = SI->getOperand(0)->getUnderlyingObject(); if (isa<MallocInst>(Ptr)) { // Okay, easy case. @@ -468,8 +445,8 @@ AliasAnalysis::AliasResult GlobalsModRef::alias(const Value *V1, unsigned V1Size, const Value *V2, unsigned V2Size) { // Get the base object these pointers point to. - Value *UV1 = getUnderlyingObject(const_cast<Value*>(V1)); - Value *UV2 = getUnderlyingObject(const_cast<Value*>(V2)); + Value *UV1 = const_cast<Value*>(V1->getUnderlyingObject()); + Value *UV2 = const_cast<Value*>(V2->getUnderlyingObject()); // If either of the underlying values is a global, they may be non-addr-taken // globals, which we can answer queries about. @@ -526,7 +503,7 @@ GlobalsModRef::getModRefInfo(CallSite CS, Value *P, unsigned Size) { // If we are asking for mod/ref info of a direct call with a pointer to a // global we are tracking, return information if we have it. - if (GlobalValue *GV = dyn_cast<GlobalValue>(getUnderlyingObject(P))) + if (GlobalValue *GV = dyn_cast<GlobalValue>(P->getUnderlyingObject())) if (GV->hasInternalLinkage()) if (Function *F = CS.getCalledFunction()) if (NonAddressTakenGlobals.count(GV)) |

