1
Fork 0

execute liveness, write a simple test

This commit is contained in:
Niko Matsakis 2017-10-24 10:42:47 -04:00
parent 6713736275
commit c42a64518a
2 changed files with 72 additions and 3 deletions

View file

@ -21,6 +21,7 @@ use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use syntax_pos::DUMMY_SP;
use std::collections::HashMap;
use std::fmt;
use util::liveness;
use util as mir_util;
use self::mir_util::PassWhere;
@ -151,13 +152,34 @@ impl MirPass for NLL {
tcx.infer_ctxt().enter(|infcx| {
// Clone mir so we can mutate it without disturbing the rest of the compiler
let mut renumbered_mir = mir.clone();
let mut visitor = NLLVisitor::new(&infcx);
visitor.visit_mir(&mut renumbered_mir);
let liveness = liveness::liveness_of_locals(&renumbered_mir);
mir_util::dump_mir(tcx, None, "nll", &0, source, mir, |pass_where, out| {
if let PassWhere::BeforeCFG = pass_where {
for (index, value) in visitor.regions.iter_enumerated() {
writeln!(out, "// R{:03}: {:?}", index.0, value)?;
match pass_where {
// Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => {
for (index, value) in visitor.regions.iter_enumerated() {
writeln!(out, "| R{:03}: {:?}", index.0, value)?;
}
}
// Before each basic block, dump out the values
// that are live on entry to the basic block.
PassWhere::BeforeBlock(bb) => {
let local_set = &liveness.ins[bb];
writeln!(out, " | Variables live on entry to the block {:?}:", bb)?;
for local in local_set.iter() {
writeln!(out, " | - {:?}", local)?;
}
}
PassWhere::InCFG(_) => { }
PassWhere::AfterCFG => { }
}
Ok(())
});

View file

@ -0,0 +1,47 @@
// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags:-Znll
fn cond() -> bool { false }
fn make_live(x: usize) { }
fn make_dead() { }
fn main() {
let x = 5;
if cond() {
make_live(x);
} else {
// x should be dead on entry to this block
make_dead();
}
}
// END RUST SOURCE
// START rustc.node18.nll.0.mir
// | Variables live on entry to the block bb2:
// | - _1
// bb2: {
// StorageLive(_4);
// _4 = _1;
// _3 = const make_live(_4) -> bb4;
// }
// END rustc.node18.nll.0.mir
// START rustc.node18.nll.0.mir
// | Variables live on entry to the block bb3:
// bb3: {
// _5 = const make_dead() -> bb5;
// }
// END rustc.node18.nll.0.mir