//===- IndVarSimplify.cpp - Induction Variable Elimination ----------------===//
-//
+//
// 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 transformation analyzes and transforms the induction variables (and
bool isInsertedInstruction(Instruction *I) const {
return InsertedInstructions.count(I);
}
-
+
/// getOrInsertCanonicalInductionVariable - This method returns the
/// canonical induction variable of the specified type for the specified
/// loop (inserting one if there is none). A canonical induction variable
return ConstantExpr::getCast(C, Ty);
else if (Instruction *I = dyn_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();
+ 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.
BasicBlock::InstListType &InstList =
- I->getParent()->getInstList();
+ It->getParent()->getInstList();
InstList.splice(It, CI->getParent()->getInstList(), CI);
}
return CI;
if (SCEVConstant *SC = dyn_cast<SCEVConstant>(S->getOperand(0)))
if (SC->getValue()->isAllOnesValue())
FirstOp = 1;
-
+
int i = S->getNumOperands()-2;
Value *V = expandInTy(S->getOperand(i+1), Ty);
-
+
// Emit a bunch of multiply instructions
for (; i >= FirstOp; --i)
V = BinaryOperator::createMul(V, expandInTy(S->getOperand(i), Ty),
/// EliminatePointerRecurrence - Check to see if this is a trivial GEP pointer
/// recurrence. If so, change it into an integer recurrence, permitting
/// analysis by the SCEV routines.
-void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
+void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
BasicBlock *Preheader,
std::set<Instruction*> &DeadInsts) {
assert(PN->getNumIncomingValues() == 2 && "Noncanonicalized loop!");
dyn_cast<GetElementPtrInst>(PN->getIncomingValue(BackedgeIdx)))
if (GEPI->getOperand(0) == PN) {
assert(GEPI->getNumOperands() == 2 && "GEP types must mismatch!");
-
+
// Okay, we found a pointer recurrence. Transform this pointer
// recurrence into an integer recurrence. Compute the value that gets
// added to the pointer at every iteration.
Value *NewAdd = BinaryOperator::createAdd(NewPhi, AddedVal,
GEPI->getName()+".rec", GEPI);
NewPhi->addIncoming(NewAdd, PN->getIncomingBlock(BackedgeIdx));
-
+
// Update the existing GEP to use the recurrence.
GEPI->setOperand(0, PN->getIncomingValue(PreheaderIdx));
-
+
// Update the GEP to use the new recurrence we just inserted.
GEPI->setOperand(1, NewAdd);
bool HasConstantItCount = isa<SCEVConstant>(SE->getIterationCount(L));
std::set<Instruction*> InstructionsToDelete;
-
+
for (unsigned i = 0, e = L->getBlocks().size(); i != e; ++i)
if (LI->getLoopFor(L->getBlocks()[i]) == L) { // Not in a subloop...
BasicBlock *BB = L->getBlocks()[i];
//
BasicBlock *Header = L->getHeader();
BasicBlock *Preheader = L->getLoopPreheader();
-
+
std::set<Instruction*> DeadInsts;
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
PHINode *PN = cast<PHINode>(I);
DeadInsts.insert(I);
++NumRemoved;
Changed = true;
- }
+ }
}
}
#endif