namespace {
class Reassociate : public FunctionPass {
- map<BasicBlock*, unsigned> RankMap;
+ std::map<BasicBlock*, unsigned> RankMap;
public:
bool runOnFunction(Function &F);
bool ReassociateBB(BasicBlock *BB);
};
- RegisterPass<Reassociate> X("reassociate", "Reassociate expressions");
+ RegisterOpt<Reassociate> X("reassociate", "Reassociate expressions");
}
Pass *createReassociatePass() { return new Reassociate(); }
// 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
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;
}
// 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));