summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-03 22:45:25 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 23:28:59 -0800
commitf2ef352ee0bfa65cef8242740ab7ba5a831d1934 (patch)
tree517d6ebe9b21e3aed600fe1025f499ecb4f185ac
parent89f8e20aa410fa0728b638a92adca114a71706c0 (diff)
Implement opt_str_freeze
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb22
-rw-r--r--mjit_c.rb4
-rwxr-xr-xtool/mjit/bindgen.rb1
3 files changed, 24 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index fa6ab2071c..d245ff2ce2 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -24,7 +24,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 69/101
+ # 70/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -79,7 +79,7 @@ module RubyVM::MJIT
when :send then send(jit, ctx, asm)
when :opt_send_without_block then opt_send_without_block(jit, ctx, asm)
when :objtostring then objtostring(jit, ctx, asm)
- # opt_str_freeze
+ when :opt_str_freeze then opt_str_freeze(jit, ctx, asm)
when :opt_nil_p then opt_nil_p(jit, ctx, asm)
# opt_str_uminus
# opt_newarray_max
@@ -1016,7 +1016,23 @@ module RubyVM::MJIT
end
end
- # opt_str_freeze
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def opt_str_freeze(jit, ctx, asm)
+ unless Invariants.assume_bop_not_redefined(jit, C.STRING_REDEFINED_OP_FLAG, C.BOP_FREEZE)
+ return CantCompile;
+ end
+
+ str = jit.operand(0, ruby: true)
+
+ # Push the return value onto the stack
+ stack_ret = ctx.stack_push
+ asm.mov(:rax, to_value(str))
+ asm.mov(stack_ret, :rax)
+
+ KeepCompiling
+ end
# @param jit [RubyVM::MJIT::JITState]
# @param ctx [RubyVM::MJIT::Context]
diff --git a/mjit_c.rb b/mjit_c.rb
index 97e2987e25..de5c421714 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -547,6 +547,10 @@ module RubyVM::MJIT # :nodoc: all
Primitive.cexpr! %q{ UINT2NUM(BOP_EQ) }
end
+ def C.BOP_FREEZE
+ Primitive.cexpr! %q{ UINT2NUM(BOP_FREEZE) }
+ end
+
def C.BOP_GE
Primitive.cexpr! %q{ UINT2NUM(BOP_GE) }
end
diff --git a/tool/mjit/bindgen.rb b/tool/mjit/bindgen.rb
index b2ec9e27bd..749965de7d 100755
--- a/tool/mjit/bindgen.rb
+++ b/tool/mjit/bindgen.rb
@@ -365,6 +365,7 @@ generator = BindingGenerator.new(
BOP_MOD
BOP_OR
BOP_PLUS
+ BOP_FREEZE
ARRAY_REDEFINED_OP_FLAG
HASH_REDEFINED_OP_FLAG
INTEGER_REDEFINED_OP_FLAG