Move arg unpacking for all remaining expand functions to simple_legalize
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
//! instruction into code that depends on the kind of global value referenced.
|
//! instruction into code that depends on the kind of global value referenced.
|
||||||
|
|
||||||
use crate::cursor::{Cursor, FuncCursor};
|
use crate::cursor::{Cursor, FuncCursor};
|
||||||
use crate::flowgraph::ControlFlowGraph;
|
|
||||||
use crate::ir::{self, InstBuilder};
|
use crate::ir::{self, InstBuilder};
|
||||||
use crate::isa::TargetIsa;
|
use crate::isa::TargetIsa;
|
||||||
|
|
||||||
@@ -12,22 +11,10 @@ use crate::isa::TargetIsa;
|
|||||||
pub fn expand_global_value(
|
pub fn expand_global_value(
|
||||||
inst: ir::Inst,
|
inst: ir::Inst,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
_cfg: &mut ControlFlowGraph,
|
|
||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
|
global_value: ir::GlobalValue,
|
||||||
) {
|
) {
|
||||||
// Unpack the instruction.
|
match func.global_values[global_value] {
|
||||||
let gv = match func.dfg[inst] {
|
|
||||||
ir::InstructionData::UnaryGlobalValue {
|
|
||||||
opcode,
|
|
||||||
global_value,
|
|
||||||
} => {
|
|
||||||
debug_assert_eq!(opcode, ir::Opcode::GlobalValue);
|
|
||||||
global_value
|
|
||||||
}
|
|
||||||
_ => panic!("Wanted global_value: {}", func.dfg.display_inst(inst)),
|
|
||||||
};
|
|
||||||
|
|
||||||
match func.global_values[gv] {
|
|
||||||
ir::GlobalValueData::VMContext => vmctx_addr(inst, func),
|
ir::GlobalValueData::VMContext => vmctx_addr(inst, func),
|
||||||
ir::GlobalValueData::IAddImm {
|
ir::GlobalValueData::IAddImm {
|
||||||
base,
|
base,
|
||||||
@@ -40,7 +27,7 @@ pub fn expand_global_value(
|
|||||||
global_type,
|
global_type,
|
||||||
readonly,
|
readonly,
|
||||||
} => load_addr(inst, func, base, offset, global_type, readonly, isa),
|
} => load_addr(inst, func, base, offset, global_type, readonly, isa),
|
||||||
ir::GlobalValueData::Symbol { tls, .. } => symbol(inst, func, gv, isa, tls),
|
ir::GlobalValueData::Symbol { tls, .. } => symbol(inst, func, global_value, isa, tls),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
use crate::cursor::{Cursor, FuncCursor};
|
use crate::cursor::{Cursor, FuncCursor};
|
||||||
use crate::flowgraph::ControlFlowGraph;
|
use crate::flowgraph::ControlFlowGraph;
|
||||||
use crate::ir::condcodes::IntCC;
|
use crate::ir::condcodes::IntCC;
|
||||||
|
use crate::ir::immediates::Uimm32;
|
||||||
use crate::ir::{self, InstBuilder};
|
use crate::ir::{self, InstBuilder};
|
||||||
use crate::isa::TargetIsa;
|
use crate::isa::TargetIsa;
|
||||||
|
|
||||||
@@ -15,31 +16,26 @@ pub fn expand_heap_addr(
|
|||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
cfg: &mut ControlFlowGraph,
|
cfg: &mut ControlFlowGraph,
|
||||||
isa: &dyn TargetIsa,
|
isa: &dyn TargetIsa,
|
||||||
|
heap: ir::Heap,
|
||||||
|
offset: ir::Value,
|
||||||
|
access_size: Uimm32,
|
||||||
) {
|
) {
|
||||||
// Unpack the instruction.
|
|
||||||
let (heap, offset, access_size) = match func.dfg[inst] {
|
|
||||||
ir::InstructionData::HeapAddr {
|
|
||||||
opcode,
|
|
||||||
heap,
|
|
||||||
arg,
|
|
||||||
imm,
|
|
||||||
} => {
|
|
||||||
debug_assert_eq!(opcode, ir::Opcode::HeapAddr);
|
|
||||||
(heap, arg, u64::from(imm))
|
|
||||||
}
|
|
||||||
_ => panic!("Wanted heap_addr: {}", func.dfg.display_inst(inst)),
|
|
||||||
};
|
|
||||||
|
|
||||||
match func.heaps[heap].style {
|
match func.heaps[heap].style {
|
||||||
ir::HeapStyle::Dynamic { bound_gv } => {
|
ir::HeapStyle::Dynamic { bound_gv } => dynamic_addr(
|
||||||
dynamic_addr(isa, inst, heap, offset, access_size, bound_gv, func)
|
isa,
|
||||||
}
|
inst,
|
||||||
|
heap,
|
||||||
|
offset,
|
||||||
|
u64::from(access_size),
|
||||||
|
bound_gv,
|
||||||
|
func,
|
||||||
|
),
|
||||||
ir::HeapStyle::Static { bound } => static_addr(
|
ir::HeapStyle::Static { bound } => static_addr(
|
||||||
isa,
|
isa,
|
||||||
inst,
|
inst,
|
||||||
heap,
|
heap,
|
||||||
offset,
|
offset,
|
||||||
access_size,
|
u64::from(access_size),
|
||||||
bound.into(),
|
bound.into(),
|
||||||
func,
|
func,
|
||||||
cfg,
|
cfg,
|
||||||
|
|||||||
@@ -60,21 +60,25 @@ pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa:
|
|||||||
cfg.recompute_block(pos.func, old_block);
|
cfg.recompute_block(pos.func, old_block);
|
||||||
}
|
}
|
||||||
InstructionData::CondTrap {
|
InstructionData::CondTrap {
|
||||||
opcode: ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz,
|
opcode:
|
||||||
..
|
opcode @ (ir::Opcode::Trapnz | ir::Opcode::Trapz | ir::Opcode::ResumableTrapnz),
|
||||||
|
arg,
|
||||||
|
code,
|
||||||
} => {
|
} => {
|
||||||
expand_cond_trap(inst, &mut pos.func, cfg, isa);
|
expand_cond_trap(inst, &mut pos.func, cfg, opcode, arg, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
// memory and constants
|
// memory and constants
|
||||||
InstructionData::UnaryGlobalValue {
|
InstructionData::UnaryGlobalValue {
|
||||||
opcode: ir::Opcode::GlobalValue,
|
opcode: ir::Opcode::GlobalValue,
|
||||||
..
|
global_value,
|
||||||
} => expand_global_value(inst, &mut pos.func, cfg, isa),
|
} => expand_global_value(inst, &mut pos.func, isa, global_value),
|
||||||
InstructionData::HeapAddr {
|
InstructionData::HeapAddr {
|
||||||
opcode: ir::Opcode::HeapAddr,
|
opcode: ir::Opcode::HeapAddr,
|
||||||
..
|
heap,
|
||||||
} => expand_heap_addr(inst, &mut pos.func, cfg, isa),
|
arg,
|
||||||
|
imm,
|
||||||
|
} => expand_heap_addr(inst, &mut pos.func, cfg, isa, heap, arg, imm),
|
||||||
InstructionData::StackLoad {
|
InstructionData::StackLoad {
|
||||||
opcode: ir::Opcode::StackLoad,
|
opcode: ir::Opcode::StackLoad,
|
||||||
stack_slot,
|
stack_slot,
|
||||||
@@ -113,8 +117,10 @@ pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa:
|
|||||||
}
|
}
|
||||||
InstructionData::TableAddr {
|
InstructionData::TableAddr {
|
||||||
opcode: ir::Opcode::TableAddr,
|
opcode: ir::Opcode::TableAddr,
|
||||||
..
|
table,
|
||||||
} => expand_table_addr(inst, &mut pos.func, cfg, isa),
|
arg,
|
||||||
|
offset,
|
||||||
|
} => expand_table_addr(inst, &mut pos.func, table, arg, offset),
|
||||||
|
|
||||||
// bitops
|
// bitops
|
||||||
InstructionData::BinaryImm64 {
|
InstructionData::BinaryImm64 {
|
||||||
@@ -287,27 +293,20 @@ pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Custom expansion for conditional trap instructions.
|
/// Custom expansion for conditional trap instructions.
|
||||||
/// TODO: Add CFG support to the Rust DSL patterns so we won't have to do this.
|
|
||||||
fn expand_cond_trap(
|
fn expand_cond_trap(
|
||||||
inst: ir::Inst,
|
inst: ir::Inst,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
cfg: &mut ControlFlowGraph,
|
cfg: &mut ControlFlowGraph,
|
||||||
_isa: &dyn TargetIsa,
|
opcode: ir::Opcode,
|
||||||
|
arg: ir::Value,
|
||||||
|
code: ir::TrapCode,
|
||||||
) {
|
) {
|
||||||
// Parse the instruction.
|
// Parse the instruction.
|
||||||
let trapz;
|
let trapz = match opcode {
|
||||||
let (arg, code, opcode) = match func.dfg[inst] {
|
|
||||||
ir::InstructionData::CondTrap { opcode, arg, code } => {
|
|
||||||
// We want to branch *over* an unconditional trap.
|
|
||||||
trapz = match opcode {
|
|
||||||
ir::Opcode::Trapz => true,
|
ir::Opcode::Trapz => true,
|
||||||
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
|
ir::Opcode::Trapnz | ir::Opcode::ResumableTrapnz => false,
|
||||||
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
|
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
|
||||||
};
|
};
|
||||||
(arg, code, opcode)
|
|
||||||
}
|
|
||||||
_ => panic!("Expected cond trap: {}", func.dfg.display_inst(inst)),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Split the block after `inst`:
|
// Split the block after `inst`:
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -4,43 +4,17 @@
|
|||||||
//! instruction into code that depends on the kind of table referenced.
|
//! instruction into code that depends on the kind of table referenced.
|
||||||
|
|
||||||
use crate::cursor::{Cursor, FuncCursor};
|
use crate::cursor::{Cursor, FuncCursor};
|
||||||
use crate::flowgraph::ControlFlowGraph;
|
|
||||||
use crate::ir::condcodes::IntCC;
|
use crate::ir::condcodes::IntCC;
|
||||||
use crate::ir::immediates::Offset32;
|
use crate::ir::immediates::Offset32;
|
||||||
use crate::ir::{self, InstBuilder};
|
use crate::ir::{self, InstBuilder};
|
||||||
use crate::isa::TargetIsa;
|
|
||||||
|
|
||||||
/// Expand a `table_addr` instruction according to the definition of the table.
|
/// Expand a `table_addr` instruction according to the definition of the table.
|
||||||
pub fn expand_table_addr(
|
pub fn expand_table_addr(
|
||||||
inst: ir::Inst,
|
inst: ir::Inst,
|
||||||
func: &mut ir::Function,
|
func: &mut ir::Function,
|
||||||
_cfg: &mut ControlFlowGraph,
|
|
||||||
_isa: &dyn TargetIsa,
|
|
||||||
) {
|
|
||||||
// Unpack the instruction.
|
|
||||||
let (table, index, element_offset) = match func.dfg[inst] {
|
|
||||||
ir::InstructionData::TableAddr {
|
|
||||||
opcode,
|
|
||||||
table,
|
|
||||||
arg,
|
|
||||||
offset,
|
|
||||||
} => {
|
|
||||||
debug_assert_eq!(opcode, ir::Opcode::TableAddr);
|
|
||||||
(table, arg, offset)
|
|
||||||
}
|
|
||||||
_ => panic!("Wanted table_addr: {}", func.dfg.display_inst(inst)),
|
|
||||||
};
|
|
||||||
|
|
||||||
dynamic_addr(inst, table, index, element_offset, func);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Expand a `table_addr` for a dynamic table.
|
|
||||||
fn dynamic_addr(
|
|
||||||
inst: ir::Inst,
|
|
||||||
table: ir::Table,
|
table: ir::Table,
|
||||||
index: ir::Value,
|
index: ir::Value,
|
||||||
element_offset: Offset32,
|
element_offset: Offset32,
|
||||||
func: &mut ir::Function,
|
|
||||||
) {
|
) {
|
||||||
let bound_gv = func.tables[table].bound_gv;
|
let bound_gv = func.tables[table].bound_gv;
|
||||||
let index_ty = func.dfg.value_type(index);
|
let index_ty = func.dfg.value_type(index);
|
||||||
|
|||||||
Reference in New Issue
Block a user