Skip to content
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

iterate_to_fixpoint -> iterate_reachable_to_fixpoint #94576

Closed
Closed
Show file tree
Hide file tree
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
52 changes: 38 additions & 14 deletions compiler/rustc_mir_dataflow/src/framework/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,37 +181,61 @@ where
self
}

/// Computes the fixpoint for this dataflow problem and returns it.
/// Computes the fixpoint for this dataflow problem over all basic blocks and returns the
/// fixpoint.
pub fn iterate_to_fixpoint(self) -> Results<'tcx, A>
where
A::Domain: DebugWithContext<A>,
{
let Engine {
analysis,
body,
dead_unwinds,
mut entry_sets,
tcx,
apply_trans_for_block,
pass_name,
..
} = self;
let mut dirty_queue: WorkQueue<BasicBlock> =
WorkQueue::with_none(self.body.basic_blocks().len());

self.body.basic_blocks().indices().for_each(|bb| {
dirty_queue.insert(bb);
});
Comment on lines +190 to +195
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order in which blocks are added to the work queue is significant. I suspect this will hurt performance. It would be kind of fun to check though, since the basic block numbering is usually fairly close to RPO due to how we build MIR.


self.iterate_to_fixpoint_inner(dirty_queue)
}

/// Computes the fixpoint for this dataflow problem over the reachable basic blocks and returns
/// the fixpoint.
pub fn iterate_reachable_to_fixpoint(self) -> Results<'tcx, A>
where
A::Domain: DebugWithContext<A>,
{
let mut dirty_queue: WorkQueue<BasicBlock> =
WorkQueue::with_none(body.basic_blocks().len());
WorkQueue::with_none(self.body.basic_blocks().len());

if A::Direction::is_forward() {
for (bb, _) in traversal::reverse_postorder(body) {
for (bb, _) in traversal::reverse_postorder(self.body) {
dirty_queue.insert(bb);
}
} else {
// Reverse post-order on the reverse CFG may generate a better iteration order for
// backward dataflow analyses, but probably not enough to matter.
for (bb, _) in traversal::postorder(body) {
for (bb, _) in traversal::postorder(self.body) {
dirty_queue.insert(bb);
}
}

self.iterate_to_fixpoint_inner(dirty_queue)
}

fn iterate_to_fixpoint_inner(self, mut dirty_queue: WorkQueue<BasicBlock>) -> Results<'tcx, A>
where
A::Domain: DebugWithContext<A>,
{
let Engine {
analysis,
body,
dead_unwinds,
mut entry_sets,
tcx,
apply_trans_for_block,
pass_name,
..
} = self;

// `state` is not actually used between iterations;
// this is just an optimization to avoid reallocating
// every iteration.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ fn locals_live_across_suspend_points<'tcx>(
// for.
let requires_storage_results = MaybeRequiresStorage::new(body, &borrowed_locals_results)
.into_engine(tcx, body_ref)
.iterate_to_fixpoint();
.iterate_reachable_to_fixpoint();
let mut requires_storage_cursor =
rustc_mir_dataflow::ResultsCursor::new(body_ref, &requires_storage_results);

Expand Down