From fecbcbb7b48e72da9034b1d1906482a080f4fabe Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 25 Aug 2017 10:36:25 -0700 Subject: [PATCH] Drop the domtree argument to legalize_function(). Future legalization patterns will have the ability to mutate the flowgraph, so the domtree's list of RPO blocks is not a good guide for iteration. Use the layout order instead. This will pick up any new EBBs inserted. --- lib/cretonne/src/context.rs | 2 +- lib/cretonne/src/legalizer/mod.rs | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/cretonne/src/context.rs b/lib/cretonne/src/context.rs index 9967f1e11e..7fec7ea0fb 100644 --- a/lib/cretonne/src/context.rs +++ b/lib/cretonne/src/context.rs @@ -103,7 +103,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, &self.domtree, isa); + legalize_function(&mut self.func, &mut self.cfg, isa); self.verify_if(isa) } diff --git a/lib/cretonne/src/legalizer/mod.rs b/lib/cretonne/src/legalizer/mod.rs index 65365018d2..8909366e01 100644 --- a/lib/cretonne/src/legalizer/mod.rs +++ b/lib/cretonne/src/legalizer/mod.rs @@ -14,7 +14,6 @@ //! from the encoding recipes, and solved later by the register allocator. use cursor::{Cursor, FuncCursor}; -use dominator_tree::DominatorTree; use flowgraph::ControlFlowGraph; use ir; use isa::TargetIsa; @@ -33,21 +32,16 @@ use self::heap::expand_heap_addr; /// - Transform any instructions that don't have a legal representation in `isa`. /// - Fill out `func.encodings`. /// -pub fn legalize_function(func: &mut ir::Function, - cfg: &mut ControlFlowGraph, - domtree: &DominatorTree, - isa: &TargetIsa) { +pub fn legalize_function(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa: &TargetIsa) { boundary::legalize_signatures(func, isa); func.encodings.resize(func.dfg.num_insts()); let mut pos = FuncCursor::new(func); - // 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); - + // Process EBBs in layout order. Some legalization actions may split the current EBB or append + // new ones to the end. We need to make sure we visit those new EBBs too. + while let Some(_ebb) = pos.next_ebb() { // Keep track of the cursor position before the instruction being processed, so we can // double back when replacing instructions. let mut prev_pos = pos.position();