//
// 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.
//
//===----------------------------------------------------------------------===//
//
for (Value::use_iterator UI = A->use_begin(), E = A->use_end();
UI != E; ++UI) {
if ((*UI)->getType() == Ty)
- if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- // If the cast isn't the first instruction of the function, move it.
- if (BasicBlock::iterator(CI) !=
- A->getParent()->getEntryBlock().begin()) {
- CI->moveBefore(A->getParent()->getEntryBlock().begin());
+ if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI)))
+ if (CI->getOpcode() == opcode) {
+ // If the cast isn't the first instruction of the function, move it.
+ if (BasicBlock::iterator(CI) !=
+ A->getParent()->getEntryBlock().begin()) {
+ CI->moveBefore(A->getParent()->getEntryBlock().begin());
+ }
+ return CI;
}
- return CI;
- }
}
- return CastInst::create(opcode, V, Ty, V->getName(),
+ return CastInst::Create(opcode, V, Ty, V->getName(),
A->getParent()->getEntryBlock().begin());
}
-
+
Instruction *I = cast<Instruction>(V);
-
+
// Check to see if there is already a cast. If there is, use it.
for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
UI != E; ++UI) {
if ((*UI)->getType() == Ty)
- if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
- BasicBlock::iterator It = I; ++It;
- if (isa<InvokeInst>(I))
- It = cast<InvokeInst>(I)->getNormalDest()->begin();
- while (isa<PHINode>(It)) ++It;
- if (It != BasicBlock::iterator(CI)) {
- // Splice the cast immediately after the operand in question.
- CI->moveBefore(It);
+ if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI)))
+ if (CI->getOpcode() == opcode) {
+ BasicBlock::iterator It = I; ++It;
+ if (isa<InvokeInst>(I))
+ It = cast<InvokeInst>(I)->getNormalDest()->begin();
+ while (isa<PHINode>(It)) ++It;
+ if (It != BasicBlock::iterator(CI)) {
+ // Splice the cast immediately after the operand in question.
+ CI->moveBefore(It);
+ }
+ return CI;
}
- return CI;
- }
}
BasicBlock::iterator IP = I; ++IP;
if (InvokeInst *II = dyn_cast<InvokeInst>(I))
IP = II->getNormalDest()->begin();
while (isa<PHINode>(IP)) ++IP;
- return CastInst::create(opcode, V, Ty, V->getName(), IP);
+ return CastInst::Create(opcode, V, Ty, V->getName(), IP);
}
/// InsertBinop - Insert the specified binary operator, doing a small amount
}
// If we don't have
- return BinaryOperator::create(Opcode, LHS, RHS, "tmp", InsertPt);
+ return BinaryOperator::Create(Opcode, LHS, RHS, "tmp", InsertPt);
}
Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {
// Create and insert the PHI node for the induction variable in the
// specified loop.
BasicBlock *Header = L->getHeader();
- PHINode *PN = new PHINode(Ty, "indvar", Header->begin());
+ PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader());
pred_iterator HPI = pred_begin(Header);
// Insert a unit add instruction right before the terminator corresponding
// to the back-edge.
Constant *One = ConstantInt::get(Ty, 1);
- Instruction *Add = BinaryOperator::createAdd(PN, One, "indvar.next",
+ Instruction *Add = BinaryOperator::CreateAdd(PN, One, "indvar.next",
(*HPI)->getTerminator());
pred_iterator PI = pred_begin(Header);
return expand(V);
}
+Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {
+ Value *LHS = expand(S->getOperand(0));
+ for (unsigned i = 1; i < S->getNumOperands(); ++i) {
+ Value *RHS = expand(S->getOperand(i));
+ Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt);
+ LHS = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt);
+ }
+ return LHS;
+}
+
+Value *SCEVExpander::visitUMaxExpr(SCEVUMaxExpr *S) {
+ Value *LHS = expand(S->getOperand(0));
+ for (unsigned i = 1; i < S->getNumOperands(); ++i) {
+ Value *RHS = expand(S->getOperand(i));
+ Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt);
+ LHS = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt);
+ }
+ return LHS;
+}
+
Value *SCEVExpander::expand(SCEV *S) {
// Check to see if we already expanded this.
std::map<SCEVHandle, Value*>::iterator I = InsertedExpressions.find(S);
InsertedExpressions[S] = V;
return V;
}
-