From 8556d2a7f155c7edfaf454a3acda8ce28863c5e4 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Sun, 18 Jan 2009 12:19:30 +0000 Subject: 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@62461 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/BasicAliasAnalysis.cpp | 55 ++----------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) (limited to 'lib/Analysis/BasicAliasAnalysis.cpp') diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 9cefdcf40d..82514400b8 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/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(*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(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(I)->paramHasAttr(UI.getOperandNo()-2, - Attribute::NoCapture)) - continue; - return true; - default: - return true; - } - } - return false; -} - static const User *isGEP(const Value *V) { if (isa(V) || (isa(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(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; } -- cgit v1.2.3