From 349032b1af24daf10e878f5052792827fb70f082 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Tue, 29 Nov 2022 10:44:15 -0800 Subject: [PATCH] WIP. --- src/backend/treeify.rs | 6 ++++++ src/ir/func.rs | 6 +++++- src/passes/resolve_aliases.rs | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/backend/treeify.rs b/src/backend/treeify.rs index e25b385..22fd3a0 100644 --- a/src/backend/treeify.rs +++ b/src/backend/treeify.rs @@ -1,6 +1,7 @@ //! Treeification: placing some values "under" others if only used //! once, to generate more AST-like Wasm code. +use crate::entity::EntityRef; use crate::ir::{FunctionBody, Value, ValueDef}; use crate::Operator; use std::collections::{HashMap, HashSet}; @@ -29,6 +30,11 @@ impl Trees { for (value, def) in body.values.entries() { match def { &ValueDef::Operator(_, ref args, _) => { + // Ignore operators with invalid args: these must + // always be unreachable. + if args.iter().any(|arg| arg.is_invalid()) { + continue; + } // For each of the args, if the value is produced // by a single-output op and is movable, and is // not already recorded in `multi_use`, place it diff --git a/src/ir/func.rs b/src/ir/func.rs index 359a0dd..e80ddf3 100644 --- a/src/ir/func.rs +++ b/src/ir/func.rs @@ -1,5 +1,5 @@ use super::{Block, FunctionBodyDisplay, Local, Module, Signature, Type, Value, ValueDef}; -use crate::entity::{EntityVec, PerEntity}; +use crate::entity::{EntityRef, EntityVec, PerEntity}; #[derive(Clone, Debug)] pub enum FuncDecl { @@ -112,6 +112,10 @@ impl FunctionBody { } pub fn resolve_alias(&self, value: Value) -> Value { + if value.is_invalid() { + return value; + } + let mut result = value; loop { if let &ValueDef::Alias(to) = &self.values[result] { diff --git a/src/passes/resolve_aliases.rs b/src/passes/resolve_aliases.rs index 8d254b2..370a7c5 100644 --- a/src/passes/resolve_aliases.rs +++ b/src/passes/resolve_aliases.rs @@ -3,6 +3,10 @@ use crate::{FunctionBody, ValueDef}; pub fn run(body: &mut FunctionBody) { + log::debug!( + "Resolve aliases: running on:\n{}\n", + body.display_verbose("| ") + ); for value in body.values.iter() { let mut value_def = std::mem::take(&mut body.values[value]); match &mut value_def {