diff options
author | Duncan Sands <baldrick@free.fr> | 2009-01-18 12:19:30 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2009-01-18 12:19:30 +0000 |
commit | e0aa0d677d9f0c23c415735afc9c81d5adbea9cd (patch) | |
tree | d87df67dbcaae7a4c6d2bae3343436d3031c0459 /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | c671e061eb2c48b3966c54405959ed4ab3941c51 (diff) | |
download | bcm5719-llvm-e0aa0d677d9f0c23c415735afc9c81d5adbea9cd.tar.gz bcm5719-llvm-e0aa0d677d9f0c23c415735afc9c81d5adbea9cd.zip |
BasicAliasAnalysis and FunctionAttrs were both
doing very similar pointer capture analysis.
Factor out the common logic. The new version
is from FunctionAttrs since it does a better
job than the version in BasicAliasAnalysis
llvm-svn: 62461
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 9cefdcf40dc..82514400b82 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/Passes.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -35,56 +36,6 @@ using namespace llvm; // Useful predicates //===----------------------------------------------------------------------===// -// Determine if a value escapes from the function it is contained in (being -// returned by the function does not count as escaping here). If a value local -// to the function does not escape, there is no way another function can mod/ref -// it. We do this by looking at its uses and determining if they can escape -// (recursively). -static bool AddressMightEscape(const Value *V) { - for (Value::use_const_iterator UI = V->use_begin(), E = V->use_end(); - UI != E; ++UI) { - const Instruction *I = cast<Instruction>(*UI); - switch (I->getOpcode()) { - case Instruction::Load: - break; //next use. - case Instruction::Store: - if (I->getOperand(0) == V) - return true; // Escapes if the pointer is stored. - break; // next use. - case Instruction::GetElementPtr: - if (AddressMightEscape(I)) - return true; - break; // next use. - case Instruction::BitCast: - if (AddressMightEscape(I)) - return true; - break; // next use - case Instruction::Ret: - // If returned, the address will escape to calling functions, but no - // callees could modify it. - break; // next use - case Instruction::Call: - // If the argument to the call has the nocapture attribute, then the call - // may store or load to the pointer, but it cannot escape. - if (cast<CallInst>(I)->paramHasAttr(UI.getOperandNo(), - Attribute::NoCapture)) - continue; - return true; - case Instruction::Invoke: - // If the argument to the call has the nocapture attribute, then the call - // may store or load to the pointer, but it cannot escape. - // Do compensate for the two BB operands, i.e. Arg1 is at index 3! - if (cast<InvokeInst>(I)->paramHasAttr(UI.getOperandNo()-2, - Attribute::NoCapture)) - continue; - return true; - default: - return true; - } - } - return false; -} - static const User *isGEP(const Value *V) { if (isa<GetElementPtrInst>(V) || (isa<ConstantExpr>(V) && @@ -158,7 +109,7 @@ static bool isKnownNonNull(const Value *V) { static bool isNonEscapingLocalObject(const Value *V) { // If this is a local allocation, check to see if it escapes. if (isa<AllocationInst>(V) || isNoAliasCall(V)) - return !AddressMightEscape(V); + return !PointerMayBeCaptured(V, false); // If this is an argument that corresponds to a byval or noalias argument, // then it has not escaped before entering the function. Check if it escapes @@ -168,7 +119,7 @@ static bool isNonEscapingLocalObject(const Value *V) { // Don't bother analyzing arguments already known not to escape. if (A->hasNoCaptureAttr()) return true; - return !AddressMightEscape(V); + return !PointerMayBeCaptured(V, false); } return false; } |