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:
@@ -353,16 +353,12 @@ def gen_xform_group(xgrp, fmt, type_sets):
|
||||
fmt.doc_comment("Legalize the instruction pointed to by `pos`.")
|
||||
fmt.line('#[allow(unused_variables,unused_assignments)]')
|
||||
with fmt.indented(
|
||||
'pub fn {}(dfg: &mut ir::DataFlowGraph, '
|
||||
'cfg: &mut ::flowgraph::ControlFlowGraph, '
|
||||
'pos: &mut ir::Cursor) -> '
|
||||
'pub fn {}(inst: ir::Inst, '
|
||||
'func: &mut ir::Function, '
|
||||
'cfg: &mut ::flowgraph::ControlFlowGraph) -> '
|
||||
'bool {{'.format(xgrp.name), '}'):
|
||||
fmt.line('use ir::{InstBuilder, CursorBase};')
|
||||
|
||||
# Gen the instruction to be legalized. The cursor we're passed must be
|
||||
# pointing at an instruction.
|
||||
fmt.line('let inst = pos.current_inst().expect("need instruction");')
|
||||
|
||||
# Group the xforms by opcode so we can generate a big switch.
|
||||
# Preserve ordering.
|
||||
xforms = defaultdict(list) # type: DefaultDict[str, List[XForm]]
|
||||
@@ -370,18 +366,23 @@ def gen_xform_group(xgrp, fmt, type_sets):
|
||||
inst = xform.src.rtl[0].expr.inst
|
||||
xforms[inst.camel_name].append(xform)
|
||||
|
||||
with fmt.indented('match dfg[inst].opcode() {', '}'):
|
||||
for camel_name in sorted(xforms.keys()):
|
||||
with fmt.indented(
|
||||
'ir::Opcode::{} => {{'.format(camel_name), '}'):
|
||||
for xform in xforms[camel_name]:
|
||||
gen_xform(xform, fmt, type_sets)
|
||||
# We'll assume there are uncovered opcodes.
|
||||
fmt.line('_ => {},')
|
||||
with fmt.indented('{', '}'):
|
||||
fmt.line(
|
||||
'let pos = &mut ir::Cursor::new(&mut func.layout)'
|
||||
'.at_inst(inst);')
|
||||
fmt.line('let dfg = &mut func.dfg;')
|
||||
with fmt.indented('match dfg[inst].opcode() {', '}'):
|
||||
for camel_name in sorted(xforms.keys()):
|
||||
with fmt.indented(
|
||||
'ir::Opcode::{} => {{'.format(camel_name), '}'):
|
||||
for xform in xforms[camel_name]:
|
||||
gen_xform(xform, fmt, type_sets)
|
||||
# We'll assume there are uncovered opcodes.
|
||||
fmt.line('_ => {},')
|
||||
|
||||
# If we fall through, nothing was expanded. Call the chain if any.
|
||||
if xgrp.chain:
|
||||
fmt.format('{}(dfg, cfg, pos)', xgrp.chain.rust_name())
|
||||
fmt.format('{}(inst, func, cfg)', xgrp.chain.rust_name())
|
||||
else:
|
||||
fmt.line('false')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user