[llvm-commits] CVS: llvm/lib/Transforms/IPO/IPConstantPropagation.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Oct 27 15:10:01 PST 2003


Changes in directory llvm/lib/Transforms/IPO:

IPConstantPropagation.cpp updated: 1.2 -> 1.3

---
Log message:

Propagating constants to arguments can make other arguments constant.  For now
do something dumb, and inefficient, but more complete.


---
Diffs of the changes:  (+15 -5)

Index: llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
diff -u llvm/lib/Transforms/IPO/IPConstantPropagation.cpp:1.2 llvm/lib/Transforms/IPO/IPConstantPropagation.cpp:1.3
--- llvm/lib/Transforms/IPO/IPConstantPropagation.cpp:1.2	Thu Oct 23 13:49:23 2003
+++ llvm/lib/Transforms/IPO/IPConstantPropagation.cpp	Mon Oct 27 15:09:00 2003
@@ -40,9 +40,17 @@
 
 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 @@
   // 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;
 }





More information about the llvm-commits mailing list