diff options
author | ywenc <[email protected]> | 2025-06-12 18:05:04 -0400 |
---|---|---|
committer | Alan Wu <[email protected]> | 2025-06-20 01:19:38 +0900 |
commit | 38d38bd5ceec57d13c1c5250f2e0d0c88c4c47f0 () | |
tree | c4e9d99e0a96f65048270bc2987ebc39e1056ec9 | |
parent | 34eaa6418e5c5b8639add323dbfd531b32a7d4a3 (diff) |
ZJIT: objtostring to HIR
Add a fast path for known strings at compile time, otherwise calls method id to_s using Insn::SendWithoutBlock Co-authored-by: composerinteralia <[email protected]> More specific test name in zjit/src/hir.rs Co-authored-by: Max Bernstein <[email protected]>
Notes: Merged: https://.com/ruby/ruby/pull/13627
-rw-r--r-- | zjit/src/hir.rs | 89 |
1 files changed, 89 insertions, 0 deletions
@@ -496,6 +496,9 @@ pub enum Insn { FixnumGt { left: InsnId, right: InsnId }, FixnumGe { left: InsnId, right: InsnId }, /// Side-exit if val doesn't have the expected type. GuardType { val: InsnId, guard_type: Type, state: InsnId }, /// Side-exit if val is not the expected VALUE. @@ -695,6 +698,7 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> { Insn::ToNewArray { val, .. } => write!(f, "ToNewArray {val}"), Insn::ArrayExtend { left, right, .. } => write!(f, "ArrayExtend {left}, {right}"), Insn::ArrayPush { array, val, .. } => write!(f, "ArrayPush {array}, {val}"), Insn::SideExit { .. } => write!(f, "SideExit"), Insn::PutSpecialObject { value_type } => { write!(f, "PutSpecialObject {}", value_type) @@ -1013,6 +1017,12 @@ impl Function { FixnumLt { left, right } => FixnumLt { left: find!(*left), right: find!(*right) }, FixnumLe { left, right } => FixnumLe { left: find!(*left), right: find!(*right) }, PutSpecialObject { value_type } => PutSpecialObject { value_type: *value_type }, SendWithoutBlock { self_val, call_info, cd, args, state } => SendWithoutBlock { self_val: find!(*self_val), call_info: call_info.clone(), @@ -1143,6 +1153,7 @@ impl Function { Insn::GetIvar { .. } => types::BasicObject, Insn::ToNewArray { .. } => types::ArrayExact, Insn::ToArray { .. } => types::ArrayExact, } } @@ -1386,6 +1397,15 @@ impl Function { let replacement = self.push_insn(block, Insn::Const { val: Const::Value(unsafe { (*ice).value }) }); self.make_equal_to(insn_id, replacement); } _ => { self.push_insn_id(block, insn_id); } } } @@ -1758,6 +1778,10 @@ impl Function { worklist.push_back(val); worklist.push_back(state); } Insn::GetGlobal { state, .. } | Insn::SideExit { state } => worklist.push_back(state), } @@ -2677,6 +2701,26 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> { let insn_id = fun.push_insn(block, Insn::InvokeBuiltin { bf, args, state: exit_id }); state.stack_push(insn_id); } _ => { // Unknown opcode; side-exit into the interpreter let exit_id = fun.push_insn(block, Insn::Snapshot { state: exit_state }); @@ -4344,6 +4388,21 @@ mod tests { Return v20 "#]]); } } #[cfg(test)] @@ -5902,4 +5961,34 @@ mod opt_tests { Return v7 "#]]); } } |