mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
LoopUnroll: Create sub-loops in LoopInfo
`LoopUnrollPass` says that it preserves `LoopInfo` -- make it so. In particular, tell `LoopInfo` about copies of inner loops when unrolling the outer loop. Conservatively, also tell `ScalarEvolution` to forget about the original versions of these loops, since their inputs may have changed. Fixes PR20987. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219241 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -301,13 +301,41 @@ bool llvm::UnrollLoop(Loop *L, unsigned Count, unsigned TripCount,
|
||||
|
||||
for (unsigned It = 1; It != Count; ++It) {
|
||||
std::vector<BasicBlock*> NewBlocks;
|
||||
SmallDenseMap<const Loop *, Loop *, 4> NewLoops;
|
||||
NewLoops[L] = L;
|
||||
|
||||
for (LoopBlocksDFS::RPOIterator BB = BlockBegin; BB != BlockEnd; ++BB) {
|
||||
ValueToValueMapTy VMap;
|
||||
BasicBlock *New = CloneBasicBlock(*BB, VMap, "." + Twine(It));
|
||||
Header->getParent()->getBasicBlockList().push_back(New);
|
||||
|
||||
L->addBasicBlockToLoop(New, LI->getBase());
|
||||
// Tell LI about New.
|
||||
if (*BB == Header) {
|
||||
assert(LI->getLoopFor(*BB) == L && "Header should not be in a sub-loop");
|
||||
L->addBasicBlockToLoop(New, LI->getBase());
|
||||
} else {
|
||||
// Figure out which loop New is in.
|
||||
const Loop *OldLoop = LI->getLoopFor(*BB);
|
||||
assert(OldLoop && "Should (at least) be in the loop being unrolled!");
|
||||
|
||||
Loop *&NewLoop = NewLoops[OldLoop];
|
||||
if (!NewLoop) {
|
||||
// Found a new sub-loop.
|
||||
assert(*BB == OldLoop->getHeader() &&
|
||||
"Header should be first in RPO");
|
||||
|
||||
Loop *NewLoopParent = NewLoops.lookup(OldLoop->getParentLoop());
|
||||
assert(NewLoopParent &&
|
||||
"Expected parent loop before sub-loop in RPO");
|
||||
NewLoop = new Loop;
|
||||
NewLoopParent->addChildLoop(NewLoop);
|
||||
|
||||
// Forget the old loop, since its inputs may have changed.
|
||||
if (SE)
|
||||
SE->forgetLoop(OldLoop);
|
||||
}
|
||||
NewLoop->addBasicBlockToLoop(New, LI->getBase());
|
||||
}
|
||||
|
||||
if (*BB == Header)
|
||||
// Loop over all of the PHI nodes in the block, changing them to use
|
||||
|
Reference in New Issue
Block a user