WIP.
This commit is contained in:
parent
a053396e69
commit
349032b1af
|
@ -1,6 +1,7 @@
|
||||||
//! Treeification: placing some values "under" others if only used
|
//! Treeification: placing some values "under" others if only used
|
||||||
//! once, to generate more AST-like Wasm code.
|
//! once, to generate more AST-like Wasm code.
|
||||||
|
|
||||||
|
use crate::entity::EntityRef;
|
||||||
use crate::ir::{FunctionBody, Value, ValueDef};
|
use crate::ir::{FunctionBody, Value, ValueDef};
|
||||||
use crate::Operator;
|
use crate::Operator;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
@ -29,6 +30,11 @@ impl Trees {
|
||||||
for (value, def) in body.values.entries() {
|
for (value, def) in body.values.entries() {
|
||||||
match def {
|
match def {
|
||||||
&ValueDef::Operator(_, ref args, _) => {
|
&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
|
// For each of the args, if the value is produced
|
||||||
// by a single-output op and is movable, and is
|
// by a single-output op and is movable, and is
|
||||||
// not already recorded in `multi_use`, place it
|
// not already recorded in `multi_use`, place it
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use super::{Block, FunctionBodyDisplay, Local, Module, Signature, Type, Value, ValueDef};
|
use super::{Block, FunctionBodyDisplay, Local, Module, Signature, Type, Value, ValueDef};
|
||||||
use crate::entity::{EntityVec, PerEntity};
|
use crate::entity::{EntityRef, EntityVec, PerEntity};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum FuncDecl {
|
pub enum FuncDecl {
|
||||||
|
@ -112,6 +112,10 @@ impl FunctionBody {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_alias(&self, value: Value) -> Value {
|
pub fn resolve_alias(&self, value: Value) -> Value {
|
||||||
|
if value.is_invalid() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
let mut result = value;
|
let mut result = value;
|
||||||
loop {
|
loop {
|
||||||
if let &ValueDef::Alias(to) = &self.values[result] {
|
if let &ValueDef::Alias(to) = &self.values[result] {
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
use crate::{FunctionBody, ValueDef};
|
use crate::{FunctionBody, ValueDef};
|
||||||
|
|
||||||
pub fn run(body: &mut FunctionBody) {
|
pub fn run(body: &mut FunctionBody) {
|
||||||
|
log::debug!(
|
||||||
|
"Resolve aliases: running on:\n{}\n",
|
||||||
|
body.display_verbose("| ")
|
||||||
|
);
|
||||||
for value in body.values.iter() {
|
for value in body.values.iter() {
|
||||||
let mut value_def = std::mem::take(&mut body.values[value]);
|
let mut value_def = std::mem::take(&mut body.values[value]);
|
||||||
match &mut value_def {
|
match &mut value_def {
|
||||||
|
|
Loading…
Reference in a new issue