Skip to content

Commit 37d3588

Browse files
authored
Merge pull request #19 from sendilkumarn/adding-dominators
adding extra dominators
2 parents 4a6494c + 85e7ab8 commit 37d3588

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

β€Žanalyze/analyze.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ pub fn top(items: &mut ir::Items, opts: &opt::Top) -> Result<Box<traits::Emit>,
196196

197197
struct DominatorTree {
198198
tree: BTreeMap<ir::Id, Vec<ir::Id>>,
199+
opts: opt::Dominators,
199200
}
200201

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

216+
let opts = &self.opts;
217+
218+
let mut row = 0 as usize;
219+
215220
fn recursive_add_rows(
216221
table: &mut Table,
217222
items: &ir::Items,
218223
dominator_tree: &BTreeMap<ir::Id, Vec<ir::Id>>,
219224
depth: usize,
225+
mut row: &mut usize,
226+
opts: &opt::Dominators,
220227
id: ir::Id,
221228
) {
222229
assert_eq!(id == items.meta_root(), depth == 0);
223230

231+
if let Some(max_rows) = opts.max_rows {
232+
if *row == max_rows {
233+
return;
234+
}
235+
}
236+
237+
if let Some(max_depth) = opts.max_depth {
238+
if depth > max_depth {
239+
return;
240+
}
241+
}
242+
224243
if depth > 0 {
225244
let item = &items[id];
226245

@@ -248,12 +267,29 @@ impl traits::Emit for DominatorTree {
248267
children
249268
.sort_unstable_by(|a, b| items.retained_size(*b).cmp(&items.retained_size(*a)));
250269
for child in children {
251-
recursive_add_rows(table, items, dominator_tree, depth + 1, child);
270+
*row += 1;
271+
recursive_add_rows(
272+
table,
273+
items,
274+
dominator_tree,
275+
depth + 1,
276+
&mut row,
277+
&opts,
278+
child,
279+
);
252280
}
253281
}
254282
}
255283

256-
recursive_add_rows(&mut table, items, &self.tree, 0, items.meta_root());
284+
recursive_add_rows(
285+
&mut table,
286+
items,
287+
&self.tree,
288+
0,
289+
&mut row,
290+
&opts,
291+
items.meta_root(),
292+
);
257293
write!(&mut dest, "{}", &table)?;
258294
Ok(())
259295
}
@@ -262,13 +298,14 @@ impl traits::Emit for DominatorTree {
262298
/// Compute the dominator tree for the given IR graph.
263299
pub fn dominators(
264300
items: &mut ir::Items,
265-
_opts: &opt::Dominators,
301+
opts: &opt::Dominators,
266302
) -> Result<Box<traits::Emit>, failure::Error> {
267303
items.compute_dominator_tree();
268304
items.compute_retained_sizes();
269305

270306
let tree = DominatorTree {
271307
tree: items.dominator_tree().clone(),
308+
opts: opts.clone(),
272309
};
273310

274311
Ok(Box::new(tree) as Box<traits::Emit>)

β€Žopt/opt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ pub struct Dominators {
125125
/// The format the output should be written in.
126126
#[structopt(short = "f", long = "format", default_value = "text")]
127127
pub output_format: OutputFormat,
128+
129+
/// The maximum depth to print the dominators tree.
130+
#[structopt(short = "d")]
131+
pub max_depth: Option<usize>,
132+
133+
/// The maximum number of rows, regardless of depth in the tree, to display.
134+
#[structopt(short = "r")]
135+
pub max_rows: Option<usize>,
128136
}
129137

130138
impl CommonOptions for Dominators {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Retained Bytes β”‚ Retained % β”‚ Dominator Tree
2+
────────────────┼────────────┼────────────────────────────
3+
774 β”Š 27.48% β”Š "function names" subsection
4+
564 β”Š 20.02% β”Š export "hello"
5+
59 β”Š 2.09% β”Š export "goodbye"
6+
49 β”Š 1.74% β”Š β€· func[9]
7+
44 β”Š 1.56% β”Š β€· goodbye
8+
4 β”Š 0.14% β”Š β€· type[3]
9+
11 β”Š 0.39% β”Š export "memory"
10+
2 β”Š 0.07% β”Š β€· memory[0]

β€Žsvelte/tests/tests.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ test!(
105105
"./fixtures/wee_alloc.wasm"
106106
);
107107

108+
test!(
109+
dominators_wee_alloc_with_depth_and_row,
110+
"dominators",
111+
"./fixtures/wee_alloc.wasm",
112+
"-d",
113+
"5",
114+
"-r",
115+
"3"
116+
);
117+
108118
test!(
109119
paths_wee_alloc,
110120
"paths",

0 commit comments

Comments
Β (0)