summaryrefslogtreecommitdiff
path: root/lib/ruby_vm/mjit/exit_compiler.rb
diff options
context:
space:
mode:
authorTakashi Kokubun <[email protected]>2023-01-02 14:11:06 -0800
committerTakashi Kokubun <[email protected]>2023-03-05 22:11:20 -0800
commit21696ad81ec40cf9cd146836dc8c945f1e485774 (patch)
treef5d132f2f11c082512790d2c20804910bc658159 /lib/ruby_vm/mjit/exit_compiler.rb
parent00c659d246784fe98114136bc3eb4d7f02cb071c (diff)
Partly implement BOP assumption
Diffstat (limited to 'lib/ruby_vm/mjit/exit_compiler.rb')
-rw-r--r--lib/ruby_vm/mjit/exit_compiler.rb41
1 files changed, 33 insertions, 8 deletions
diff --git a/lib/ruby_vm/mjit/exit_compiler.rb b/lib/ruby_vm/mjit/exit_compiler.rb
index bec2eab514..4577f65e20 100644
--- a/lib/ruby_vm/mjit/exit_compiler.rb
+++ b/lib/ruby_vm/mjit/exit_compiler.rb
@@ -5,16 +5,31 @@ module RubyVM::MJIT
@gc_refs = []
end
+ # Used for invalidating a block on entry.
+ # @param pc [Integer]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def compile_entry_exit(pc, asm, cause:)
+ # Increment per-insn exit counter
+ incr_insn_exit(pc)
+
+ # TODO: Saving pc and sp may be needed later
+
+ # Restore callee-saved registers
+ asm.comment("#{cause}: entry exit")
+ asm.pop(SP)
+ asm.pop(EC)
+ asm.pop(CFP)
+
+ asm.mov(:rax, Qundef)
+ asm.ret
+ end
+
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::Assembler]
- def compile_exit(jit, ctx, asm)
- if C.mjit_opts.stats
- insn = decode_insn(C.VALUE.new(jit.pc).*)
- asm.comment("increment insn exit: #{insn.name}")
- asm.mov(:rax, (C.mjit_insn_exits + insn.bin).to_i)
- asm.add([:rax], 1) # TODO: lock
- end
+ def compile_side_exit(jit, ctx, asm)
+ # Increment per-insn exit counter
+ incr_insn_exit(jit.pc)
# Fix pc/sp offsets for the interpreter
save_pc_and_sp(jit, ctx, asm)
@@ -50,11 +65,21 @@ module RubyVM::MJIT
private
+ # @param pc [Integer]
+ def incr_insn_exit(pc)
+ if C.mjit_opts.stats
+ insn = decode_insn(C.VALUE.new(pc).*)
+ asm.comment("increment insn exit: #{insn.name}")
+ asm.mov(:rax, (C.mjit_insn_exits + insn.bin).to_i)
+ asm.add([:rax], 1) # TODO: lock
+ end
+ end
+
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
# @param asm [RubyVM::MJIT::Assembler]
def save_pc_and_sp(jit, ctx, asm)
- # Update pc
+ # Update pc (TODO: manage PC offset?)
asm.comment("save pc #{'and sp' if ctx.sp_offset != 0}")
asm.mov(:rax, jit.pc) # rax = jit.pc
asm.mov([CFP, C.rb_control_frame_t.offsetof(:pc)], :rax) # cfp->pc = rax