From e6963b8d786afa5885a6b2da295e9f7c7be4fde1 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Mon, 28 Nov 2022 22:23:24 -0800 Subject: [PATCH] WIP. --- src/backend/mod.rs | 7 ++++--- src/backend/stackify.rs | 14 +++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 0f61be6..9059176 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -20,13 +20,14 @@ pub struct WasmBackend<'a> { impl<'a> WasmBackend<'a> { pub fn new(body: &'a FunctionBody) -> Result> { + log::debug!("Backend compiling:\n{}\n", body.display("| ")); let cfg = CFGInfo::new(body); let rpo = RPO::compute(body); - log::trace!("RPO:\n{:?}\n", rpo); + log::debug!("RPO:\n{:?}\n", rpo); let trees = Trees::compute(body); - log::trace!("Trees:\n{:?}\n", trees); + log::debug!("Trees:\n{:?}\n", trees); let ctrl = StackifyContext::new(body, &cfg, &rpo)?.compute(); - log::trace!("Ctrl:\n{:?}\n", ctrl); + log::debug!("Ctrl:\n{:?}\n", ctrl); Ok(WasmBackend { body, rpo, diff --git a/src/backend/stackify.rs b/src/backend/stackify.rs index 2b5917d..45b17b1 100644 --- a/src/backend/stackify.rs +++ b/src/backend/stackify.rs @@ -168,9 +168,17 @@ impl<'a, 'b> Context<'a, 'b> { .filter(|child| self.merge_nodes.contains(&child)) .collect::>(); // Sort merge nodes so highest RPO number comes first. - merge_node_children.sort_unstable_by_key(|&block| self.rpo.rev[block]); + merge_node_children.sort_unstable_by_key(|&block| std::cmp::Reverse(self.rpo.rev[block])); let is_loop_header = self.loop_headers.contains(&block); + + log::trace!( + "handle_dom_subtree: block {} merge_nodes {:?} loop_header {}", + block, + merge_node_children, + is_loop_header + ); + if is_loop_header { self.ctrl_stack.push(CtrlEntry::Loop { header: block }); let mut body = vec![]; @@ -186,6 +194,7 @@ impl<'a, 'b> Context<'a, 'b> { } fn resolve_target(&self, target: Block) -> WasmLabel { + log::trace!("resolve_target: {} in stack {:?}", target, self.ctrl_stack); WasmLabel( u32::try_from( self.ctrl_stack @@ -199,6 +208,7 @@ impl<'a, 'b> Context<'a, 'b> { } fn do_branch(&mut self, source: Block, target: &'a BlockTarget, into: &mut Vec>) { + log::trace!("do_branch: {} -> {:?}", source, target); // This will be a branch to some entry in the control stack if // the target is either a merge block, or is a backward branch // (by RPO number). @@ -231,6 +241,7 @@ impl<'a, 'b> Context<'a, 'b> { default: &'a BlockTarget, into: &mut Vec>, ) { + log::trace!("do_branch_select: {:?}, default {:?}", targets, default); let mut body = vec![WasmBlock::Select { selector, targets: (0..targets.len()) @@ -271,6 +282,7 @@ impl<'a, 'b> Context<'a, 'b> { } fn node_within(&mut self, block: Block, merge_nodes: &[Block], into: &mut Vec>) { + log::trace!("node_within: block {} merge_nodes {:?}", block, merge_nodes); if let Some((&first, rest)) = merge_nodes.split_first() { self.ctrl_stack.push(CtrlEntry::Block { out: first }); let mut body = vec![];