Avoid the CFG get_successors() when computing a post-order.

The control flow graph does not guarantee any particular ordering for
its successor lists, and the post-order we are computing for building
the dominator tree needs to be "split-invariant".

See #146 for details.

- Discover EBB successors directly from the EBB instruction sequence to
  guarantee that the post-order we compute is canonical/split-invariant.
- Use an alternative graph DFS algorithm which doesn't require indexing
  into a slice of successors.

This changes cfg_postorder in some cases because the edge pruning when
converting the (DAG) CFG to a tree for the DFT is different.
This commit is contained in:
Jakob Stoklund Olesen
2017-11-21 09:45:52 -08:00
parent 2e0b931590
commit cf45afa1e7
3 changed files with 206 additions and 31 deletions

View File

@@ -26,6 +26,30 @@ fn test_reverse_postorder_traversal(function_source: &str, ebb_order: Vec<u32>)
#[test]
fn simple_traversal() {
// Fall-through-first, prune-at-source DFT:
//
// ebb0 {
// ebb0:brz v0, ebb1 {
// ebb0:jump ebb2 {
// ebb2 {
// ebb2:brz v2, ebb2 -
// ebb2:brz v3, ebb1 -
// ebb2:brz v4, ebb4 {
// ebb2: jump ebb5 {
// ebb5 {}
// }
// ebb4 {}
// }
// } ebb2
// }
// ebb1 {
// ebb1:jump ebb3 {
// ebb3 {}
// }
// } ebb1
// }
// } ebb0
test_reverse_postorder_traversal(
"
function %test(i32) native {
@@ -51,12 +75,28 @@ fn simple_traversal() {
trap user0
}
",
vec![0, 2, 5, 4, 1, 3],
vec![0, 1, 3, 2, 4, 5],
);
}
#[test]
fn loops_one() {
// Fall-through-first, prune-at-source DFT:
// ebb0 {
// ebb0:jump ebb1 {
// ebb1 {
// ebb1:brnz v0, ebb3 {
// ebb1:jump ebb2 {
// ebb2 {
// ebb2:jump ebb3 -
// } ebb2
// }
// ebb3 {}
// }
// } ebb1
// }
// } ebb0
test_reverse_postorder_traversal(
"
function %test(i32) native {
@@ -71,12 +111,40 @@ fn loops_one() {
return
}
",
vec![0, 1, 2, 3],
vec![0, 1, 3, 2],
);
}
#[test]
fn loops_two() {
// Fall-through-first, prune-at-source DFT:
// ebb0 {
// ebb0:brz v0, ebb1 {
// ebb0:jump ebb2 {
// ebb2 {
// ebb2:brz v0, ebb4 {
// ebb2:jump ebb5 {
// ebb5 {
// brz v0, ebb4 -
// } ebb5
// }
// ebb4 {
// ebb4:brz v0, ebb3 {
// ebb4:jump ebb5 -
// ebb3 {
// ebb3:jump ebb4 -
// } ebb3
// }
// } ebb4
// }
// } ebb2
// }
// ebb1 {
// ebb1:jump ebb3 -
// } ebb1
// }
// } ebb0
test_reverse_postorder_traversal(
"
function %test(i32) native {
@@ -98,7 +166,7 @@ fn loops_two() {
return
}
",
vec![0, 2, 1, 3, 4, 5],
vec![0, 1, 2, 4, 3, 5],
);
}
@@ -130,7 +198,7 @@ fn loops_three() {
return
}
",
vec![0, 2, 1, 3, 4, 6, 7, 5],
vec![0, 1, 2, 4, 3, 6, 7, 5],
);
}