@@ -582,17 +582,15 @@ struct AllSwitchPaths {
582582 VisitedBlocks VB;
583583 // Get paths from the determinator BBs to SwitchPhiDefBB
584584 std::vector<ThreadingPath> PathsToPhiDef =
585- getPathsFromStateDefMap (StateDef, SwitchPhi, VB, MaxNumPaths );
585+ getPathsFromStateDefMap (StateDef, SwitchPhi, VB);
586586 if (SwitchPhiDefBB == SwitchBlock) {
587587 TPaths = std::move (PathsToPhiDef);
588588 return ;
589589 }
590590
591- assert (MaxNumPaths >= PathsToPhiDef.size ());
592- auto PathsLimit = MaxNumPaths / PathsToPhiDef.size ();
593591 // Find and append paths from SwitchPhiDefBB to SwitchBlock.
594592 PathsType PathsToSwitchBB =
595- paths (SwitchPhiDefBB, SwitchBlock, VB, /* PathDepth = */ 1 , PathsLimit );
593+ paths (SwitchPhiDefBB, SwitchBlock, VB, /* PathDepth = */ 1 );
596594 if (PathsToSwitchBB.empty ())
597595 return ;
598596
@@ -613,16 +611,13 @@ struct AllSwitchPaths {
613611 typedef DenseMap<const BasicBlock *, const PHINode *> StateDefMap;
614612 std::vector<ThreadingPath> getPathsFromStateDefMap (StateDefMap &StateDef,
615613 PHINode *Phi,
616- VisitedBlocks &VB,
617- unsigned PathsLimit) {
614+ VisitedBlocks &VB) {
618615 std::vector<ThreadingPath> Res;
619616 auto *PhiBB = Phi->getParent ();
620617 VB.insert (PhiBB);
621618
622619 VisitedBlocks UniqueBlocks;
623620 for (auto *IncomingBB : Phi->blocks ()) {
624- if (Res.size () >= PathsLimit)
625- break ;
626621 if (!UniqueBlocks.insert (IncomingBB).second )
627622 continue ;
628623 if (!SwitchOuterLoop->contains (IncomingBB))
@@ -658,9 +653,8 @@ struct AllSwitchPaths {
658653
659654 // Direct predecessor, just add to the path.
660655 if (IncomingPhiDefBB == IncomingBB) {
661- assert (PathsLimit > Res.size ());
662- std::vector<ThreadingPath> PredPaths = getPathsFromStateDefMap (
663- StateDef, IncomingPhi, VB, PathsLimit - Res.size ());
656+ std::vector<ThreadingPath> PredPaths =
657+ getPathsFromStateDefMap (StateDef, IncomingPhi, VB);
664658 for (ThreadingPath &Path : PredPaths) {
665659 Path.push_back (PhiBB);
666660 Res.push_back (std::move (Path));
@@ -673,17 +667,13 @@ struct AllSwitchPaths {
673667 continue ;
674668
675669 PathsType IntermediatePaths;
676- assert (PathsLimit > Res.size ());
677- auto InterPathLimit = PathsLimit - Res.size ();
678- IntermediatePaths = paths (IncomingPhiDefBB, IncomingBB, VB,
679- /* PathDepth = */ 1 , InterPathLimit);
670+ IntermediatePaths =
671+ paths (IncomingPhiDefBB, IncomingBB, VB, /* PathDepth = */ 1 );
680672 if (IntermediatePaths.empty ())
681673 continue ;
682674
683- assert (InterPathLimit >= IntermediatePaths.size ());
684- auto PredPathLimit = InterPathLimit / IntermediatePaths.size ();
685675 std::vector<ThreadingPath> PredPaths =
686- getPathsFromStateDefMap (StateDef, IncomingPhi, VB, PredPathLimit );
676+ getPathsFromStateDefMap (StateDef, IncomingPhi, VB);
687677 for (const ThreadingPath &Path : PredPaths) {
688678 for (const PathType &IPath : IntermediatePaths) {
689679 ThreadingPath NewPath (Path);
@@ -698,7 +688,7 @@ struct AllSwitchPaths {
698688 }
699689
700690 PathsType paths (BasicBlock *BB, BasicBlock *ToBB, VisitedBlocks &Visited,
701- unsigned PathDepth, unsigned PathsLimit ) {
691+ unsigned PathDepth) {
702692 PathsType Res;
703693
704694 // Stop exploring paths after visiting MaxPathLength blocks
@@ -725,8 +715,6 @@ struct AllSwitchPaths {
725715 // is used to prevent a duplicate path from being generated
726716 SmallSet<BasicBlock *, 4 > Successors;
727717 for (BasicBlock *Succ : successors (BB)) {
728- if (Res.size () >= PathsLimit)
729- break ;
730718 if (!Successors.insert (Succ).second )
731719 continue ;
732720
@@ -748,12 +736,14 @@ struct AllSwitchPaths {
748736 // coverage and compile time.
749737 if (LI->getLoopFor (Succ) != CurrLoop)
750738 continue ;
751- assert (PathsLimit > Res.size ());
752- PathsType SuccPaths =
753- paths (Succ, ToBB, Visited, PathDepth + 1 , PathsLimit - Res.size ());
739+
740+ PathsType SuccPaths = paths (Succ, ToBB, Visited, PathDepth + 1 );
754741 for (PathType &Path : SuccPaths) {
755742 Path.push_front (BB);
756743 Res.push_back (Path);
744+ if (Res.size () >= MaxNumPaths) {
745+ return Res;
746+ }
757747 }
758748 }
759749 // This block could now be visited again from a different predecessor. Note
0 commit comments