Skip to content

Commit

Permalink
Rollup merge of rust-lang#62063 - ecstatic-morse:dataflow-backward-or…
Browse files Browse the repository at this point in the history
…der, 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.
  • Loading branch information
Centril authored Jun 30, 2019
2 parents 543c464 + e2479e2 commit 70ea57b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/librustc_mir/util/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,24 @@ pub fn liveness_of_locals<'tcx>(

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

// queue of things that need to be re-processed, and a set containing
// the things currently in the queue
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_all(body.basic_blocks().len());
// The dirty queue contains the set of basic blocks whose entry sets have changed since they
// were last processed. At the start of the analysis, we initialize the queue in post-order to
// make it more likely that the entry set for a given basic block will have the effects of all
// its successors in the CFG applied before it is processed.
//
// FIXME(ecstaticmorse): Reverse post-order on the reverse CFG may generate a better iteration
// order when cycles are present, but the overhead of computing the reverse CFG may outweigh
// any benefits. Benchmark this and find out.
let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks().len());
for (bb, _) in traversal::postorder(body) {
dirty_queue.insert(bb);
}

// Add blocks which are not reachable from START_BLOCK to the work queue. These blocks will
// be processed after the ones added above.
for bb in body.basic_blocks().indices() {
dirty_queue.insert(bb);
}

let predecessors = body.predecessors();

Expand Down

0 comments on commit 70ea57b

Please sign in to comment.