summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/GlobalOpt.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-10-17 18:00:25 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-10-17 18:00:25 +0000
commit4a7cef2202893d74caf5aa817aa40d1a67c8de46 (patch)
tree9d5060726c95580ec85bcad9373020dabbc145ff /lib/Transforms/IPO/GlobalOpt.cpp
parentacc1f8b20f11d726ae013cf767079eb06dd0d935 (diff)
downloadllvm-4a7cef2202893d74caf5aa817aa40d1a67c8de46.tar.gz
llvm-4a7cef2202893d74caf5aa817aa40d1a67c8de46.tar.bz2
llvm-4a7cef2202893d74caf5aa817aa40d1a67c8de46.tar.xz
Simplify the interface of AnalyzeGlobal a bit and rename to analyzeGlobal.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/GlobalOpt.cpp')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index cf15580b03..642eb2f120 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -184,13 +184,8 @@ static bool SafeToDestroyConstant(const Constant *C) {
return true;
}
-
-/// AnalyzeGlobal - Look at all uses of the global and fill in the GlobalStatus
-/// structure. If the global has its address taken, return true to indicate we
-/// can't do anything with it.
-///
-static bool AnalyzeGlobal(const Value *V, GlobalStatus &GS,
- SmallPtrSet<const PHINode*, 16> &PHIUsers) {
+static bool analyzeGlobalAux(const Value *V, GlobalStatus &GS,
+ SmallPtrSet<const PHINode *, 16> &PHIUsers) {
for (Value::const_use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;
++UI) {
const User *U = *UI;
@@ -201,7 +196,8 @@ static bool AnalyzeGlobal(const Value *V, GlobalStatus &GS,
// know to expect it in various places. Just reject early.
if (!isa<PointerType>(CE->getType())) return true;
- if (AnalyzeGlobal(CE, GS, PHIUsers)) return true;
+ if (analyzeGlobalAux(CE, GS, PHIUsers))
+ return true;
} else if (const Instruction *I = dyn_cast<Instruction>(U)) {
if (!GS.HasMultipleAccessingFunctions) {
const Function *F = I->getParent()->getParent();
@@ -260,16 +256,20 @@ static bool AnalyzeGlobal(const Value *V, GlobalStatus &GS,
}
}
} else if (isa<BitCastInst>(I)) {
- if (AnalyzeGlobal(I, GS, PHIUsers)) return true;
+ if (analyzeGlobalAux(I, GS, PHIUsers))
+ return true;
} else if (isa<GetElementPtrInst>(I)) {
- if (AnalyzeGlobal(I, GS, PHIUsers)) return true;
+ if (analyzeGlobalAux(I, GS, PHIUsers))
+ return true;
} else if (isa<SelectInst>(I)) {
- if (AnalyzeGlobal(I, GS, PHIUsers)) return true;
+ if (analyzeGlobalAux(I, GS, PHIUsers))
+ return true;
} else if (const PHINode *PN = dyn_cast<PHINode>(I)) {
// PHI nodes we can check just like select or GEP instructions, but we
// have to be careful about infinite recursion.
if (PHIUsers.insert(PN)) // Not already visited.
- if (AnalyzeGlobal(I, GS, PHIUsers)) return true;
+ if (analyzeGlobalAux(I, GS, PHIUsers))
+ return true;
} else if (isa<CmpInst>(I)) {
GS.isCompared = true;
} else if (const MemTransferInst *MTI = dyn_cast<MemTransferInst>(I)) {
@@ -300,6 +300,15 @@ static bool AnalyzeGlobal(const Value *V, GlobalStatus &GS,
return false;
}
+/// Look at all uses of the global and fill in the GlobalStatus
+/// structure. If the global has its address taken, return true to indicate we
+/// can't do anything with it.
+///
+static bool analyzeGlobal(const Value *V, GlobalStatus &GS) {
+ SmallPtrSet<const PHINode *, 16> PHIUsers;
+ return analyzeGlobalAux(V, GS, PHIUsers);
+}
+
/// isLeakCheckerRoot - Is this global variable possibly used by a leak checker
/// as a root? If so, we might not really want to eliminate the stores to it.
static bool isLeakCheckerRoot(GlobalVariable *GV) {
@@ -1916,10 +1925,9 @@ bool GlobalOpt::ProcessGlobal(GlobalVariable *GV,
if (!GV->hasLocalLinkage())
return false;
- SmallPtrSet<const PHINode*, 16> PHIUsers;
GlobalStatus GS;
- if (AnalyzeGlobal(GV, GS, PHIUsers))
+ if (analyzeGlobal(GV, GS))
return false;
if (!GS.isCompared && !GV->hasUnnamedAddr()) {