Fix warning
[oota-llvm.git] / lib / Transforms / Scalar / PiNodeInsertion.cpp
index 81f3cb3e9338c62212ff6552ac22e49d642cbb35..4f52051e61bfa26cced32fe2df40bcec0908bc26 100644 (file)
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Pass.h"
 #include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iOperators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/Support/CFG.h"
-#include "Support/StatisticReporter.h"
-
-static Statistic<> NumInserted("pinodes\t\t- Number of Pi nodes inserted");
+#include "Support/Statistic.h"
 
 namespace {
+  Statistic<> NumInserted("pinodes", "Number of Pi nodes inserted");
+
   struct PiNodeInserter : public FunctionPass {
     virtual bool runOnFunction(Function &F);
     
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      AU.preservesCFG();
-      AU.addRequired(DominatorSet::ID);
+      AU.setPreservesCFG();
+      AU.addRequired<DominatorSet>();
     }
 
     // insertPiNodeFor - Insert a Pi node for V in the successors of BB if our
@@ -55,7 +54,7 @@ namespace {
     bool insertPiNodeFor(Value *V, BasicBlock *BB, Value *Rep = 0);
   };
 
-  RegisterPass<PiNodeInserter> X("pinodes", "Pi Node Insertion");
+  RegisterOpt<PiNodeInserter> X("pinodes", "Pi Node Insertion");
 }
 
 Pass *createPiNodeInsertionPass() { return new PiNodeInserter(); }
@@ -148,13 +147,8 @@ bool PiNodeInserter::insertPiNodeFor(Value *V, BasicBlock *Succ, Value *Rep) {
     
   // Create the Pi node...
   Value *Pi = Rep;
-  if (Rep == 0) {
-    PHINode *Phi = new PHINode(V->getType(), V->getName() + ".pi");
-    
-    // Insert the Pi node in the successor basic block...
-    Succ->getInstList().push_front(Phi);
-    Pi = Phi;
-  }
+  if (Rep == 0)      // Insert the Pi node in the successor basic block...
+    Pi = new PHINode(V->getType(), V->getName() + ".pi", Succ->begin());
     
   // Loop over all of the uses of V, replacing ones that the Pi node
   // dominates with references to the Pi node itself.