This commit is contained in:
Chris Fallin 2021-12-12 20:11:28 -08:00
parent 925c57be9e
commit 0947940c43
4 changed files with 36 additions and 27 deletions

9
src/backend/locations.rs Normal file
View file

@ -0,0 +1,9 @@
//! Location assignment (pseudo-regalloc) for SSA values onto
//! locals/operand-stack values.
use crate::LocalId;
pub enum Location {
Local(LocalId),
// TODO: use operand stack
}

View file

@ -2,3 +2,5 @@
mod stackify;
pub(crate) use stackify::*;
mod locations;
pub(crate) use locations::*;

View file

@ -554,7 +554,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
match &op {
wasmparser::Operator::Unreachable => {
if let Some(block) = self.cur_block {
self.body.blocks[block].terminator = Terminator::None;
self.body.end_block(block, Terminator::None);
self.locals.finish_block();
}
self.cur_block = None;
@ -1033,12 +1033,11 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
);
if let Some(block) = self.cur_block {
let args = args.to_vec();
self.body.add_edge(block, target);
let target = BlockTarget {
block: target,
args,
};
self.body.blocks[block].terminator = Terminator::Br { target };
self.body.end_block(block, Terminator::Br { target });
self.cur_block = None;
self.locals.finish_block();
}
@ -1063,19 +1062,20 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
if let Some(block) = self.cur_block {
let if_true_args = if_true_args.to_vec();
let if_false_args = if_false_args.to_vec();
self.body.blocks[block].terminator = Terminator::CondBr {
cond,
if_true: BlockTarget {
block: if_true,
args: if_true_args,
self.body.end_block(
block,
Terminator::CondBr {
cond,
if_true: BlockTarget {
block: if_true,
args: if_true_args,
},
if_false: BlockTarget {
block: if_false,
args: if_false_args,
},
},
if_false: BlockTarget {
block: if_false,
args: if_false_args,
},
};
self.body.add_edge(block, if_true);
self.body.add_edge(block, if_false);
);
self.cur_block = None;
self.locals.finish_block();
}
@ -1112,16 +1112,14 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
args: default_args,
};
for &target in indexed_targets {
self.body.add_edge(block, target);
}
self.body.add_edge(block, default_target);
self.body.blocks[block].terminator = Terminator::Select {
value: index,
targets,
default,
};
self.body.end_block(
block,
Terminator::Select {
value: index,
targets,
default,
},
);
self.cur_block = None;
self.locals.finish_block();
}
@ -1130,7 +1128,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
fn emit_ret(&mut self, values: &[Value]) {
if let Some(block) = self.cur_block {
let values = values.to_vec();
self.body.blocks[block].terminator = Terminator::Return { values };
self.body.end_block(block, Terminator::Return { values });
}
}

View file

@ -90,7 +90,7 @@ impl FunctionBody {
assert_ne!(to, Value::undef());
log::trace!("set_alias: value {:?} to {:?}", value, to);
// Resolve the `to` value through all existing aliases.
let to = self.resolve_alias(to);
let to = self.resolve_and_update_alias(to);
// Disallow cycles.
if to == value {
panic!("Cannot create an alias cycle");