Skip to content

Commit d0d31f7

Browse files
committed
[semantic-arc-opts] Refactor out reinitializing the worklist into method drainVisitedSinceLastMutationIntoWorklist and add some types/comments.
I was doing this in two places. It makes sense to refactor it out as such.
1 parent cee2af0 commit d0d31f7

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

lib/SILOptimizer/Transforms/SemanticARCOpts.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,18 @@ struct SemanticARCOptVisitor
673673
eraseInstruction(i);
674674
}
675675

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+
676688
/// Remove all results of the given instruction from the worklist and then
677689
/// erase the instruction. Assumes that the instruction does not have any
678690
/// users left.
@@ -686,13 +698,7 @@ struct SemanticARCOptVisitor
686698
i->eraseFromParent();
687699

688700
// 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();
696702
}
697703

698704
InstModCallbacks getCallbacks() {
@@ -999,14 +1005,9 @@ bool SemanticARCOptVisitor::optimize() {
9991005
assumingAtFixedPoint = true;
10001006
SWIFT_DEFER { assumingAtFixedPoint = false; };
10011007

1002-
// Add everything in visitedSinceLastMutation to the worklist.
1003-
for (auto opt : visitedSinceLastMutation) {
1004-
if (!opt.hasValue()) {
1005-
continue;
1006-
}
1007-
worklist.insert(*opt);
1008-
}
1009-
visitedSinceLastMutation.clear();
1008+
// Add everything in visitedSinceLastMutation to the worklist so we
1009+
// recompute our fixed point.
1010+
drainVisitedSinceLastMutationIntoWorklist();
10101011

10111012
// Then re-run the worklist. We shouldn't modify anything since we are at a
10121013
// fixed point and are just using this to seed the

0 commit comments

Comments
 (0)