From: Jean Privat Date: Mon, 10 Aug 2009 16:21:36 +0000 (-0400) Subject: icode: method inlining moves from IRoutine to ICodeBuilder X-Git-Tag: v0.3~68 X-Git-Url: http://nitlanguage.org icode: method inlining moves from IRoutine to ICodeBuilder Signed-off-by: Jean Privat --- diff --git a/src/analysis/inline_methods.nit b/src/analysis/inline_methods.nit index 8e174d4..0e37bec 100644 --- a/src/analysis/inline_methods.nit +++ b/src/analysis/inline_methods.nit @@ -22,27 +22,37 @@ import icode private class InlineMethodVisitor special ICodeVisitor var _pass: Int = 0 + var _icb: ICodeBuilder redef fun visit_icode(ic) do if ic isa ICall then var m = ic.property if m.iroutine != null and ic.is_inlinable then + var icb = _icb var ir = m.iroutine.as(not null) var seq = new ISeq + var old_seq = icb.seq + icb.seq = seq current_icode.insert_before(seq) - var e = ir.inline_in_seq(seq, ic.exprs) + var e = icb.inline_routine(ir, ic.exprs) var r = ic.result if r != null then assert e != null current_icode.insert_before(new IMove(r, e)) end current_icode.delete + icb.seq = old_seq visit_icode(seq) end end super end + + init(m: MMModule, r: IRoutine) + do + _icb = new ICodeBuilder(m, r) + end end redef class ICall @@ -60,7 +70,7 @@ end redef class IRoutine fun inline_methods(m: MMModule) do - var v = new InlineMethodVisitor + var v = new InlineMethodVisitor(m, self) v.visit_iroutine(self) end end diff --git a/src/compiling/compiling_global.nit b/src/compiling/compiling_global.nit index 745a523..bdc7e55 100644 --- a/src/compiling/compiling_global.nit +++ b/src/compiling/compiling_global.nit @@ -881,7 +881,7 @@ redef class MMLocalClass var ir = p.iroutine if ir == null then continue # FIXME: Not compatible with sep compilation - var e = ir.inline_in_seq(icb.seq, iselfa).as(not null) + var e = icb.inline_routine(ir, iselfa).as(not null) icb.stmt(new IAttrWrite(p, iself, e)) end end diff --git a/src/icode/icode_tools.nit b/src/icode/icode_tools.nit index 22be379..349ed1a 100644 --- a/src/icode/icode_tools.nit +++ b/src/icode/icode_tools.nit @@ -15,7 +15,7 @@ # limitations under the License. # Tools to manipulate intermediace nit code representation -import icode_base +import icode_builder # A simple visitor to visit icode structures class ICodeVisitor @@ -91,21 +91,20 @@ class ICodeVisitor end end -redef class IRoutine - # Inline an iroutine in an icode sequence - fun inline_in_seq(seq: ISeq, args: Sequence[IRegister]): nullable IRegister +redef class ICodeBuilder + # Inline an iroutine in the current icode sequence + fun inline_routine(routine: IRoutine, args: Sequence[IRegister]): nullable IRegister do var d = new ICodeDupContext - if args.length != params.length then print "{args.length} != {params.length}" - assert args.length == params.length + assert args.length == routine.params.length for i in [0..args.length[ do # FIXME The following assumes that params are readonly. # The alternative is safe but add one move :/ - d._registers[params[i]] = args[i] - #seq.icodes.add(new IMove(d.dup_ireg(params[i]), args[i])) + d._registers[routine.params[i]] = args[i] + #seq.icodes.add(new IMove(d.dup_ireg(routine.params[i]), args[i])) end - seq.icodes.add(body.dup_with(d)) - var r = result + seq.icodes.add(routine.body.dup_with(d)) + var r = routine.result if r != null then r = d.dup_ireg(r) return r end diff --git a/src/syntax/icode_generation.nit b/src/syntax/icode_generation.nit index cdceefc..e84d03b 100644 --- a/src/syntax/icode_generation.nit +++ b/src/syntax/icode_generation.nit @@ -1450,7 +1450,7 @@ redef class AClosureCallExpr v.add_assignment(r, r2) end v.seq = iif.else_seq - var r3 = closdecl_default.inline_in_seq(iif.else_seq, args) + var r3 = v.inline_routine(closdecl_default, args) if r != null then assert r3 != null v.add_assignment(r, r3)