if (!AddRec || !AddRec->isAffine())
continue;
const SCEV *Step = AddRec->getStepRecurrence(*SE);
- const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
- if (!C)
+ if (!isa<SCEVConstant>(Step))
continue;
// Found the induction variable.
// FIXME: Handle loops with more than one induction variable. Note that,
for (Loop *L : LoopList) {
const SCEV *ExitCountOuter = SE->getBackedgeTakenCount(L);
if (ExitCountOuter == SE->getCouldNotCompute()) {
- DEBUG(dbgs() << "Couldn't compute Backedge count\n");
+ DEBUG(dbgs() << "Couldn't compute backedge count\n");
return false;
}
if (L->getNumBackEdges() != 1) {
return false;
}
if (!L->getExitingBlock()) {
- DEBUG(dbgs() << "Loop Doesn't have unique exit block\n");
+ DEBUG(dbgs() << "Loop doesn't have unique exit block\n");
return false;
}
}
Loop *OuterMostLoop = *(LoopList.begin());
if (!populateDependencyMatrix(DependencyMatrix, LoopNestDepth,
OuterMostLoop, DI)) {
- DEBUG(dbgs() << "Populating Dependency matrix failed\n");
+ DEBUG(dbgs() << "Populating dependency matrix failed\n");
return false;
}
#ifdef DUMP_DEP_MATRICIES
DEBUG(dbgs() << "Loops are legal to interchange\n");
LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE);
if (!LIP.isProfitable(InnerLoopId, OuterLoopId, DependencyMatrix)) {
- DEBUG(dbgs() << "Interchanging Loops not profitable\n");
+ DEBUG(dbgs() << "Interchanging loops not profitable\n");
return false;
}
// Stores corresponding to reductions are safe while concluding if tightly
// nested.
if (StoreInst *L = dyn_cast<StoreInst>(I)) {
- PHINode *PHI = dyn_cast<PHINode>(L->getOperand(0));
- if (!PHI)
+ if (!isa<PHINode>(L->getOperand(0)))
return true;
} else if (I->mayHaveSideEffects() || I->mayReadFromMemory())
return true;
BasicBlock *InnerLoopPreHeader = InnerLoop->getLoopPreheader();
BasicBlock *OuterLoopLatch = OuterLoop->getLoopLatch();
- DEBUG(dbgs() << "Checking if Loops are Tightly Nested\n");
+ DEBUG(dbgs() << "Checking if loops are tightly nested\n");
// A perfectly nested loop will not have any branch in between the outer and
// inner block i.e. outer header will branch to either inner preheader and
// outerloop latch.
- BranchInst *outerLoopHeaderBI =
+ BranchInst *OuterLoopHeaderBI =
dyn_cast<BranchInst>(OuterLoopHeader->getTerminator());
- if (!outerLoopHeaderBI)
+ if (!OuterLoopHeaderBI)
return false;
- unsigned num = outerLoopHeaderBI->getNumSuccessors();
- for (unsigned i = 0; i < num; i++) {
- if (outerLoopHeaderBI->getSuccessor(i) != InnerLoopPreHeader &&
- outerLoopHeaderBI->getSuccessor(i) != OuterLoopLatch)
+
+ for (unsigned i = 0, e = OuterLoopHeaderBI->getNumSuccessors(); i < e; ++i) {
+ if (OuterLoopHeaderBI->getSuccessor(i) != InnerLoopPreHeader &&
+ OuterLoopHeaderBI->getSuccessor(i) != OuterLoopLatch)
return false;
}
- DEBUG(dbgs() << "Checking instructions in Loop header and Loop latch \n");
+ DEBUG(dbgs() << "Checking instructions in Loop header and Loop latch\n");
// We do not have any basic block in between now make sure the outer header
// and outer loop latch doesn't contain any unsafe instructions.
if (containsUnsafeInstructionsInHeader(OuterLoopHeader) ||
containsUnsafeInstructionsInLatch(OuterLoopLatch))
return false;
- DEBUG(dbgs() << "Loops are perfectly nested \n");
+ DEBUG(dbgs() << "Loops are perfectly nested\n");
// We have a perfect loop nest.
return true;
}
}
bool LoopInterchangeTransform::transform() {
-
- DEBUG(dbgs() << "transform\n");
bool Transformed = false;
Instruction *InnerIndexVar;
// incremented/decremented.
// TODO: This splitting logic may not work always. Fix this.
splitInnerLoopLatch(InnerIndexVar);
- DEBUG(dbgs() << "splitInnerLoopLatch Done\n");
+ DEBUG(dbgs() << "splitInnerLoopLatch done\n");
// Splits the inner loops phi nodes out into a separate basic block.
splitInnerLoopHeader();
- DEBUG(dbgs() << "splitInnerLoopHeader Done\n");
+ DEBUG(dbgs() << "splitInnerLoopHeader done\n");
}
Transformed |= adjustLoopLinks();
if (!Transformed) {
- DEBUG(dbgs() << "adjustLoopLinks Failed\n");
+ DEBUG(dbgs() << "adjustLoopLinks failed\n");
return false;
}
}
DEBUG(dbgs() << "Output of splitInnerLoopHeader InnerLoopHeaderSucc & "
- "InnerLoopHeader \n");
+ "InnerLoopHeader\n");
}
/// \brief Move all instructions except the terminator from FromBB right before