-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>>, | ||
dominators: opt::Dominators, | ||
} | ||
|
||
impl traits::Emit for DominatorTree { | ||
|
@@ -212,48 +213,70 @@ impl traits::Emit for DominatorTree { | |
(Align::Left, "Dominator Tree".to_string()), | ||
]); | ||
|
||
let dominators = &self.dominators; | ||
|
||
fn recursive_add_rows( | ||
table: &mut Table, | ||
items: &ir::Items, | ||
dominator_tree: &BTreeMap<ir::Id, Vec<ir::Id>>, | ||
depth: usize, | ||
dominators: &opt::Dominators, | ||
id: ir::Id, | ||
) { | ||
assert_eq!(id == items.meta_root(), depth == 0); | ||
|
||
if depth > 0 { | ||
let item = &items[id]; | ||
if dominators.max_row != 0 && depth != dominators.max_depth { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than indenting the whole function inside this
These tweaks should make this functionality a little less invasive |
||
if depth > 0 { | ||
let item = &items[id]; | ||
|
||
let size = items.retained_size(id); | ||
let size_percent = (size as f64) / (items.size() as f64) * 100.0; | ||
let size = items.retained_size(id); | ||
let size_percent = (size as f64) / (items.size() as f64) * 100.0; | ||
|
||
let mut label = String::with_capacity(depth * 4 + item.name().len() + "⤷ ".len()); | ||
for _ in 2..depth { | ||
label.push_str(" "); | ||
} | ||
if depth != 1 { | ||
label.push_str(" ⤷ "); | ||
} | ||
label.push_str(item.name()); | ||
let mut label = | ||
String::with_capacity(depth * 4 + item.name().len() + "⤷ ".len()); | ||
for _ in 2..depth { | ||
label.push_str(" "); | ||
} | ||
if depth != 1 { | ||
label.push_str(" ⤷ "); | ||
} | ||
label.push_str(item.name()); | ||
|
||
table.add_row(vec![ | ||
size.to_string(), | ||
format!("{:.2}%", size_percent), | ||
label, | ||
]); | ||
} | ||
table.add_row(vec![ | ||
size.to_string(), | ||
format!("{:.2}%", size_percent), | ||
label, | ||
]); | ||
} | ||
|
||
if let Some(children) = dominator_tree.get(&id) { | ||
let mut children: Vec<_> = children.iter().cloned().collect(); | ||
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); | ||
if let Some(children) = dominator_tree.get(&id) { | ||
let mut children: Vec<_> = children.iter().cloned().collect(); | ||
children.sort_unstable_by(|a, b| { | ||
items.retained_size(*b).cmp(&items.retained_size(*a)) | ||
}); | ||
for child in children { | ||
// dominators.max_row = &dominators.max_row - 1; | ||
recursive_add_rows( | ||
table, | ||
items, | ||
dominator_tree, | ||
depth + 1, | ||
&dominators, | ||
child, | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
recursive_add_rows(&mut table, items, &self.tree, 0, items.meta_root()); | ||
recursive_add_rows( | ||
&mut table, | ||
items, | ||
&self.tree, | ||
0, | ||
&dominators, | ||
items.meta_root(), | ||
); | ||
write!(&mut dest, "{}", &table)?; | ||
Ok(()) | ||
} | ||
|
@@ -262,13 +285,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(), | ||
dominators: opts.clone(), | ||
}; | ||
|
||
Ok(Box::new(tree) as Box<traits::Emit>) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,10 @@ pub struct Dominators { | |
/// The format the output should be written in. | ||
#[structopt(short = "f", long = "format", default_value = "text")] | ||
pub output_format: OutputFormat, | ||
|
||
#[structopt(short = "d", default_value = "10")] pub max_depth: usize, | ||
|
||
#[structopt(short = "r", default_value = "10")] pub max_row: usize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NItpick: Let's also add doc comments to each new field, since this will turn into the CLI help text:
Let's also make these |
||
} | ||
|
||
impl CommonOptions for Dominators { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Retained Bytes │ Retained % │ Dominator Tree | ||
────────────────┼────────────┼──────────────────────────── | ||
774 ┊ 27.48% ┊ "function names" subsection | ||
564 ┊ 20.02% ┊ export "hello" | ||
556 ┊ 19.74% ┊ ⤷ func[8] | ||
551 ┊ 19.56% ┊ ⤷ hello | ||
387 ┊ 13.74% ┊ ⤷ func[2] | ||
4 ┊ 0.14% ┊ ⤷ type[5] | ||
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: let's rename this field to
opts