[llvm-commits] [llvm] r122705 - /llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp

Nick Lewycky nicholas at mxc.ca
Sun Jan 2 11:16:44 PST 2011


Author: nicholas
Date: Sun Jan  2 13:16:44 2011
New Revision: 122705

URL: http://llvm.org/viewvc/llvm-project?rev=122705&view=rev
Log:
Also remove functions that use complex constant expressions in terms of
another function.

Modified:
    llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp

Modified: llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp?rev=122705&r1=122704&r2=122705&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/MergeFunctions.cpp Sun Jan  2 13:16:44 2011
@@ -696,11 +696,24 @@
 // RemoveUsers - For each instruction used by the value, Remove() the function
 // that contains the instruction. This should happen right before a call to RAUW.
 void MergeFunctions::RemoveUsers(Value *V) {
-  for (Value::use_iterator UI = V->use_begin(), UE = V->use_end();
-       UI != UE; ++UI) {
-    Use &U = UI.getUse();
-    if (Instruction *I = dyn_cast<Instruction>(U.getUser())) {
-      Remove(I->getParent()->getParent());
+  std::vector<Value *> Worklist;
+  Worklist.push_back(V);
+  while (!Worklist.empty()) {
+    Value *V = Worklist.back();
+    Worklist.pop_back();
+
+    for (Value::use_iterator UI = V->use_begin(), UE = V->use_end();
+         UI != UE; ++UI) {
+      Use &U = UI.getUse();
+      if (Instruction *I = dyn_cast<Instruction>(U.getUser())) {
+        Remove(I->getParent()->getParent());
+      } else if (isa<GlobalValue>(U.getUser())) {
+	// do nothing
+      } else if (Constant *C = dyn_cast<Constant>(U.getUser())) {
+	for (Value::use_iterator CUI = C->use_begin(), CUE = C->use_end();
+	     CUI != CUE; ++CUI)
+          Worklist.push_back(*CUI);
+      }
     }
   }
 }





More information about the llvm-commits mailing list