From 539af66b88bddd55a3b2d0dfdbe06a3f9fa02c0d Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Mon, 28 Nov 2022 21:55:58 -0800 Subject: [PATCH] WIP. --- src/backend/mod.rs | 15 ++++++++++++++- src/backend/stackify.rs | 16 +++++++++++----- src/backend/treeify.rs | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 8dfe593..059df29 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -1,11 +1,13 @@ //! Backend: IR to Wasm. +use crate::cfg::CFGInfo; use crate::entity::{EntityRef, PerEntity}; use crate::ir::{Block, FunctionBody, Value, ValueDef}; use crate::passes::rpo::{RPOIndex, RPO}; use anyhow::Result; pub mod stackify; +use stackify::{Context as StackifyContext, WasmBlock}; pub mod treeify; use treeify::Trees; @@ -13,13 +15,24 @@ pub struct WasmBackend<'a> { body: &'a FunctionBody, rpo: RPO, trees: Trees, + ctrl: Vec>, } impl<'a> WasmBackend<'a> { pub fn new(body: &'a FunctionBody) -> Result> { + let cfg = CFGInfo::new(body); let rpo = RPO::compute(body); + log::trace!("RPO:\n{:?}\n", rpo); let trees = Trees::compute(body); - Ok(WasmBackend { body, rpo, trees }) + log::trace!("Trees:\n{:?}\n", trees); + let ctrl = StackifyContext::new(body, &cfg, &rpo).compute(); + log::trace!("Ctrl:\n{:?}\n", ctrl); + Ok(WasmBackend { + body, + rpo, + trees, + ctrl, + }) } pub fn compile(&self) -> Result> { diff --git a/src/backend/stackify.rs b/src/backend/stackify.rs index e04c6e6..067b0f6 100644 --- a/src/backend/stackify.rs +++ b/src/backend/stackify.rs @@ -69,10 +69,10 @@ impl WasmLabel { } } -struct Context<'a> { +pub struct Context<'a, 'b> { body: &'a FunctionBody, - cfg: &'a CFGInfo, - rpo: &'a RPO, + cfg: &'b CFGInfo, + rpo: &'b RPO, merge_nodes: HashSet, loop_headers: HashSet, ctrl_stack: Vec, @@ -95,8 +95,8 @@ impl CtrlEntry { } } -impl<'a> Context<'a> { - fn new(body: &'a FunctionBody, cfg: &'a CFGInfo, rpo: &'a RPO) -> Self { +impl<'a, 'b> Context<'a, 'b> { + pub fn new(body: &'a FunctionBody, cfg: &'b CFGInfo, rpo: &'b RPO) -> Self { let (merge_nodes, loop_headers) = Self::compute_merge_nodes_and_loop_headers(body, cfg, rpo); Self { @@ -109,6 +109,12 @@ impl<'a> Context<'a> { } } + pub fn compute(mut self) -> Vec> { + let mut body = vec![]; + self.handle_dom_subtree(self.cfg.entry, &mut body); + body + } + fn compute_merge_nodes_and_loop_headers( body: &FunctionBody, cfg: &CFGInfo, diff --git a/src/backend/treeify.rs b/src/backend/treeify.rs index 30206eb..30b03f6 100644 --- a/src/backend/treeify.rs +++ b/src/backend/treeify.rs @@ -10,6 +10,7 @@ use std::convert::TryFrom; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ValueArg(Value, u16); +#[derive(Clone, Debug)] pub struct Trees { /// Is a value placed "under" the given arg slot of the given /// other value?