Expose CFG predecessors only as an iterator.

Define two public iterator types in the flowgraph module, PredIter and
SuccIter, which are by-value iterators over an EBB's predecessors and
successors respectively.

Provide matching pred_iter() and succ_iter() methods for inspecting the
CFG. Remove the get_predecessors() method which returned a slice.

Update the uses of get_predecessors(), none of which depended on it
being a slice.

This abstraction makes it possible to change the internal representation
of the CFG.
This commit is contained in:
Jakob Stoklund Olesen
2017-11-22 09:13:04 -08:00
parent 7956084121
commit 92f378de76
12 changed files with 61 additions and 54 deletions

View File

@@ -134,7 +134,7 @@ impl LoopAnalysis {
) {
// We traverse the CFG in reverse postorder
for &ebb in domtree.cfg_postorder().iter().rev() {
for &(_, pred_inst) in cfg.get_predecessors(ebb) {
for (_, pred_inst) in cfg.pred_iter(ebb) {
// If the ebb dominates one of its predecessors it is a back edge
if domtree.dominates(ebb, pred_inst, layout) {
// This ebb is a loop header, so we create its associated loop
@@ -160,7 +160,7 @@ impl LoopAnalysis {
// We handle each loop header in reverse order, corresponding to a pseudo postorder
// traversal of the graph.
for lp in self.loops().rev() {
for &(pred, pred_inst) in cfg.get_predecessors(self.loops[lp].header) {
for (pred, pred_inst) in cfg.pred_iter(self.loops[lp].header) {
// We follow the back edges
if domtree.dominates(self.loops[lp].header, pred_inst, layout) {
stack.push(pred);
@@ -210,7 +210,7 @@ impl LoopAnalysis {
// Now we have handled the popped node and need to continue the DFS by adding the
// predecessors of that node
if let Some(continue_dfs) = continue_dfs {
for &(pred, _) in cfg.get_predecessors(continue_dfs) {
for (pred, _) in cfg.pred_iter(continue_dfs) {
stack.push(pred)
}
}