Switch to a FuncCursor in the top-level legalizer loop.
Stop passing Cursor references to legalizer functions. Give them the whole &mut Function instead. Given the whole Function reference, these functions can create their own cursors. This lets legalizer actions access other Function data structures like the global variables.
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
//! The legalizer does not deal with register allocation constraints. These constraints are derived
|
||||
//! from the encoding recipes, and solved later by the register allocator.
|
||||
|
||||
use cursor::{Cursor, FuncCursor};
|
||||
use dominator_tree::DominatorTree;
|
||||
use flowgraph::ControlFlowGraph;
|
||||
use ir::{self, Function, Cursor, CursorBase};
|
||||
use ir;
|
||||
use ir::condcodes::IntCC;
|
||||
use isa::TargetIsa;
|
||||
use bitset::BitSet;
|
||||
@@ -28,7 +29,7 @@ mod split;
|
||||
/// - Transform any instructions that don't have a legal representation in `isa`.
|
||||
/// - Fill out `func.encodings`.
|
||||
///
|
||||
pub fn legalize_function(func: &mut Function,
|
||||
pub fn legalize_function(func: &mut ir::Function,
|
||||
cfg: &mut ControlFlowGraph,
|
||||
domtree: &DominatorTree,
|
||||
isa: &TargetIsa) {
|
||||
@@ -36,7 +37,7 @@ pub fn legalize_function(func: &mut Function,
|
||||
|
||||
func.encodings.resize(func.dfg.num_insts());
|
||||
|
||||
let mut pos = Cursor::new(&mut func.layout);
|
||||
let mut pos = FuncCursor::new(func);
|
||||
|
||||
// Process EBBs in a reverse post-order. This minimizes the number of split instructions we
|
||||
// need.
|
||||
@@ -48,36 +49,32 @@ pub fn legalize_function(func: &mut Function,
|
||||
let mut prev_pos = pos.position();
|
||||
|
||||
while let Some(inst) = pos.next_inst() {
|
||||
let opcode = func.dfg[inst].opcode();
|
||||
let opcode = pos.func.dfg[inst].opcode();
|
||||
|
||||
// Check for ABI boundaries that need to be converted to the legalized signature.
|
||||
if opcode.is_call() &&
|
||||
boundary::handle_call_abi(&mut func.dfg,
|
||||
&mut func.locations,
|
||||
&mut func.stack_slots,
|
||||
cfg,
|
||||
&mut pos) {
|
||||
if opcode.is_call() && boundary::handle_call_abi(inst, pos.func, cfg) {
|
||||
// Go back and legalize the inserted argument conversion instructions.
|
||||
pos.set_position(prev_pos);
|
||||
continue;
|
||||
}
|
||||
|
||||
if opcode.is_return() &&
|
||||
boundary::handle_return_abi(&mut func.dfg, cfg, &mut pos, &func.signature) {
|
||||
if opcode.is_return() && boundary::handle_return_abi(inst, pos.func, cfg) {
|
||||
// Go back and legalize the inserted return value conversion instructions.
|
||||
pos.set_position(prev_pos);
|
||||
continue;
|
||||
}
|
||||
|
||||
if opcode.is_branch() {
|
||||
split::simplify_branch_arguments(&mut func.dfg, inst);
|
||||
split::simplify_branch_arguments(&mut pos.func.dfg, inst);
|
||||
}
|
||||
|
||||
match isa.encode(&func.dfg, &func.dfg[inst], func.dfg.ctrl_typevar(inst)) {
|
||||
Ok(encoding) => *func.encodings.ensure(inst) = encoding,
|
||||
match isa.encode(&pos.func.dfg,
|
||||
&pos.func.dfg[inst],
|
||||
pos.func.dfg.ctrl_typevar(inst)) {
|
||||
Ok(encoding) => *pos.func.encodings.ensure(inst) = encoding,
|
||||
Err(action) => {
|
||||
// We should transform the instruction into legal equivalents.
|
||||
let changed = action(&mut func.dfg, cfg, &mut pos);
|
||||
let changed = action(inst, pos.func, cfg);
|
||||
// If the current instruction was replaced, we need to double back and revisit
|
||||
// the expanded sequence. This is both to assign encodings and possible to
|
||||
// expand further.
|
||||
@@ -94,7 +91,6 @@ pub fn legalize_function(func: &mut Function,
|
||||
prev_pos = pos.position();
|
||||
}
|
||||
}
|
||||
func.encodings.resize(func.dfg.num_insts());
|
||||
}
|
||||
|
||||
// Include legalization patterns that were generated by `gen_legalizer.py` from the `XForms` in
|
||||
|
||||
Reference in New Issue
Block a user