aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/IPO
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-27 21:09:00 +0000
committerChris Lattner <sabre@nondot.org>2003-10-27 21:09:00 +0000
commit2e8dfb8221d8fbb4d007cd1ab5e63dac0accea4b (patch)
treeef205f4bacc7d03670d8a98caf12f4b1bedc970b /lib/Transforms/IPO
parente01fcfbdeff0c7b1bbb861184769ad7c8bd9a4db (diff)
downloadexternal_llvm-2e8dfb8221d8fbb4d007cd1ab5e63dac0accea4b.zip
external_llvm-2e8dfb8221d8fbb4d007cd1ab5e63dac0accea4b.tar.gz
external_llvm-2e8dfb8221d8fbb4d007cd1ab5e63dac0accea4b.tar.bz2
Propagating constants to arguments can make other arguments constant. For now
do something dumb, and inefficient, but more complete. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9542 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r--lib/Transforms/IPO/IPConstantPropagation.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index bb21f11..b592138 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -40,9 +40,17 @@ Pass *createIPConstantPropagationPass() { return new IPCP(); }
bool IPCP::run(Module &M) {
bool Changed = false;
- for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- if (!I->isExternal() && I->hasInternalLinkage())
- Changed |= processFunction(*I);
+ bool LocalChange = true;
+
+ // FIXME: instead of using smart algorithms, we just iterate until we stop
+ // making changes.
+ while (LocalChange) {
+ LocalChange = false;
+ for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+ if (!I->isExternal() && I->hasInternalLinkage())
+ LocalChange |= processFunction(*I);
+ Changed |= LocalChange;
+ }
return Changed;
}
@@ -99,15 +107,17 @@ bool IPCP::processFunction(Function &F) {
// If we got to this point, there is a constant argument!
assert(NumNonconstant != ArgumentConstants.size());
Function::aiterator AI = F.abegin();
+ bool MadeChange = false;
for (unsigned i = 0, e = ArgumentConstants.size(); i != e; ++i, ++AI)
// Do we have a constant argument!?
- if (!ArgumentConstants[i].second) {
+ if (!ArgumentConstants[i].second && !AI->use_empty()) {
assert(ArgumentConstants[i].first && "Unknown constant value!");
Value *V = ArgumentConstants[i].first;
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V))
V = CPR->getValue();
AI->replaceAllUsesWith(V);
++NumArgumentsProped;
+ MadeChange = true;
}
- return true;
+ return MadeChange;
}