From c5c9f211df2ec9c6e2cf51f41f24799bbc3a20fd Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 23 Mar 2017 09:50:26 -0700 Subject: [PATCH] Legalize EBBs in a reverse post-order. This means that whenever we need to split a value, it is either already defined by a concatenation instruction in a previously processed EBB, or it's an EBB argument. --- lib/cretonne/src/legalizer/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/cretonne/src/legalizer/mod.rs b/lib/cretonne/src/legalizer/mod.rs index b9dc493527..00354822a1 100644 --- a/lib/cretonne/src/legalizer/mod.rs +++ b/lib/cretonne/src/legalizer/mod.rs @@ -29,10 +29,16 @@ mod split; pub fn legalize_function(func: &mut Function, cfg: &mut ControlFlowGraph, isa: &TargetIsa) { boundary::legalize_signatures(func, isa); - // TODO: This is very simplified and incomplete. 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) = pos.next_ebb() { + + while let Some(ebb) = postorder.pop() { + pos.goto_top(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();