diff --git a/lib/cretonne/src/context.rs b/lib/cretonne/src/context.rs index a67a4bde0e..90c4948b40 100644 --- a/lib/cretonne/src/context.rs +++ b/lib/cretonne/src/context.rs @@ -75,7 +75,7 @@ impl Context { /// Run the legalizer for `isa` on the function. pub fn legalize(&mut self, isa: &TargetIsa) -> CtonResult { - legalize_function(&mut self.func, &mut self.cfg, isa); + legalize_function(&mut self.func, &mut self.cfg, &self.domtree, isa); self.verify_if(isa) } diff --git a/lib/cretonne/src/legalizer/mod.rs b/lib/cretonne/src/legalizer/mod.rs index edd233ccee..803f5808c2 100644 --- a/lib/cretonne/src/legalizer/mod.rs +++ b/lib/cretonne/src/legalizer/mod.rs @@ -13,6 +13,7 @@ //! The legalizer does not deal with register allocation constraints. These constraints are derived //! from the encoding recipes, and solved later by the register allocator. +use dominator_tree::DominatorTree; use flowgraph::ControlFlowGraph; use ir::{Function, Cursor, DataFlowGraph, InstructionData, Opcode, InstBuilder}; use ir::condcodes::IntCC; @@ -26,17 +27,19 @@ mod split; /// - Transform any instructions that don't have a legal representation in `isa`. /// - Fill out `func.encodings`. /// -pub fn legalize_function(func: &mut Function, cfg: &mut ControlFlowGraph, isa: &TargetIsa) { +pub fn legalize_function(func: &mut Function, + cfg: &mut ControlFlowGraph, + domtree: &DominatorTree, + isa: &TargetIsa) { boundary::legalize_signatures(func, isa); func.encodings.resize(func.dfg.num_insts()); - // Process EBBs in a reverse post-order. This minimizes the number of split instructions we - // need. - let mut postorder = cfg.postorder_ebbs(); let mut pos = Cursor::new(&mut func.layout); - while let Some(ebb) = postorder.pop() { + // Process EBBs in a reverse post-order. This minimizes the number of split instructions we + // need. + for &ebb in domtree.cfg_postorder().iter().rev() { pos.goto_top(ebb); // Keep track of the cursor position before the instruction being processed, so we can diff --git a/lib/cretonne/src/loop_analysis.rs b/lib/cretonne/src/loop_analysis.rs index f67a18e9d0..f5ea45424e 100644 --- a/lib/cretonne/src/loop_analysis.rs +++ b/lib/cretonne/src/loop_analysis.rs @@ -128,8 +128,8 @@ impl LoopAnalysis { cfg: &ControlFlowGraph, domtree: &DominatorTree, layout: &Layout) { - // We traverse the CFg in reverse postorder - for &ebb in cfg.postorder_ebbs().iter().rev() { + // We traverse the CFG in reverse postorder + for &ebb in domtree.cfg_postorder().iter().rev() { for &(_, pred_inst) in cfg.get_predecessors(ebb) { // If the ebb dominates one of its predecessors it is a back edge if domtree.ebb_dominates(ebb, pred_inst, layout) { diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index a7665e965d..e8f89f4a1b 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -19,10 +19,9 @@ pub fn do_simple_gvn(func: &mut Function, cfg: &mut ControlFlowGraph) { let domtree = DominatorTree::with_function(func, &cfg); // Visit EBBs in a reverse post-order. - let mut postorder = cfg.postorder_ebbs(); let mut pos = Cursor::new(&mut func.layout); - while let Some(ebb) = postorder.pop() { + for &ebb in domtree.cfg_postorder().iter().rev() { pos.goto_top(ebb); while let Some(inst) = pos.next_inst() {