summaryrefslogtreecommitdiffstats
path: root/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2009-01-18 12:19:30 +0000
committerDuncan Sands <baldrick@free.fr>2009-01-18 12:19:30 +0000
commit8556d2a7f155c7edfaf454a3acda8ce28863c5e4 (patch)
tree1a394bc0971280641fcb33b1548f92ab4b2f53be /lib/Analysis/BasicAliasAnalysis.cpp
parente3bc6ae92a17c28824fb4b6cf606d8ab07cae974 (diff)
downloadexternal_llvm-8556d2a7f155c7edfaf454a3acda8ce28863c5e4.zip
external_llvm-8556d2a7f155c7edfaf454a3acda8ce28863c5e4.tar.gz
external_llvm-8556d2a7f155c7edfaf454a3acda8ce28863c5e4.tar.bz2
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
Diffstat (limited to 'lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp55
1 files changed, 3 insertions, 52 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 9cefdcf..8251440 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<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;
}