summaryrefslogtreecommitdiff
path: root/lib/Analysis/BasicAliasAnalysis.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-03-23 02:19:48 +0000
committerAnders Carlsson <andersca@mac.com>2011-03-23 02:19:48 +0000
commit90af3420614fcfbcc6e2c2702fbdde144e13af86 (patch)
treeb378e310969b1df382ab492691e637102683374d /lib/Analysis/BasicAliasAnalysis.cpp
parenta2f45291e1a50a571a15bbf4da38a5f42a2424ef (diff)
downloadllvm-90af3420614fcfbcc6e2c2702fbdde144e13af86.tar.gz
llvm-90af3420614fcfbcc6e2c2702fbdde144e13af86.tar.bz2
llvm-90af3420614fcfbcc6e2c2702fbdde144e13af86.tar.xz
A global variable with internal linkage where all uses are in one function and whose address is never taken is a non-escaping local object and can't alias anything else.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128140 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index f7bcd9ec44..e807933aaa 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -57,6 +57,29 @@ static bool isKnownNonNull(const Value *V) {
return false;
}
+/// areAllUsesInOneFunction - Return true if all the uses of the given value
+/// are in the same function. Note that this returns false if any of the uses
+/// are from non-instruction values.
+static bool areAllUsesInOneFunction(const Value *V) {
+ const llvm::Function *Fn = 0;
+
+ for (Value::const_use_iterator UI = V->use_begin(), E = V->use_end();
+ UI != E; ++UI) {
+ if (const Instruction *I = dyn_cast<Instruction>(*UI)) {
+ if (!Fn) {
+ Fn = I->getParent()->getParent();
+ continue;
+ }
+
+ if (Fn != I->getParent()->getParent())
+ return false;
+ } else
+ return false;
+ }
+
+ return true;
+}
+
/// isNonEscapingLocalObject - Return true if the pointer is to a function-local
/// object that never escapes from the function.
static bool isNonEscapingLocalObject(const Value *V) {
@@ -79,6 +102,16 @@ static bool isNonEscapingLocalObject(const Value *V) {
return true;
return !PointerMayBeCaptured(V, false, /*StoreCaptures=*/true);
}
+
+ // If this is an internal global variable that's only used in this function,
+ // check if it escapes the function.
+ if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
+ if (GV->hasInternalLinkage() && areAllUsesInOneFunction(GV)) {
+ return !PointerMayBeCaptured(V, /*ReturnCaptures=*/true,
+ /*StoreCaptures=*/true);
+ }
+ }
+
return false;
}