aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-10-10 16:43:46 +0000
committerChris Lattner <sabre@nondot.org>2004-10-10 16:43:46 +0000
commit031955d4623193b1c4163bd43db0eaaf6b08c27b (patch)
tree5679ba8d6df1869e878c8c1e7fd05c447cf6cf3a /lib/Transforms
parentcbb9812d0df6b64d42c3b2687c877050612a7129 (diff)
downloadexternal_llvm-031955d4623193b1c4163bd43db0eaaf6b08c27b.zip
external_llvm-031955d4623193b1c4163bd43db0eaaf6b08c27b.tar.gz
external_llvm-031955d4623193b1c4163bd43db0eaaf6b08c27b.tar.bz2
Avoid calling use_size() which could (in theory) be expensive if the global
has a large number of users. Instead, just keep track of whether we're making changes as we do so. This patch has no functionlity changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16874 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index e4696e6..7c0c322 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -231,8 +231,10 @@ static Constant *TraverseGEPInitializer(User *GEP, Constant *Init) {
/// CleanupConstantGlobalUsers - We just marked GV constant. Loop over all
/// users of the global, cleaning up the obvious ones. This is largely just a
-/// quick scan over the use list to clean up the easy and obvious cruft.
-static void CleanupConstantGlobalUsers(Value *V, Constant *Init) {
+/// quick scan over the use list to clean up the easy and obvious cruft. This
+/// returns true if it made a change.
+static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
+ bool Changed = false;
for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;) {
User *U = *UI++;
@@ -240,20 +242,27 @@ static void CleanupConstantGlobalUsers(Value *V, Constant *Init) {
// Replace the load with the initializer.
LI->replaceAllUsesWith(Init);
LI->getParent()->getInstList().erase(LI);
+ Changed = true;
} else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
// Store must be unreachable or storing Init into the global.
SI->getParent()->getInstList().erase(SI);
+ Changed = true;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
if (CE->getOpcode() == Instruction::GetElementPtr) {
if (Constant *SubInit = TraverseGEPInitializer(CE, Init))
- CleanupConstantGlobalUsers(CE, SubInit);
- if (CE->use_empty()) CE->destroyConstant();
+ Changed |= CleanupConstantGlobalUsers(CE, SubInit);
+ if (CE->use_empty()) {
+ CE->destroyConstant();
+ Changed = true;
+ }
}
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
if (Constant *SubInit = TraverseGEPInitializer(GEP, Init))
- CleanupConstantGlobalUsers(GEP, SubInit);
- if (GEP->use_empty())
+ Changed |= CleanupConstantGlobalUsers(GEP, SubInit);
+ if (GEP->use_empty()) {
GEP->getParent()->getInstList().erase(GEP);
+ Changed = true;
+ }
} else if (Constant *C = dyn_cast<Constant>(U)) {
// If we have a chain of dead constantexprs or other things dangling from
// us, and if they are all dead, nuke them without remorse.
@@ -261,10 +270,11 @@ static void CleanupConstantGlobalUsers(Value *V, Constant *Init) {
C->destroyConstant();
// This could have incalidated UI, start over from scratch.x
CleanupConstantGlobalUsers(V, Init);
- return;
+ return true;
}
}
}
+ return Changed;
}
/// SRAGlobal - Perform scalar replacement of aggregates on the specified global
@@ -472,14 +482,10 @@ static bool ProcessInternalGlobal(GlobalVariable *GV, Module::giterator &GVI) {
// Delete it now.
if (!GS.isLoaded) {
DEBUG(std::cerr << "GLOBAL NEVER LOADED: " << *GV);
- unsigned NumUsers = GV->use_size();
// Delete any stores we can find to the global. We may not be able to
// make it completely dead though.
- CleanupConstantGlobalUsers(GV, GV->getInitializer());
-
- // Did we delete any stores?
- bool Changed = NumUsers != GV->use_size();
+ bool Changed = CleanupConstantGlobalUsers(GV, GV->getInitializer());
// If the global is dead now, delete it.
if (GV->use_empty()) {