diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index e26665e8291..012846c6fa8 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -261,13 +261,6 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( } } - // Before each basic block, dump out the values - // that are live on entry to the basic block. - PassWhere::BeforeBlock(bb) => { - let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]); - writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?; - } - PassWhere::BeforeLocation(location) => { let s = live_variable_set( ®ular_liveness_per_location[&location], @@ -283,7 +276,14 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( )?; } - PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {} + // After each basic block, dump out the values + // that are live on exit from the basic block. + PassWhere::AfterTerminator(bb) => { + let s = live_variable_set(&liveness.regular.outs[bb], &liveness.drop.outs[bb]); + writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?; + } + + PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {} } Ok(()) }, diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 938eb72654a..d4b93b896de 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -56,9 +56,6 @@ pub struct LivenessResult { /// Liveness mode in use when these results were computed. pub mode: LivenessMode, - /// Live variables on entry to each basic block. - pub ins: IndexVec, - /// Live variables on exit to each basic block. This is equal to /// the union of the `ins` for each successor. pub outs: IndexVec, @@ -125,11 +122,10 @@ pub fn liveness_of_locals<'tcx>(mir: &Mir<'tcx>, mode: LivenessMode) -> Liveness .map(|b| block(mode, b, locals)) .collect(); - let mut ins: IndexVec<_, _> = mir.basic_blocks() + let mut outs: IndexVec<_, _> = mir.basic_blocks() .indices() .map(|_| LocalSet::new_empty(locals)) .collect(); - let mut outs = ins.clone(); let mut bits = LocalSet::new_empty(locals); @@ -140,28 +136,21 @@ pub fn liveness_of_locals<'tcx>(mir: &Mir<'tcx>, mode: LivenessMode) -> Liveness let predecessors = mir.predecessors(); while let Some(bb) = dirty_queue.pop() { - // outs[b] = ∪ {ins of successors} - bits.clear(); - for &successor in mir[bb].terminator().successors() { - bits.union(&ins[successor]); - } - outs[bb].overwrite(&bits); - // bits = use ∪ (bits - def) + bits.overwrite(&outs[bb]); def_use[bb].apply(&mut bits); - // update bits on entry and, if they have changed, enqueue all - // of our predecessors, since their inputs have now changed - if ins[bb] != bits { - ins[bb].overwrite(&bits); - - for &pred_bb in &predecessors[bb] { + // add `bits` to the out set for each predecessor; if those + // bits were not already present, then enqueue the predecessor + // as dirty. + for &pred_bb in &predecessors[bb] { + if outs[pred_bb].union(&bits) { dirty_queue.insert(pred_bb); } } } - LivenessResult { mode, ins, outs } + LivenessResult { mode, outs } } impl LivenessResult { @@ -202,8 +191,6 @@ impl LivenessResult { statement_defs_uses.apply(&mut bits); callback(statement_location, &bits); } - - assert_eq!(bits, self.ins[block]); } fn defs_uses<'tcx, V>(&self, mir: &Mir<'tcx>, location: Location, thing: &V) -> DefsUses @@ -445,7 +432,6 @@ pub fn write_mir_fn<'a, 'tcx>( .collect(); writeln!(w, "{} {{{}}}", prefix, live.join(", ")) }; - print(w, " ", &result.ins)?; write_basic_block(tcx, block, mir, &mut |_, _| Ok(()), w)?; print(w, " ", &result.outs)?; if block.index() + 1 != mir.basic_blocks().len() { diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 8176c644dd7..6472e588bc6 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -44,6 +44,9 @@ pub enum PassWhere { /// We just dumped the given statement or terminator. AfterLocation(Location), + + /// We just dumped the terminator for a block but not the closing `}`. + AfterTerminator(BasicBlock), } /// If the session is properly configured, dumps a human-readable @@ -351,6 +354,7 @@ where })?; extra_data(PassWhere::AfterLocation(current_location), w)?; + extra_data(PassWhere::AfterTerminator(block), w)?; writeln!(w, "{}}}", INDENT) }