Replace cretonne-wasm's Local with cretonne-frontend's Variable.
Previously, cretonne-wasm used its own Local struct for identifying local variables. However, now that cretonne-frontend provides a Variable struct, just use that instead.
This commit is contained in:
@@ -26,9 +26,9 @@ use cretonne::ir::{self, InstBuilder, MemFlags, JumpTableData};
|
||||
use cretonne::ir::types::*;
|
||||
use cretonne::ir::condcodes::{IntCC, FloatCC};
|
||||
use cretonne::packed_option::ReservedValue;
|
||||
use cton_frontend::FunctionBuilder;
|
||||
use cton_frontend::{FunctionBuilder, Variable};
|
||||
use wasmparser::{Operator, MemoryImmediate};
|
||||
use translation_utils::{f32_translation, f64_translation, type_to_type, num_return_values, Local};
|
||||
use translation_utils::{f32_translation, f64_translation, type_to_type, num_return_values};
|
||||
use translation_utils::{TableIndex, SignatureIndex, FunctionIndex, MemoryIndex};
|
||||
use state::{TranslationState, ControlStackFrame};
|
||||
use std::collections::{HashMap, hash_map};
|
||||
@@ -39,7 +39,7 @@ use std::{i32, u32};
|
||||
/// a return.
|
||||
pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
op: Operator,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
environ: &mut FE,
|
||||
) {
|
||||
@@ -53,14 +53,16 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
* `get_local` and `set_local` are treated as non-SSA variables and will completely
|
||||
* disappear in the Cretonne Code
|
||||
***********************************************************************************/
|
||||
Operator::GetLocal { local_index } => state.push1(builder.use_var(Local(local_index))),
|
||||
Operator::GetLocal { local_index } => {
|
||||
state.push1(builder.use_var(Variable::with_u32(local_index)))
|
||||
}
|
||||
Operator::SetLocal { local_index } => {
|
||||
let val = state.pop1();
|
||||
builder.def_var(Local(local_index), val);
|
||||
builder.def_var(Variable::with_u32(local_index), val);
|
||||
}
|
||||
Operator::TeeLocal { local_index } => {
|
||||
let val = state.peek1();
|
||||
builder.def_var(Local(local_index), val);
|
||||
builder.def_var(Variable::with_u32(local_index), val);
|
||||
}
|
||||
/********************************** Globals ****************************************
|
||||
* `get_global` and `set_global` are handled by the environment.
|
||||
@@ -934,7 +936,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
|
||||
/// portion so the translation state muts be updated accordingly.
|
||||
fn translate_unreachable_operator(
|
||||
op: Operator,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
) {
|
||||
match op {
|
||||
@@ -1019,7 +1021,7 @@ fn get_heap_addr(
|
||||
addr32: ir::Value,
|
||||
offset: u32,
|
||||
addr_ty: ir::Type,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
) -> (ir::Value, i32) {
|
||||
use std::cmp::min;
|
||||
|
||||
@@ -1055,7 +1057,7 @@ fn translate_load<FE: FuncEnvironment + ?Sized>(
|
||||
offset: u32,
|
||||
opcode: ir::Opcode,
|
||||
result_ty: ir::Type,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
environ: &mut FE,
|
||||
) {
|
||||
@@ -1078,7 +1080,7 @@ fn translate_load<FE: FuncEnvironment + ?Sized>(
|
||||
fn translate_store<FE: FuncEnvironment + ?Sized>(
|
||||
offset: u32,
|
||||
opcode: ir::Opcode,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
environ: &mut FE,
|
||||
) {
|
||||
|
||||
@@ -9,10 +9,9 @@ use cretonne::entity::EntityRef;
|
||||
use cretonne::ir::{self, InstBuilder, Ebb};
|
||||
use cretonne::result::{CtonResult, CtonError};
|
||||
use cretonne::timing;
|
||||
use cton_frontend::{ILBuilder, FunctionBuilder};
|
||||
use cton_frontend::{ILBuilder, FunctionBuilder, Variable};
|
||||
use environ::FuncEnvironment;
|
||||
use state::TranslationState;
|
||||
use translation_utils::Local;
|
||||
use wasmparser::{self, BinaryReader};
|
||||
|
||||
/// WebAssembly to Cretonne IL function translator.
|
||||
@@ -21,7 +20,7 @@ use wasmparser::{self, BinaryReader};
|
||||
/// by a `FuncEnvironment` object. A single translator instance can be reused to translate multiple
|
||||
/// functions which will reduce heap allocation traffic.
|
||||
pub struct FuncTranslator {
|
||||
il_builder: ILBuilder<Local>,
|
||||
il_builder: ILBuilder<Variable>,
|
||||
state: TranslationState,
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ impl FuncTranslator {
|
||||
/// Declare local variables for the signature parameters that correspond to WebAssembly locals.
|
||||
///
|
||||
/// Return the number of local variables declared.
|
||||
fn declare_wasm_parameters(builder: &mut FunctionBuilder<Local>, entry_block: Ebb) -> usize {
|
||||
fn declare_wasm_parameters(builder: &mut FunctionBuilder<Variable>, entry_block: Ebb) -> usize {
|
||||
let sig_len = builder.func.signature.params.len();
|
||||
let mut next_local = 0;
|
||||
for i in 0..sig_len {
|
||||
@@ -116,7 +115,7 @@ fn declare_wasm_parameters(builder: &mut FunctionBuilder<Local>, entry_block: Eb
|
||||
// signature parameters. For example, a `vmctx` pointer.
|
||||
if param_type.purpose == ir::ArgumentPurpose::Normal {
|
||||
// This is a normal WebAssembly signature parameter, so create a local for it.
|
||||
let local = Local::new(next_local);
|
||||
let local = Variable::new(next_local);
|
||||
builder.declare_var(local, param_type.value_type);
|
||||
next_local += 1;
|
||||
|
||||
@@ -133,7 +132,7 @@ fn declare_wasm_parameters(builder: &mut FunctionBuilder<Local>, entry_block: Eb
|
||||
/// Declare local variables, starting from `num_params`.
|
||||
fn parse_local_decls(
|
||||
reader: &mut BinaryReader,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
num_params: usize,
|
||||
) -> CtonResult {
|
||||
let mut next_local = num_params;
|
||||
@@ -157,7 +156,7 @@ fn parse_local_decls(
|
||||
///
|
||||
/// Fail of too many locals are declared in the function, or if the type is not valid for a local.
|
||||
fn declare_locals(
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
count: u32,
|
||||
wasm_type: wasmparser::Type,
|
||||
next_local: &mut usize,
|
||||
@@ -174,7 +173,7 @@ fn declare_locals(
|
||||
|
||||
let ty = builder.func.dfg.value_type(zeroval);
|
||||
for _ in 0..count {
|
||||
let local = Local::new(*next_local);
|
||||
let local = Variable::new(*next_local);
|
||||
builder.declare_var(local, ty);
|
||||
builder.def_var(local, zeroval);
|
||||
*next_local += 1;
|
||||
@@ -187,7 +186,7 @@ fn declare_locals(
|
||||
/// arguments and locals are declared in the builder.
|
||||
fn parse_function_body<FE: FuncEnvironment + ?Sized>(
|
||||
mut reader: BinaryReader,
|
||||
builder: &mut FunctionBuilder<Local>,
|
||||
builder: &mut FunctionBuilder<Variable>,
|
||||
state: &mut TranslationState,
|
||||
environ: &mut FE,
|
||||
) -> CtonResult {
|
||||
|
||||
@@ -71,25 +71,6 @@ pub struct Memory {
|
||||
pub shared: bool,
|
||||
}
|
||||
|
||||
/// Wrapper to a `get_local` and `set_local` index. They are WebAssembly's non-SSA variables.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub struct Local(pub u32);
|
||||
impl cretonne::entity::EntityRef for Local {
|
||||
fn new(index: usize) -> Self {
|
||||
debug_assert!(index < (u32::MAX as usize));
|
||||
Local(index as u32)
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
self.0 as usize
|
||||
}
|
||||
}
|
||||
impl Default for Local {
|
||||
fn default() -> Self {
|
||||
Local(u32::MAX)
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function translating wasmparser types to Cretonne types when possible.
|
||||
pub fn type_to_type(ty: &wasmparser::Type) -> Result<cretonne::ir::Type, ()> {
|
||||
match *ty {
|
||||
|
||||
Reference in New Issue
Block a user