@@ -737,7 +737,7 @@ TargetTransformInfo::PeelingPreferences llvm::gatherPeelingPreferences(
737
737
// / for the bulk of dynamic execution, can be further simplified by scalar
738
738
// / optimizations.
739
739
bool llvm::peelLoop (Loop *L, unsigned PeelCount, LoopInfo *LI,
740
- ScalarEvolution *SE, DominatorTree * DT, AssumptionCache *AC,
740
+ ScalarEvolution *SE, DominatorTree & DT, AssumptionCache *AC,
741
741
bool PreserveLCSSA) {
742
742
assert (PeelCount > 0 && " Attempt to peel out zero iterations?" );
743
743
assert (canPeel (L) && " Attempt to peel a loop which is not peelable?" );
@@ -756,23 +756,21 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
756
756
// routes which can lead to the exit: we can reach it from the peeled
757
757
// iterations too.
758
758
DenseMap<BasicBlock *, BasicBlock *> NonLoopBlocksIDom;
759
- if (DT) {
760
- for (auto *BB : L->blocks ()) {
761
- auto *BBDomNode = DT->getNode (BB);
762
- SmallVector<BasicBlock *, 16 > ChildrenToUpdate;
763
- for (auto *ChildDomNode : BBDomNode->children ()) {
764
- auto *ChildBB = ChildDomNode->getBlock ();
765
- if (!L->contains (ChildBB))
766
- ChildrenToUpdate.push_back (ChildBB);
767
- }
768
- // The new idom of the block will be the nearest common dominator
769
- // of all copies of the previous idom. This is equivalent to the
770
- // nearest common dominator of the previous idom and the first latch,
771
- // which dominates all copies of the previous idom.
772
- BasicBlock *NewIDom = DT->findNearestCommonDominator (BB, Latch);
773
- for (auto *ChildBB : ChildrenToUpdate)
774
- NonLoopBlocksIDom[ChildBB] = NewIDom;
759
+ for (auto *BB : L->blocks ()) {
760
+ auto *BBDomNode = DT.getNode (BB);
761
+ SmallVector<BasicBlock *, 16 > ChildrenToUpdate;
762
+ for (auto *ChildDomNode : BBDomNode->children ()) {
763
+ auto *ChildBB = ChildDomNode->getBlock ();
764
+ if (!L->contains (ChildBB))
765
+ ChildrenToUpdate.push_back (ChildBB);
775
766
}
767
+ // The new idom of the block will be the nearest common dominator
768
+ // of all copies of the previous idom. This is equivalent to the
769
+ // nearest common dominator of the previous idom and the first latch,
770
+ // which dominates all copies of the previous idom.
771
+ BasicBlock *NewIDom = DT.findNearestCommonDominator (BB, Latch);
772
+ for (auto *ChildBB : ChildrenToUpdate)
773
+ NonLoopBlocksIDom[ChildBB] = NewIDom;
776
774
}
777
775
778
776
Function *F = Header->getParent ();
@@ -822,11 +820,11 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
822
820
// If (cond) goto Header
823
821
// Exit:
824
822
825
- BasicBlock *InsertTop = SplitEdge (PreHeader, Header, DT, LI);
823
+ BasicBlock *InsertTop = SplitEdge (PreHeader, Header, & DT, LI);
826
824
BasicBlock *InsertBot =
827
- SplitBlock (InsertTop, InsertTop->getTerminator (), DT, LI);
825
+ SplitBlock (InsertTop, InsertTop->getTerminator (), & DT, LI);
828
826
BasicBlock *NewPreHeader =
829
- SplitBlock (InsertBot, InsertBot->getTerminator (), DT, LI);
827
+ SplitBlock (InsertBot, InsertBot->getTerminator (), & DT, LI);
830
828
831
829
InsertTop->setName (Header->getName () + " .peel.begin" );
832
830
InsertBot->setName (Header->getName () + " .peel.next" );
@@ -852,23 +850,21 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
852
850
ValueToValueMapTy VMap;
853
851
854
852
cloneLoopBlocks (L, Iter, InsertTop, InsertBot, ExitEdges, NewBlocks,
855
- LoopBlocks, VMap, LVMap, DT, LI,
853
+ LoopBlocks, VMap, LVMap, & DT, LI,
856
854
LoopLocalNoAliasDeclScopes);
857
855
858
856
// Remap to use values from the current iteration instead of the
859
857
// previous one.
860
858
remapInstructionsInBlocks (NewBlocks, VMap);
861
859
862
- if (DT) {
863
- // Update IDoms of the blocks reachable through exits.
864
- if (Iter == 0 )
865
- for (auto BBIDom : NonLoopBlocksIDom)
866
- DT->changeImmediateDominator (BBIDom.first ,
867
- cast<BasicBlock>(LVMap[BBIDom.second ]));
860
+ // Update IDoms of the blocks reachable through exits.
861
+ if (Iter == 0 )
862
+ for (auto BBIDom : NonLoopBlocksIDom)
863
+ DT.changeImmediateDominator (BBIDom.first ,
864
+ cast<BasicBlock>(LVMap[BBIDom.second ]));
868
865
#ifdef EXPENSIVE_CHECKS
869
- assert (DT-> verify (DominatorTree::VerificationLevel::Fast));
866
+ assert (DT. verify (DominatorTree::VerificationLevel::Fast));
870
867
#endif
871
- }
872
868
873
869
auto *LatchBRCopy = cast<BranchInst>(VMap[LatchBR]);
874
870
updateBranchWeights (InsertBot, LatchBRCopy, ExitWeight, FallThroughWeight);
@@ -877,7 +873,7 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
877
873
LatchBRCopy->setMetadata (LLVMContext::MD_loop, nullptr );
878
874
879
875
InsertTop = InsertBot;
880
- InsertBot = SplitBlock (InsertBot, InsertBot->getTerminator (), DT, LI);
876
+ InsertBot = SplitBlock (InsertBot, InsertBot->getTerminator (), & DT, LI);
881
877
InsertBot->setName (Header->getName () + " .peel.next" );
882
878
883
879
F->getBasicBlockList ().splice (InsertTop->getIterator (),
@@ -912,10 +908,10 @@ bool llvm::peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI,
912
908
SE->forgetTopmostLoop (L);
913
909
914
910
// Finally DomtTree must be correct.
915
- assert (DT-> verify (DominatorTree::VerificationLevel::Fast));
911
+ assert (DT. verify (DominatorTree::VerificationLevel::Fast));
916
912
917
913
// FIXME: Incrementally update loop-simplify
918
- simplifyLoop (L, DT, LI, SE, AC, nullptr , PreserveLCSSA);
914
+ simplifyLoop (L, & DT, LI, SE, AC, nullptr , PreserveLCSSA);
919
915
920
916
NumPeeled++;
921
917
0 commit comments