@@ -673,6 +673,18 @@ struct SemanticARCOptVisitor
673
673
eraseInstruction (i);
674
674
}
675
675
676
+ // / Pop values off of visitedSinceLastMutation, adding .some values to the
677
+ // / worklist.
678
+ void drainVisitedSinceLastMutationIntoWorklist () {
679
+ while (!visitedSinceLastMutation.empty ()) {
680
+ Optional<SILValue> nextValue = visitedSinceLastMutation.pop_back_val ();
681
+ if (!nextValue.hasValue ()) {
682
+ continue ;
683
+ }
684
+ worklist.insert (*nextValue);
685
+ }
686
+ }
687
+
676
688
// / Remove all results of the given instruction from the worklist and then
677
689
// / erase the instruction. Assumes that the instruction does not have any
678
690
// / users left.
@@ -686,13 +698,7 @@ struct SemanticARCOptVisitor
686
698
i->eraseFromParent ();
687
699
688
700
// Add everything else from visitedSinceLastMutation to the worklist.
689
- for (auto opt : visitedSinceLastMutation) {
690
- if (!opt.hasValue ()) {
691
- continue ;
692
- }
693
- worklist.insert (*opt);
694
- }
695
- visitedSinceLastMutation.clear ();
701
+ drainVisitedSinceLastMutationIntoWorklist ();
696
702
}
697
703
698
704
InstModCallbacks getCallbacks () {
@@ -998,14 +1004,9 @@ bool SemanticARCOptVisitor::optimize() {
998
1004
assumingAtFixedPoint = true ;
999
1005
SWIFT_DEFER { assumingAtFixedPoint = false ; };
1000
1006
1001
- // Add everything in visitedSinceLastMutation to the worklist.
1002
- for (auto opt : visitedSinceLastMutation) {
1003
- if (!opt.hasValue ()) {
1004
- continue ;
1005
- }
1006
- worklist.insert (*opt);
1007
- }
1008
- visitedSinceLastMutation.clear ();
1007
+ // Add everything in visitedSinceLastMutation to the worklist so we
1008
+ // recompute our fixed point.
1009
+ drainVisitedSinceLastMutationIntoWorklist ();
1009
1010
1010
1011
// Then re-run the worklist. We shouldn't modify anything since we are at a
1011
1012
// fixed point and are just using this to seed the
0 commit comments