API changes for class Use size reduction, wave 1.
[oota-llvm.git] / lib / Transforms / Scalar / GCSE.cpp
index f4727d4e30305def281b96480ed18c20aa2b909e..39a1b257258073a123d797f30df865593bae909d 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -37,6 +37,9 @@ STATISTIC(NumArgsRepl   , "Number of function arguments replaced "
                           "with constant values");
 namespace {
   struct VISIBILITY_HIDDEN GCSE : public FunctionPass {
+    static char ID; // Pass identification, replacement for typeid
+    GCSE() : FunctionPass((intptr_t)&ID) {}
+
     virtual bool runOnFunction(Function &F);
 
   private:
@@ -45,12 +48,12 @@ namespace {
     // This transformation requires dominator and immediate dominator info
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesCFG();
-      AU.addRequired<ETForest>();
       AU.addRequired<DominatorTree>();
       AU.addRequired<ValueNumbering>();
     }
   };
 
+  char GCSE::ID = 0;
   RegisterPass<GCSE> X("gcse", "Global Common Subexpression Elimination");
 }
 
@@ -64,9 +67,8 @@ bool GCSE::runOnFunction(Function &F) {
   bool Changed = false;
 
   // Get pointers to the analysis results that we will be using...
-  ETForest &EF = getAnalysis<ETForest>();
-  ValueNumbering &VN = getAnalysis<ValueNumbering>();
   DominatorTree &DT = getAnalysis<DominatorTree>();
+  ValueNumbering &VN = getAnalysis<ValueNumbering>();
 
   std::vector<Value*> EqualValues;
 
@@ -90,7 +92,7 @@ bool GCSE::runOnFunction(Function &F) {
 
   // Traverse the CFG of the function in dominator order, so that we see each
   // instruction after we see its operands.
-  for (df_iterator<DominatorTree::Node*> DI = df_begin(DT.getRootNode()),
+  for (df_iterator<DomTreeNode*> DI = df_begin(DT.getRootNode()),
          E = df_end(DT.getRootNode()); DI != E; ++DI) {
     BasicBlock *BB = DI->getBlock();
 
@@ -141,7 +143,7 @@ bool GCSE::runOnFunction(Function &F) {
             if (OtherI->getParent() == BB)
               Dominates = BlockInsts.count(OtherI);
             else
-              Dominates = EF.dominates(OtherI->getParent(), BB);
+              Dominates = DT.dominates(OtherI->getParent(), BB);
 
             if (Dominates) {
               // Okay, we found an instruction with the same value as this one
@@ -190,7 +192,7 @@ void GCSE::ReplaceInstructionWith(Instruction *I, Value *V) {
   if (InvokeInst *II = dyn_cast<InvokeInst>(I)) {
     // Removing an invoke instruction requires adding a branch to the normal
     // destination and removing PHI node entries in the exception destination.
-    new BranchInst(II->getNormalDest(), II);
+    BranchInst::Create(II->getNormalDest(), II);
     II->getUnwindDest()->removePredecessor(II->getParent());
   }