Skip to content

Commit

Permalink
iterate_to_fixpoint -> iterate_reachable_to_fixpoint
Browse files Browse the repository at this point in the history
* Renames `iterate_to_fixpoint` to `iterate_reachable_to_fixpoint`.
* Adds to `framework::Enginge` a new method with the old name
  (`iterate_to_fixpoint`). The new method computes the fixpoint over
  all basic blocks, instead of just the reachable ones.
* Changes one occurrence of `iterate_to_fixpoint` to
  `iterate_reachable_to_fixpoint` where the analysis seemed to care
  about only reachable basic blocks.
  • Loading branch information
smoelius committed Mar 3, 2022
1 parent 8769f4e commit 8b67c5e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
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);
});

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

0 comments on commit 8b67c5e

Please sign in to comment.