Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Show First 20 Lines • Show All 823 Lines • ▼ Show 20 Lines | ORE->emit([&]() { | ||||
return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIOuter", | return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIOuter", | ||||
OuterLoop->getStartLoc(), | OuterLoop->getStartLoc(), | ||||
OuterLoop->getHeader()) | OuterLoop->getHeader()) | ||||
<< "Only outer loops with induction or reduction PHI nodes can be" | << "Only outer loops with induction or reduction PHI nodes can be" | ||||
" interchanged currently."; | " interchanged currently."; | ||||
}); | }); | ||||
return true; | return true; | ||||
} | } | ||||
// TODO: Currently we handle only loops with 1 induction variable. | |||||
if (Inductions.size() != 1) { | |||||
LLVM_DEBUG(dbgs() << "Loops with more than 1 induction variables are not " | |||||
<< "supported currently.\n"); | |||||
ORE->emit([&]() { | |||||
return OptimizationRemarkMissed(DEBUG_TYPE, "MultiIndutionOuter", | |||||
OuterLoop->getStartLoc(), | |||||
OuterLoop->getHeader()) | |||||
<< "Only outer loops with 1 induction variable can be " | |||||
"interchanged currently."; | |||||
}); | |||||
return true; | |||||
} | |||||
Inductions.clear(); | Inductions.clear(); | ||||
bmahjour: this imposes an ordering constraint...the OuterLoopInduction member variable is invalid until… | |||||
if (!findInductionAndReductions(InnerLoop, Inductions, nullptr)) { | if (!findInductionAndReductions(InnerLoop, Inductions, nullptr)) { | ||||
LLVM_DEBUG( | LLVM_DEBUG( | ||||
dbgs() << "Only inner loops with induction or reduction PHI nodes " | dbgs() << "Only inner loops with induction or reduction PHI nodes " | ||||
<< "are supported currently.\n"); | << "are supported currently.\n"); | ||||
ORE->emit([&]() { | ORE->emit([&]() { | ||||
return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIInner", | return OptimizationRemarkMissed(DEBUG_TYPE, "UnsupportedPHIInner", | ||||
InnerLoop->getStartLoc(), | InnerLoop->getStartLoc(), | ||||
InnerLoop->getHeader()) | InnerLoop->getHeader()) | ||||
▲ Show 20 Lines • Show All 751 Lines • ▼ Show 20 Lines | bool LoopInterchangeTransform::adjustLoopBranches() { | ||||
if (InnerLoopLatchBI->getSuccessor(0) == InnerLoopHeader) | if (InnerLoopLatchBI->getSuccessor(0) == InnerLoopHeader) | ||||
InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(1); | InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(1); | ||||
else | else | ||||
InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(0); | InnerLoopLatchSuccessor = InnerLoopLatchBI->getSuccessor(0); | ||||
updateSuccessor(InnerLoopLatchPredecessorBI, InnerLoopLatch, | updateSuccessor(InnerLoopLatchPredecessorBI, InnerLoopLatch, | ||||
InnerLoopLatchSuccessor, DTUpdates); | InnerLoopLatchSuccessor, DTUpdates); | ||||
if (OuterLoopLatchBI->getSuccessor(0) == OuterLoopHeader) | if (OuterLoopLatchBI->getSuccessor(0) == OuterLoopHeader) | ||||
OuterLoopLatchSuccessor = OuterLoopLatchBI->getSuccessor(1); | OuterLoopLatchSuccessor = OuterLoopLatchBI->getSuccessor(1); | ||||
else | else | ||||
OuterLoopLatchSuccessor = OuterLoopLatchBI->getSuccessor(0); | OuterLoopLatchSuccessor = OuterLoopLatchBI->getSuccessor(0); | ||||
updateSuccessor(InnerLoopLatchBI, InnerLoopLatchSuccessor, | updateSuccessor(InnerLoopLatchBI, InnerLoopLatchSuccessor, | ||||
OuterLoopLatchSuccessor, DTUpdates); | OuterLoopLatchSuccessor, DTUpdates); | ||||
updateSuccessor(OuterLoopLatchBI, OuterLoopLatchSuccessor, InnerLoopLatch, | updateSuccessor(OuterLoopLatchBI, OuterLoopLatchSuccessor, InnerLoopLatch, | ||||
Show All 13 Lines | bool LoopInterchangeTransform::adjustLoopBranches() { | ||||
auto &OuterInnerReductions = LIL.getOuterInnerReductions(); | auto &OuterInnerReductions = LIL.getOuterInnerReductions(); | ||||
// Now update the reduction PHIs in the inner and outer loop headers. | // Now update the reduction PHIs in the inner and outer loop headers. | ||||
SmallVector<PHINode *, 4> InnerLoopPHIs, OuterLoopPHIs; | SmallVector<PHINode *, 4> InnerLoopPHIs, OuterLoopPHIs; | ||||
for (PHINode &PHI : InnerLoopHeader->phis()) | for (PHINode &PHI : InnerLoopHeader->phis()) | ||||
if (OuterInnerReductions.contains(&PHI)) | if (OuterInnerReductions.contains(&PHI)) | ||||
InnerLoopPHIs.push_back(cast<PHINode>(&PHI)); | InnerLoopPHIs.push_back(cast<PHINode>(&PHI)); | ||||
for (PHINode &PHI : OuterLoopHeader->phis()) | for (PHINode &PHI : OuterLoopHeader->phis()) | ||||
if (OuterInnerReductions.contains(&PHI)) | if (OuterInnerReductions.contains(&PHI)) | ||||
OuterLoopPHIs.push_back(cast<PHINode>(&PHI)); | OuterLoopPHIs.push_back(&PHI); | ||||
// Now move the remaining reduction PHIs from outer to inner loop header and | // Now move the remaining reduction PHIs from outer to inner loop header and | ||||
// vice versa. The PHI nodes must be part of a reduction across the inner and | // vice versa. The PHI nodes must be part of a reduction across the inner and | ||||
// outer loop and all the remains to do is and updating the incoming blocks. | // outer loop and all the remains to do is and updating the incoming blocks. | ||||
for (PHINode *PHI : OuterLoopPHIs) { | for (PHINode *PHI : OuterLoopPHIs) { | ||||
LLVM_DEBUG(dbgs() << "Outer loop reduction PHIs:\n"; PHI->dump();); | |||||
PHI->moveBefore(InnerLoopHeader->getFirstNonPHI()); | PHI->moveBefore(InnerLoopHeader->getFirstNonPHI()); | ||||
assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); | assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); | ||||
} | } | ||||
for (PHINode *PHI : InnerLoopPHIs) { | for (PHINode *PHI : InnerLoopPHIs) { | ||||
PHI->moveBefore(OuterLoopHeader->getFirstNonPHI()); | PHI->moveBefore(OuterLoopHeader->getFirstNonPHI()); | ||||
assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); | assert(OuterInnerReductions.count(PHI) && "Expected a reduction PHI node"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
this imposes an ordering constraint...the OuterLoopInduction member variable is invalid until we get here. It would be cleaner to introduce an initialization step before calling either urrentLimitations() or adjustLoopBranches().