Class: Optimize::Passes::InliningPass
- Inherits:
-
Optimize::Pass
- Object
- Optimize::Pass
- Optimize::Passes::InliningPass
- Defined in:
- lib/optimize/passes/inlining_pass.rb
Overview
v1: inline zero-arg FCALLs to constant-body callees. See docs/superpowers/specs/2026-04-21-pass-inlining-v1-design.md.
Constant Summary collapse
- INLINE_BUDGET =
max callee instructions INCLUDING the trailing leave
16- SEND_OPCODES =
%i[ send opt_send_without_block invokesuper invokesuperforward invokeblock opt_str_uminus opt_duparray_send opt_newarray_send ].freeze
- CONTROL_FLOW_OPCODES =
(IR::CFG::BRANCH_OPCODES + IR::CFG::JUMP_OPCODES + %i[opt_case_dispatch]).freeze
- ARG_PUSH_OPCODES =
Single-instruction arg-push opcodes v2 accepts for the one-arg shape.
%i[ putobject putnil putstring putobject_INT2FIX_0_ putobject_INT2FIX_1_ getlocal_WC_0 ].freeze
- NEW_SLOT_LINDEX =
VM_ENV_DATA_SIZE: the last-appended slot’s LINDEX is always 3.
3
Instance Method Summary collapse
- #apply(function, type_env:, log:, object_table: nil, callee_map: {}, slot_type_map: {}, **_extras) ⇒ Object
- #name ⇒ Object
- #one_shot? ⇒ Boolean
Instance Method Details
#apply(function, type_env:, log:, object_table: nil, callee_map: {}, slot_type_map: {}, **_extras) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/optimize/passes/inlining_pass.rb', line 40 def apply(function, type_env:, log:, object_table: nil, callee_map: {}, slot_type_map: {}, **_extras) _ = type_env return unless object_table slot_table = slot_type_map[function] insts = function.instructions return unless insts loop do changed = false i = 0 while i < insts.size b = insts[i] if b.opcode == :opt_send_without_block cd = b.operands[0] if cd.is_a?(IR::CallData) && cd.fcall? if try_inline(function, i, callee_map, object_table, log) changed = true insts = function.instructions next end elsif slot_table if try_inline_opt_send(function, i, callee_map, object_table, log, slot_table) changed = true insts = function.instructions next end end end i += 1 end break unless changed end end |
#name ⇒ Object
34 |
# File 'lib/optimize/passes/inlining_pass.rb', line 34 def name = :inlining |
#one_shot? ⇒ Boolean
36 37 38 |
# File 'lib/optimize/passes/inlining_pass.rb', line 36 def one_shot? true end |