This commit is contained in:
Chris Fallin 2022-11-29 10:44:15 -08:00
parent a053396e69
commit 349032b1af
No known key found for this signature in database
GPG key ID: 31649E4FE65EB465
3 changed files with 15 additions and 1 deletions

View file

@ -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

View file

@ -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] {

View file

@ -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 {