1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

Actually insert inserted instructions into the InsertedValues map.

llvm-svn: 70557
This commit is contained in:
Dan Gohman 2009-05-01 17:13:31 +00:00
parent daa3a9f38c
commit d57099a9eb
2 changed files with 35 additions and 13 deletions

View File

@ -106,8 +106,8 @@ namespace llvm {
/// InsertBinop - Insert the specified binary operator, doing a small amount /// InsertBinop - Insert the specified binary operator, doing a small amount
/// of work to avoid inserting an obviously redundant operation. /// of work to avoid inserting an obviously redundant operation.
static Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
Value *RHS, BasicBlock::iterator InsertPt); Value *RHS, BasicBlock::iterator InsertPt);
private: private:
Value *expand(const SCEV *S); Value *expand(const SCEV *S);

View File

@ -64,8 +64,10 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
return CI; return CI;
} }
} }
return CastInst::Create(opcode, V, Ty, V->getName(), Instruction *I = CastInst::Create(opcode, V, Ty, V->getName(),
A->getParent()->getEntryBlock().begin()); A->getParent()->getEntryBlock().begin());
InsertedValues.insert(I);
return I;
} }
Instruction *I = cast<Instruction>(V); Instruction *I = cast<Instruction>(V);
@ -93,7 +95,9 @@ Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V,
if (InvokeInst *II = dyn_cast<InvokeInst>(I)) if (InvokeInst *II = dyn_cast<InvokeInst>(I))
IP = II->getNormalDest()->begin(); IP = II->getNormalDest()->begin();
while (isa<PHINode>(IP)) ++IP; while (isa<PHINode>(IP)) ++IP;
return CastInst::Create(opcode, V, Ty, V->getName(), IP); Instruction *CI = CastInst::Create(opcode, V, Ty, V->getName(), IP);
InsertedValues.insert(CI);
return CI;
} }
/// InsertNoopCastOfTo - Insert a cast of V to the specified type, /// InsertNoopCastOfTo - Insert a cast of V to the specified type,
@ -135,7 +139,9 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
} }
// If we haven't found this binop, insert it. // If we haven't found this binop, insert it.
return BinaryOperator::Create(Opcode, LHS, RHS, "tmp", InsertPt); Instruction *BO = BinaryOperator::Create(Opcode, LHS, RHS, "tmp", InsertPt);
InsertedValues.insert(BO);
return BO;
} }
Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) { Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) {
@ -218,6 +224,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
// specified loop. // specified loop.
BasicBlock *Header = L->getHeader(); BasicBlock *Header = L->getHeader();
PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin()); PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
InsertedValues.insert(PN);
PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader()); PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader());
pred_iterator HPI = pred_begin(Header); pred_iterator HPI = pred_begin(Header);
@ -231,6 +238,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
Constant *One = ConstantInt::get(Ty, 1); Constant *One = ConstantInt::get(Ty, 1);
Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next", Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
(*HPI)->getTerminator()); (*HPI)->getTerminator());
InsertedValues.insert(Add);
pred_iterator PI = pred_begin(Header); pred_iterator PI = pred_begin(Header);
if (*PI == L->getLoopPreheader()) if (*PI == L->getLoopPreheader())
@ -296,21 +304,27 @@ Value *SCEVExpander::visitTruncateExpr(const SCEVTruncateExpr *S) {
const Type *Ty = SE.getEffectiveSCEVType(S->getType()); const Type *Ty = SE.getEffectiveSCEVType(S->getType());
Value *V = expand(S->getOperand()); Value *V = expand(S->getOperand());
V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType())); V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType()));
return new TruncInst(V, Ty, "tmp.", InsertPt); Instruction *I = new TruncInst(V, Ty, "tmp.", InsertPt);
InsertedValues.insert(I);
return I;
} }
Value *SCEVExpander::visitZeroExtendExpr(const SCEVZeroExtendExpr *S) { Value *SCEVExpander::visitZeroExtendExpr(const SCEVZeroExtendExpr *S) {
const Type *Ty = SE.getEffectiveSCEVType(S->getType()); const Type *Ty = SE.getEffectiveSCEVType(S->getType());
Value *V = expand(S->getOperand()); Value *V = expand(S->getOperand());
V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType())); V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType()));
return new ZExtInst(V, Ty, "tmp.", InsertPt); Instruction *I = new ZExtInst(V, Ty, "tmp.", InsertPt);
InsertedValues.insert(I);
return I;
} }
Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) { Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {
const Type *Ty = SE.getEffectiveSCEVType(S->getType()); const Type *Ty = SE.getEffectiveSCEVType(S->getType());
Value *V = expand(S->getOperand()); Value *V = expand(S->getOperand());
V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType())); V = InsertNoopCastOfTo(V, SE.getEffectiveSCEVType(V->getType()));
return new SExtInst(V, Ty, "tmp.", InsertPt); Instruction *I = new SExtInst(V, Ty, "tmp.", InsertPt);
InsertedValues.insert(I);
return I;
} }
Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) { Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) {
@ -320,8 +334,12 @@ Value *SCEVExpander::visitSMaxExpr(const SCEVSMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) { for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i)); Value *RHS = expand(S->getOperand(i));
RHS = InsertNoopCastOfTo(RHS, Ty); RHS = InsertNoopCastOfTo(RHS, Ty);
Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt); Instruction *ICmp =
LHS = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt); new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt);
InsertedValues.insert(ICmp);
Instruction *Sel = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt);
InsertedValues.insert(Sel);
LHS = Sel;
} }
return LHS; return LHS;
} }
@ -333,8 +351,12 @@ Value *SCEVExpander::visitUMaxExpr(const SCEVUMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) { for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i)); Value *RHS = expand(S->getOperand(i));
RHS = InsertNoopCastOfTo(RHS, Ty); RHS = InsertNoopCastOfTo(RHS, Ty);
Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt); Instruction *ICmp =
LHS = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt); new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt);
InsertedValues.insert(ICmp);
Instruction *Sel = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt);
InsertedValues.insert(Sel);
LHS = Sel;
} }
return LHS; return LHS;
} }