diff options
author | Takashi Kokubun <[email protected]> | 2023-01-02 14:11:06 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 22:11:20 -0800 |
commit | 21696ad81ec40cf9cd146836dc8c945f1e485774 (patch) | |
tree | f5d132f2f11c082512790d2c20804910bc658159 /lib/ruby_vm/mjit/compiler.rb | |
parent | 00c659d246784fe98114136bc3eb4d7f02cb071c (diff) |
Partly implement BOP assumption
Diffstat (limited to 'lib/ruby_vm/mjit/compiler.rb')
-rw-r--r-- | lib/ruby_vm/mjit/compiler.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index 3302b02ffa..56e23a1f77 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -1,10 +1,12 @@ require 'ruby_vm/mjit/assembler' +require 'ruby_vm/mjit/block' require 'ruby_vm/mjit/block_stub' require 'ruby_vm/mjit/code_block' require 'ruby_vm/mjit/context' require 'ruby_vm/mjit/exit_compiler' require 'ruby_vm/mjit/insn_compiler' require 'ruby_vm/mjit/instruction' +require 'ruby_vm/mjit/invariants' require 'ruby_vm/mjit/jit_state' module RubyVM::MJIT @@ -36,7 +38,7 @@ module RubyVM::MJIT @cb = CodeBlock.new(mem_block: mem_block, mem_size: mem_size / 2) @ocb = CodeBlock.new(mem_block: mem_block + mem_size / 2, mem_size: mem_size / 2, outlined: true) @exit_compiler = ExitCompiler.new - @insn_compiler = InsnCompiler.new(@ocb) + @insn_compiler = InsnCompiler.new(@ocb, @exit_compiler) end # Compile an ISEQ from its entry point. @@ -66,8 +68,7 @@ module RubyVM::MJIT # Prepare the jump target new_asm = Assembler.new.tap do |asm| jit = JITState.new(iseq: stub.iseq, cfp:) - index = (stub.pc - stub.iseq.body.iseq_encoded.to_i) / C.VALUE.size - compile_block(asm, jit:, index:, ctx: stub.ctx) + compile_block(asm, jit:, pc: stub.pc, ctx: stub.ctx) end # Rewrite the stub @@ -110,17 +111,24 @@ module RubyVM::MJIT end # @param asm [RubyVM::MJIT::Assembler] - def compile_block(asm, jit:, index: 0, ctx: Context.new) + def compile_block(asm, jit:, pc: jit.iseq.body.iseq_encoded.to_i, ctx: Context.new) + # Mark the block start address and prepare an exit code storage + jit.block = Block.new(pc:) + asm.block(jit.block) + + # Compile each insn iseq = jit.iseq + index = (pc - iseq.body.iseq_encoded.to_i) / C.VALUE.size while index < iseq.body.iseq_size insn = self.class.decode_insn(iseq.body.iseq_encoded[index]) jit.pc = (iseq.body.iseq_encoded + index).to_i case @insn_compiler.compile(jit, ctx, asm, insn) when EndBlock + # TODO: pad nops if entry exit exists break when CantCompile - @exit_compiler.compile_exit(jit, ctx, asm) + @exit_compiler.compile_side_exit(jit, ctx, asm) break end index += insn.len |