Skip to content

Commit 92193fc

Browse files
committed
ZJIT: Update GetBlockHandler to use GetLEP
1 parent af17ded commit 92193fc

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

zjit/src/codegen.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
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)),
457457
&Insn::GuardSuperMethodEntry { lep, cme, state } => no_output!(gen_guard_super_method_entry(jit, asm, opnd!(lep), cme, &function.frame_state(state))),
458-
Insn::GetBlockHandler => gen_get_block_handler(jit, asm),
458+
Insn::GetBlockHandler { lep } => gen_get_block_handler(asm, opnd!(lep)),
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)),
461461
// Give up CCallWithFrame for 7+ args since asm.ccall() supports at most 6 args (recv + args).
@@ -736,9 +736,8 @@ fn gen_guard_super_method_entry(
736736
}
737737

738738
/// Get the block handler from ep[VM_ENV_DATA_INDEX_SPECVAL] at the local EP (LEP).
739-
fn gen_get_block_handler(jit: &JITState, asm: &mut Assembler) -> Opnd {
739+
fn gen_get_block_handler(asm: &mut Assembler, lep: Opnd) -> Opnd {
740740
asm_comment!(asm, "get block handler from LEP");
741-
let lep = gen_get_lep(jit, asm);
742741
asm.load(Opnd::mem(64, lep, SIZEOF_VALUE_I32 * VM_ENV_DATA_INDEX_SPECVAL))
743742
}
744743

zjit/src/hir.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ pub enum Insn {
10181018
/// Used to ensure super calls are made from the expected method context.
10191019
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).
1021-
GetBlockHandler,
1021+
GetBlockHandler { lep: InsnId },
10221022

10231023
/// Generate no code (or padding if necessary) and insert a patch point
10241024
/// that can be rewritten to a side exit when the Invariant is broken.
@@ -1516,7 +1516,7 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
15161516
Insn::GuardLess { left, right, .. } => write!(f, "GuardLess {left}, {right}"),
15171517
Insn::GuardGreaterEq { left, right, .. } => write!(f, "GuardGreaterEq {left}, {right}"),
15181518
Insn::GuardSuperMethodEntry { lep, cme, .. } => write!(f, "GuardSuperMethodEntry {lep}, {:p}", self.ptr_map.map_ptr(cme)),
1519-
Insn::GetBlockHandler => write!(f, "GetBlockHandler"),
1519+
Insn::GetBlockHandler { lep } => write!(f, "GetBlockHandler {lep}"),
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)) },
15221522
Insn::IsBlockGiven => { write!(f, "IsBlockGiven") },
@@ -2181,7 +2181,7 @@ impl Function {
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 },
21832183
&GuardSuperMethodEntry { lep, cme, state } => GuardSuperMethodEntry { lep: find!(lep), cme, state },
2184-
&GetBlockHandler => GetBlockHandler,
2184+
&GetBlockHandler { lep } => GetBlockHandler { lep: find!(lep) },
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 },
21872187
&FixnumMult { left, right, state } => FixnumMult { left: find!(left), right: find!(right), state },
@@ -2476,7 +2476,7 @@ impl Function {
24762476
Insn::AnyToString { .. } => types::String,
24772477
Insn::GetLocal { rest_param: true, .. } => types::ArrayExact,
24782478
Insn::GetLocal { .. } => types::BasicObject,
2479-
Insn::GetBlockHandler => types::RubyValue,
2479+
Insn::GetBlockHandler { .. } => types::RubyValue,
24802480
// The type of Snapshot doesn't really matter; it's never materialized. It's used only
24812481
// as a reference for FrameState, which we use to generate side-exit code.
24822482
Insn::Snapshot { .. } => types::Any,
@@ -3429,7 +3429,7 @@ impl Function {
34293429
});
34303430

34313431
// Guard that no block is being passed (implicit or explicit).
3432-
let block_handler = self.push_insn(block, Insn::GetBlockHandler);
3432+
let block_handler = self.push_insn(block, Insn::GetBlockHandler { lep });
34333433
self.push_insn(block, Insn::GuardBitEquals {
34343434
val: block_handler,
34353435
expected: Const::Value(VALUE(VM_BLOCK_HANDLER_NONE as usize)),
@@ -4373,12 +4373,14 @@ impl Function {
43734373
| &Insn::GetLEP
43744374
| &Insn::LoadSelf
43754375
| &Insn::GetLocal { .. }
4376-
| &Insn::GetBlockHandler
43774376
| &Insn::PutSpecialObject { .. }
43784377
| &Insn::IsBlockGiven
43794378
| &Insn::IncrCounter(_)
43804379
| &Insn::IncrCounterPtr { .. } =>
43814380
{}
4381+
&Insn::GetBlockHandler { lep } => {
4382+
worklist.push_back(lep);
4383+
}
43824384
&Insn::PatchPoint { state, .. }
43834385
| &Insn::CheckInterrupts { state }
43844386
| &Insn::GetConstantPath { ic: _, state } => {
@@ -5123,7 +5125,7 @@ impl Function {
51235125
| Insn::EntryPoint { .. }
51245126
| Insn::GuardBlockParamProxy { .. }
51255127
| Insn::GuardSuperMethodEntry { .. }
5126-
| Insn::GetBlockHandler
5128+
| Insn::GetBlockHandler { .. }
51275129
| Insn::PatchPoint { .. }
51285130
| Insn::SideExit { .. }
51295131
| Insn::IncrCounter { .. }

zjit/src/hir/opt_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10945,7 +10945,7 @@ mod hir_opt_tests {
1094510945
PatchPoint MethodRedefined(A@0x1000, foo@0x1008, cme:0x1010)
1094610946
v17:CPtr = GetLEP
1094710947
GuardSuperMethodEntry v17, 0x1038
10948-
v19:RubyValue = GetBlockHandler
10948+
v19:RubyValue = GetBlockHandler v17
1094910949
v20:FalseClass = GuardBitEquals v19, Value(false)
1095010950
v21:BasicObject = SendWithoutBlockDirect v6, :foo (0x1040)
1095110951
CheckInterrupts
@@ -10989,7 +10989,7 @@ mod hir_opt_tests {
1098910989
PatchPoint MethodRedefined(A@0x1000, foo@0x1008, cme:0x1010)
1099010990
v26:CPtr = GetLEP
1099110991
GuardSuperMethodEntry v26, 0x1038
10992-
v28:RubyValue = GetBlockHandler
10992+
v28:RubyValue = GetBlockHandler v26
1099310993
v29:FalseClass = GuardBitEquals v28, Value(false)
1099410994
v30:BasicObject = SendWithoutBlockDirect v8, :foo (0x1040), v9
1099510995
v17:Fixnum[1] = Const Value(1)

0 commit comments

Comments
 (0)