Function.h is unnecessary when Module.h is included.
[oota-llvm.git] / lib / Transforms / Scalar / Reassociate.cpp
index 05758039d944f5f38b019f190a18d8ccb9eaa927..7d76bfb681f8fc01eaa57ebd0b32900e3a3a2367 100644 (file)
@@ -33,7 +33,7 @@ static Statistic<> NumSwapped("reassociate\t- Number of insts with operands swap
 
 namespace {
   class Reassociate : public FunctionPass {
-    map<BasicBlock*, unsigned> RankMap;
+    std::map<BasicBlock*, unsigned> RankMap;
   public:
     bool runOnFunction(Function &F);
 
@@ -47,7 +47,7 @@ namespace {
     bool ReassociateBB(BasicBlock *BB);
   };
 
-  RegisterPass<Reassociate> X("reassociate", "Reassociate expressions");
+  RegisterOpt<Reassociate> X("reassociate", "Reassociate expressions");
 }
 
 Pass *createReassociatePass() { return new Reassociate(); }
@@ -180,12 +180,9 @@ static Value *NegateValue(Value *V, BasicBlock *BB, BasicBlock::iterator &BI) {
       // adding it now, we are assured that the neg instructions we just
       // inserted dominate the instruction we are about to insert after them.
       //
-      BasicBlock::iterator NBI = cast<Instruction>(RHS);
-
-      Instruction *Add =
-        BinaryOperator::create(Instruction::Add, LHS, RHS, I->getName()+".neg");
-      BB->getInstList().insert(++NBI, Add);  // Add to the basic block...
-      return Add;
+      return BinaryOperator::create(Instruction::Add, LHS, RHS,
+                                    I->getName()+".neg",
+                                    cast<Instruction>(RHS)->getNext());
     }
 
   // Insert a 'neg' instruction that subtracts the value from zero to get the
@@ -194,8 +191,8 @@ static Value *NegateValue(Value *V, BasicBlock *BB, BasicBlock::iterator &BI) {
   Instruction *Neg =
     BinaryOperator::create(Instruction::Sub,
                            Constant::getNullValue(V->getType()), V,
-                           V->getName()+".neg");
-  BI = BB->getInstList().insert(BI, Neg);  // Add to the basic block...
+                           V->getName()+".neg", BI);
+  --BI;
   return Neg;
 }
 
@@ -220,8 +217,9 @@ bool Reassociate::ReassociateBB(BasicBlock *BB) {
           // Insert a new temporary instruction... (A+B)+C
           BinaryOperator *Tmp = BinaryOperator::create(I->getOpcode(), LHSI,
                                                        RHSI->getOperand(0),
-                                                       RHSI->getName()+".ra");
-          BI = BB->getInstList().insert(BI, Tmp);  // Add to the basic block...
+                                                       RHSI->getName()+".ra",
+                                                       BI);
+          BI = Tmp;
           I->setOperand(0, Tmp);
           I->setOperand(1, RHSI->getOperand(1));