Improve domtree as per @Amanieu's feedback.
This commit is contained in:
@@ -85,16 +85,13 @@ fn check_idom_violations(idom: &[Block], path: &Path) {
|
|||||||
let mut parent = idom[block.index()];
|
let mut parent = idom[block.index()];
|
||||||
let mut domset = HashSet::new();
|
let mut domset = HashSet::new();
|
||||||
domset.insert(*block);
|
domset.insert(*block);
|
||||||
loop {
|
while parent.is_valid() {
|
||||||
assert!(parent.is_valid());
|
|
||||||
assert!(visited.contains(&parent));
|
assert!(visited.contains(&parent));
|
||||||
domset.insert(parent);
|
domset.insert(parent);
|
||||||
let next = idom[parent.index()];
|
let next = idom[parent.index()];
|
||||||
if next == parent {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
parent = next;
|
parent = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that `dominates()` returns true for every block in domset,
|
// Check that `dominates()` returns true for every block in domset,
|
||||||
// and false for every other block.
|
// and false for every other block.
|
||||||
for domblock in 0..idom.len() {
|
for domblock in 0..idom.len() {
|
||||||
|
|||||||
@@ -98,6 +98,10 @@ pub fn calculate<'a, PredFn: Fn(Block) -> &'a [Block]>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now set the start node's dominator-tree parent to "invalid";
|
||||||
|
// this allows the loop in `dominates` to terminate.
|
||||||
|
idom[start.index()] = Block::invalid();
|
||||||
|
|
||||||
idom
|
idom
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +113,6 @@ pub fn dominates(idom: &[Block], a: Block, mut b: Block) -> bool {
|
|||||||
if b.is_invalid() {
|
if b.is_invalid() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let parent = idom[b.index()];
|
|
||||||
if b == parent {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
b = idom[b.index()];
|
b = idom[b.index()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user