Skip to content

adding extra dominators #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions analyze/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ pub fn top(items: &mut ir::Items, opts: &opt::Top) -> Result<Box<traits::Emit>,

struct DominatorTree {
tree: BTreeMap<ir::Id, Vec<ir::Id>>,
opts: opt::Dominators,
}

impl traits::Emit for DominatorTree {
Expand All @@ -212,15 +213,33 @@ impl traits::Emit for DominatorTree {
(Align::Left, "Dominator Tree".to_string()),
]);

let opts = &self.opts;

let mut row = 0 as usize;

fn recursive_add_rows(
table: &mut Table,
items: &ir::Items,
dominator_tree: &BTreeMap<ir::Id, Vec<ir::Id>>,
depth: usize,
mut row: &mut usize,
opts: &opt::Dominators,
id: ir::Id,
) {
assert_eq!(id == items.meta_root(), depth == 0);

if let Some(max_rows) = opts.max_rows {
if *row == max_rows {
return;
}
}

if let Some(max_depth) = opts.max_depth {
if depth > max_depth {
return;
}
}

if depth > 0 {
let item = &items[id];

Expand Down Expand Up @@ -248,12 +267,29 @@ impl traits::Emit for DominatorTree {
children
.sort_unstable_by(|a, b| items.retained_size(*b).cmp(&items.retained_size(*a)));
for child in children {
recursive_add_rows(table, items, dominator_tree, depth + 1, child);
*row += 1;
recursive_add_rows(
table,
items,
dominator_tree,
depth + 1,
&mut row,
&opts,
child,
);
}
}
}

recursive_add_rows(&mut table, items, &self.tree, 0, items.meta_root());
recursive_add_rows(
&mut table,
items,
&self.tree,
0,
&mut row,
&opts,
items.meta_root(),
);
write!(&mut dest, "{}", &table)?;
Ok(())
}
Expand All @@ -262,13 +298,14 @@ impl traits::Emit for DominatorTree {
/// Compute the dominator tree for the given IR graph.
pub fn dominators(
items: &mut ir::Items,
_opts: &opt::Dominators,
opts: &opt::Dominators,
) -> Result<Box<traits::Emit>, failure::Error> {
items.compute_dominator_tree();
items.compute_retained_sizes();

let tree = DominatorTree {
tree: items.dominator_tree().clone(),
opts: opts.clone(),
};

Ok(Box::new(tree) as Box<traits::Emit>)
Expand Down
8 changes: 8 additions & 0 deletions opt/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ pub struct Dominators {
/// The format the output should be written in.
#[structopt(short = "f", long = "format", default_value = "text")]
pub output_format: OutputFormat,

/// The maximum depth to print the dominators tree.
#[structopt(short = "d")]
pub max_depth: Option<usize>,

/// The maximum number of rows, regardless of depth in the tree, to display.
#[structopt(short = "r")]
pub max_rows: Option<usize>,
}

impl CommonOptions for Dominators {
Expand Down
10 changes: 10 additions & 0 deletions svelte/tests/expectations/dominators_wee_alloc_with_depth_and_row
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Retained Bytes │ Retained % │ Dominator Tree
────────────────┼────────────┼────────────────────────────
774 ┊ 27.48% ┊ "function names" subsection
564 ┊ 20.02% ┊ export "hello"
59 ┊ 2.09% ┊ export "goodbye"
49 ┊ 1.74% ┊ ⤷ func[9]
44 ┊ 1.56% ┊ ⤷ goodbye
4 ┊ 0.14% ┊ ⤷ type[3]
11 ┊ 0.39% ┊ export "memory"
2 ┊ 0.07% ┊ ⤷ memory[0]
10 changes: 10 additions & 0 deletions svelte/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ test!(
"./fixtures/wee_alloc.wasm"
);

test!(
dominators_wee_alloc_with_depth_and_row,
"dominators",
"./fixtures/wee_alloc.wasm",
"-d",
"5",
"-r",
"3"
);

test!(
paths_wee_alloc,
"paths",
Expand Down