Skip to content

Commit 70ea57b

Browse files
authored
Rollup merge of rust-lang#62063 - ecstatic-morse:dataflow-backward-order, r=nagisa
Use a more efficient iteration order for backward dataflow This applies the same basic principle as rust-lang#62062 to the reverse dataflow analysis used to compute liveness information. It is functionally equivalent, except that post-order is used instead of reverse post-order. In the long-term, `BitDenotation` should probably be extended to support both forward and backward dataflow, but there's some more work needed to get to that point.
2 parents 543c464 + e2479e2 commit 70ea57b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/librustc_mir/util/liveness.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,24 @@ pub fn liveness_of_locals<'tcx>(
7575

7676
let mut bits = LiveVarSet::new_empty(num_live_vars);
7777

78-
// queue of things that need to be re-processed, and a set containing
79-
// the things currently in the queue
80-
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_all(body.basic_blocks().len());
78+
// The dirty queue contains the set of basic blocks whose entry sets have changed since they
79+
// were last processed. At the start of the analysis, we initialize the queue in post-order to
80+
// make it more likely that the entry set for a given basic block will have the effects of all
81+
// its successors in the CFG applied before it is processed.
82+
//
83+
// FIXME(ecstaticmorse): Reverse post-order on the reverse CFG may generate a better iteration
84+
// order when cycles are present, but the overhead of computing the reverse CFG may outweigh
85+
// any benefits. Benchmark this and find out.
86+
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks().len());
87+
for (bb, _) in traversal::postorder(body) {
88+
dirty_queue.insert(bb);
89+
}
90+
91+
// Add blocks which are not reachable from START_BLOCK to the work queue. These blocks will
92+
// be processed after the ones added above.
93+
for bb in body.basic_blocks().indices() {
94+
dirty_queue.insert(bb);
95+
}
8196

8297
let predecessors = body.predecessors();
8398

0 commit comments

Comments
 (0)