* Standardize how analysis results/passes as printed with the print() virtual
[oota-llvm.git] / lib / Transforms / Scalar / PiNodeInsertion.cpp
index d7bc08b1a4b36f91545902b97e5b22279b71b588..399b5fee88cba658c3ffa67ce88088ada7b2efe0 100644 (file)
 #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");
 
 namespace {
   struct PiNodeInserter : public FunctionPass {
-    const char *getPassName() const { return "Pi Node Insertion"; }
-    
-    virtual bool runOnFunction(Function *F);
+    virtual bool runOnFunction(Function &F);
     
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.preservesCFG();
@@ -53,16 +54,17 @@ namespace {
     //
     bool insertPiNodeFor(Value *V, BasicBlock *BB, Value *Rep = 0);
   };
+
+  RegisterOpt<PiNodeInserter> X("pinodes", "Pi Node Insertion");
 }
 
 Pass *createPiNodeInsertionPass() { return new PiNodeInserter(); }
 
 
-bool PiNodeInserter::runOnFunction(Function *F) {
+bool PiNodeInserter::runOnFunction(Function &F) {
   bool Changed = false;
-  for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
-    BasicBlock *BB = *I;
-    TerminatorInst *TI = BB->getTerminator();
+  for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
+    TerminatorInst *TI = I->getTerminator();
     
     // FIXME: Insert PI nodes for switch statements too
 
@@ -109,8 +111,7 @@ bool PiNodeInserter::runOnFunction(Function *F) {
 }
 
 
-// alreadyHasPiNodeFor - Return true if there is already a Pi node in BB for
-// V.
+// alreadyHasPiNodeFor - Return true if there is already a Pi node in BB for V.
 static bool alreadyHasPiNodeFor(Value *V, BasicBlock *BB) {
   for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
     if (PHINode *PN = dyn_cast<PHINode>(*I))
@@ -180,6 +181,8 @@ bool PiNodeInserter::insertPiNodeFor(Value *V, BasicBlock *Succ, Value *Rep) {
   if (Rep == 0)
     cast<PHINode>(Pi)->addIncoming(V, Pred);
  
+
+  ++NumInserted;
   return true;
 }