Skip to content

[semantic-arc-opts] Refactor out reinitializing the worklist into method drainVisitedSinceLastMutationIntoWorklist and add some types/comments. #30320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions lib/SILOptimizer/Transforms/SemanticARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,18 @@ struct SemanticARCOptVisitor
eraseInstruction(i);
}

/// Pop values off of visitedSinceLastMutation, adding .some values to the
/// worklist.
void drainVisitedSinceLastMutationIntoWorklist() {
while (!visitedSinceLastMutation.empty()) {
Optional<SILValue> nextValue = visitedSinceLastMutation.pop_back_val();
if (!nextValue.hasValue()) {
continue;
}
worklist.insert(*nextValue);
}
}

/// Remove all results of the given instruction from the worklist and then
/// erase the instruction. Assumes that the instruction does not have any
/// users left.
Expand All @@ -686,13 +698,7 @@ struct SemanticARCOptVisitor
i->eraseFromParent();

// Add everything else from visitedSinceLastMutation to the worklist.
for (auto opt : visitedSinceLastMutation) {
if (!opt.hasValue()) {
continue;
}
worklist.insert(*opt);
}
visitedSinceLastMutation.clear();
drainVisitedSinceLastMutationIntoWorklist();
}

InstModCallbacks getCallbacks() {
Expand Down Expand Up @@ -999,14 +1005,9 @@ bool SemanticARCOptVisitor::optimize() {
assumingAtFixedPoint = true;
SWIFT_DEFER { assumingAtFixedPoint = false; };

// Add everything in visitedSinceLastMutation to the worklist.
for (auto opt : visitedSinceLastMutation) {
if (!opt.hasValue()) {
continue;
}
worklist.insert(*opt);
}
visitedSinceLastMutation.clear();
// Add everything in visitedSinceLastMutation to the worklist so we
// recompute our fixed point.
drainVisitedSinceLastMutationIntoWorklist();

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