[llvm-commits] CVS: llvm/lib/Transforms/Scalar/GVNPRE.cpp

Owen Anderson resistor at mac.com
Wed Jun 20 11:30:42 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

GVNPRE.cpp updated: 1.44 -> 1.45
---
Log message:

Make GVNPRE accurate report whether it modified the function or not.


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

 GVNPRE.cpp |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Scalar/GVNPRE.cpp
diff -u llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.44 llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.45
--- llvm/lib/Transforms/Scalar/GVNPRE.cpp:1.44	Tue Jun 19 19:43:33 2007
+++ llvm/lib/Transforms/Scalar/GVNPRE.cpp	Wed Jun 20 13:30:20 2007
@@ -351,7 +351,7 @@
     // For a given block, calculate the generated expressions, temporaries,
     // and the AVAIL_OUT set
     void cleanup();
-    void elimination();
+    void elimination(bool& changed_function);
     
     void val_insert(std::set<Value*>& s, Value* v);
     void val_replace(std::set<Value*>& s, Value* v);
@@ -656,7 +656,7 @@
   DOUT << "}\n\n";
 }
 
-void GVNPRE::elimination() {
+void GVNPRE::elimination(bool& changed_function) {
   DOUT << "\n\nPhase 3: Elimination\n\n";
   
   std::vector<std::pair<Instruction*, Value*> > replace;
@@ -693,6 +693,7 @@
     std::pair<Instruction*, Value*> rep = replace.back();
     replace.pop_back();
     rep.first->replaceAllUsesWith(rep.second);
+    changed_function = true;
   }
     
   for (std::vector<Instruction*>::iterator I = erase.begin(), E = erase.end();
@@ -716,6 +717,8 @@
   availableOut.clear();
   anticipatedIn.clear();
   invokeDep.clear();
+  
+  bool changed_function = false;
 
   std::map<BasicBlock*, std::set<Value*> > generatedExpressions;
   std::map<BasicBlock*, std::set<PHINode*> > generatedPhis;
@@ -798,7 +801,7 @@
   // If function has no exit blocks, only perform GVN
   PostDominatorTree &PDT = getAnalysis<PostDominatorTree>();
   if (PDT[&F.getEntryBlock()] == 0) {
-    elimination();
+    elimination(changed_function);
     cleanup();
     
     return true;
@@ -1049,6 +1052,8 @@
                                              C->getName()+".gvnpre",
                                              (*PI)->getTerminator());
                   
+                  changed_function = true;
+                  
                   VN.add(newVal, VN.lookup(U));
                   
                   std::set<Value*>& predAvail = availableOut[*PI];
@@ -1076,6 +1081,8 @@
                 p->addIncoming(avail[*PI], *PI);
               }
               
+              changed_function = true;
+              
               VN.add(p, VN.lookup(e));
               DOUT << "Creating value: " << std::hex << p << std::dec << "\n";
               
@@ -1106,10 +1113,10 @@
   }
   
   // Phase 3: Eliminate
-  elimination();
+  elimination(changed_function);
   
   // Phase 4: Cleanup
   cleanup();
   
-  return true;
+  return changed_function;
 }






More information about the llvm-commits mailing list