Skip to content

Commit af17ded

Browse files
committed
ZJIT: Update GuardSuperMethodEntry to use GetLEP
1 parent d1bea77 commit af17ded

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

zjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
454454
Insn::GuardNotShared { recv, state } => gen_guard_not_shared(jit, asm, opnd!(recv), &function.frame_state(*state)),
455455
&Insn::GuardLess { left, right, state } => gen_guard_less(jit, asm, opnd!(left), opnd!(right), &function.frame_state(state)),
456456
&Insn::GuardGreaterEq { left, right, state } => gen_guard_greater_eq(jit, asm, opnd!(left), opnd!(right), &function.frame_state(state)),
457-
&Insn::GuardSuperMethodEntry { cme, state } => no_output!(gen_guard_super_method_entry(jit, asm, cme, &function.frame_state(state))),
457+
&Insn::GuardSuperMethodEntry { lep, cme, state } => no_output!(gen_guard_super_method_entry(jit, asm, opnd!(lep), cme, &function.frame_state(state))),
458458
Insn::GetBlockHandler => gen_get_block_handler(jit, asm),
459459
Insn::PatchPoint { invariant, state } => no_output!(gen_patch_point(jit, asm, invariant, &function.frame_state(*state))),
460460
Insn::CCall { cfunc, recv, args, name, return_type: _, elidable: _ } => gen_ccall(asm, *cfunc, *name, opnd!(recv), opnds!(args)),
@@ -724,11 +724,11 @@ fn gen_guard_greater_eq(jit: &JITState, asm: &mut Assembler, left: Opnd, right:
724724
fn gen_guard_super_method_entry(
725725
jit: &JITState,
726726
asm: &mut Assembler,
727+
lep: Opnd,
727728
cme: *const rb_callable_method_entry_t,
728729
state: &FrameState,
729730
) {
730731
asm_comment!(asm, "guard super method entry");
731-
let lep = gen_get_lep(jit, asm);
732732
let ep_me_opnd = Opnd::mem(64, lep, SIZEOF_VALUE_I32 * VM_ENV_DATA_INDEX_ME_CREF);
733733
let ep_me = asm.load(ep_me_opnd);
734734
asm.cmp(ep_me, Opnd::UImm(cme as u64));

zjit/src/hir.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ pub enum Insn {
10161016
GuardLess { left: InsnId, right: InsnId, state: InsnId },
10171017
/// Side-exit if the method entry at ep[VM_ENV_DATA_INDEX_ME_CREF] doesn't match the expected CME.
10181018
/// Used to ensure super calls are made from the expected method context.
1019-
GuardSuperMethodEntry { cme: *const rb_callable_method_entry_t, state: InsnId },
1019+
GuardSuperMethodEntry { lep: InsnId, cme: *const rb_callable_method_entry_t, state: InsnId },
10201020
/// Get the block handler from ep[VM_ENV_DATA_INDEX_SPECVAL] at the local EP (LEP).
10211021
GetBlockHandler,
10221022

@@ -1515,7 +1515,7 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
15151515
Insn::GuardNotShared { recv, .. } => write!(f, "GuardNotShared {recv}"),
15161516
Insn::GuardLess { left, right, .. } => write!(f, "GuardLess {left}, {right}"),
15171517
Insn::GuardGreaterEq { left, right, .. } => write!(f, "GuardGreaterEq {left}, {right}"),
1518-
Insn::GuardSuperMethodEntry { cme, .. } => write!(f, "GuardSuperMethodEntry {:p}", self.ptr_map.map_ptr(cme)),
1518+
Insn::GuardSuperMethodEntry { lep, cme, .. } => write!(f, "GuardSuperMethodEntry {lep}, {:p}", self.ptr_map.map_ptr(cme)),
15191519
Insn::GetBlockHandler => write!(f, "GetBlockHandler"),
15201520
Insn::PatchPoint { invariant, .. } => { write!(f, "PatchPoint {}", invariant.print(self.ptr_map)) },
15211521
Insn::GetConstantPath { ic, .. } => { write!(f, "GetConstantPath {:p}", self.ptr_map.map_ptr(ic)) },
@@ -2180,7 +2180,7 @@ impl Function {
21802180
&GuardNotShared { recv, state } => GuardNotShared { recv: find!(recv), state },
21812181
&GuardGreaterEq { left, right, state } => GuardGreaterEq { left: find!(left), right: find!(right), state },
21822182
&GuardLess { left, right, state } => GuardLess { left: find!(left), right: find!(right), state },
2183-
&GuardSuperMethodEntry { cme, state } => GuardSuperMethodEntry { cme, state },
2183+
&GuardSuperMethodEntry { lep, cme, state } => GuardSuperMethodEntry { lep: find!(lep), cme, state },
21842184
&GetBlockHandler => GetBlockHandler,
21852185
&FixnumAdd { left, right, state } => FixnumAdd { left: find!(left), right: find!(right), state },
21862186
&FixnumSub { left, right, state } => FixnumSub { left: find!(left), right: find!(right), state },
@@ -3421,7 +3421,12 @@ impl Function {
34213421
});
34223422

34233423
// Guard that we're calling `super` from the expected method context.
3424-
self.push_insn(block, Insn::GuardSuperMethodEntry { cme: current_cme, state });
3424+
let lep = self.push_insn(block, Insn::GetLEP);
3425+
self.push_insn(block, Insn::GuardSuperMethodEntry {
3426+
lep,
3427+
cme: current_cme,
3428+
state
3429+
});
34253430

34263431
// Guard that no block is being passed (implicit or explicit).
34273432
let block_handler = self.push_insn(block, Insn::GetBlockHandler);
@@ -4598,12 +4603,15 @@ impl Function {
45984603
worklist.push_back(val);
45994604
}
46004605
&Insn::GuardBlockParamProxy { state, .. } |
4601-
&Insn::GuardSuperMethodEntry { state, .. } |
46024606
&Insn::GetGlobal { state, .. } |
46034607
&Insn::GetSpecialSymbol { state, .. } |
46044608
&Insn::GetSpecialNumber { state, .. } |
46054609
&Insn::ObjectAllocClass { state, .. } |
46064610
&Insn::SideExit { state, .. } => worklist.push_back(state),
4611+
&Insn::GuardSuperMethodEntry { lep, state, .. } => {
4612+
worklist.push_back(lep);
4613+
worklist.push_back(state);
4614+
}
46074615
&Insn::UnboxFixnum { val } => worklist.push_back(val),
46084616
&Insn::FixnumAref { recv, index } => {
46094617
worklist.push_back(recv);

zjit/src/hir/opt_tests.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10943,12 +10943,13 @@ mod hir_opt_tests {
1094310943
Jump bb2(v4)
1094410944
bb2(v6:BasicObject):
1094510945
PatchPoint MethodRedefined(A@0x1000, foo@0x1008, cme:0x1010)
10946-
GuardSuperMethodEntry 0x1038
10947-
v18:RubyValue = GetBlockHandler
10948-
v19:FalseClass = GuardBitEquals v18, Value(false)
10949-
v20:BasicObject = SendWithoutBlockDirect v6, :foo (0x1040)
10946+
v17:CPtr = GetLEP
10947+
GuardSuperMethodEntry v17, 0x1038
10948+
v19:RubyValue = GetBlockHandler
10949+
v20:FalseClass = GuardBitEquals v19, Value(false)
10950+
v21:BasicObject = SendWithoutBlockDirect v6, :foo (0x1040)
1095010951
CheckInterrupts
10951-
Return v20
10952+
Return v21
1095210953
");
1095310954
}
1095410955

@@ -10986,17 +10987,18 @@ mod hir_opt_tests {
1098610987
Jump bb2(v5, v6)
1098710988
bb2(v8:BasicObject, v9:BasicObject):
1098810989
PatchPoint MethodRedefined(A@0x1000, foo@0x1008, cme:0x1010)
10989-
GuardSuperMethodEntry 0x1038
10990-
v27:RubyValue = GetBlockHandler
10991-
v28:FalseClass = GuardBitEquals v27, Value(false)
10992-
v29:BasicObject = SendWithoutBlockDirect v8, :foo (0x1040), v9
10990+
v26:CPtr = GetLEP
10991+
GuardSuperMethodEntry v26, 0x1038
10992+
v28:RubyValue = GetBlockHandler
10993+
v29:FalseClass = GuardBitEquals v28, Value(false)
10994+
v30:BasicObject = SendWithoutBlockDirect v8, :foo (0x1040), v9
1099310995
v17:Fixnum[1] = Const Value(1)
1099410996
PatchPoint MethodRedefined(Integer@0x1048, +@0x1050, cme:0x1058)
10995-
v32:Fixnum = GuardType v29, Fixnum
10996-
v33:Fixnum = FixnumAdd v32, v17
10997+
v33:Fixnum = GuardType v30, Fixnum
10998+
v34:Fixnum = FixnumAdd v33, v17
1099710999
IncrCounter inline_cfunc_optimized_send_count
1099811000
CheckInterrupts
10999-
Return v33
11001+
Return v34
1100011002
");
1100111003
}
1100211004

0 commit comments

Comments
 (0)