X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FPiNodeInsertion.cpp;h=4f52051e61bfa26cced32fe2df40bcec0908bc26;hb=0006bd75201f340b95c1dbf71e50dc5de5ed9425;hp=2e9c32800b6189c5d8123cd30228750fafff1374;hpb=3dec1f272219ee1f8e1499929cdf53f5bc3c2272;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/PiNodeInsertion.cpp b/lib/Transforms/Scalar/PiNodeInsertion.cpp index 2e9c32800b6..4f52051e61b 100644 --- a/lib/Transforms/Scalar/PiNodeInsertion.cpp +++ b/lib/Transforms/Scalar/PiNodeInsertion.cpp @@ -29,24 +29,21 @@ #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 { - 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(); - AU.addRequired(DominatorSet::ID); + AU.setPreservesCFG(); + AU.addRequired(); } // insertPiNodeFor - Insert a Pi node for V in the successors of BB if our @@ -56,16 +53,17 @@ namespace { // bool insertPiNodeFor(Value *V, BasicBlock *BB, Value *Rep = 0); }; + + RegisterOpt 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 @@ -112,8 +110,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(*I)) @@ -150,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.