Skip to content

Commit 1e1d833

Browse files
committed
ZJIT: Remove GetLEP
Use get_lvar_level and GetEP instead.
1 parent 5d87dd6 commit 1e1d833

5 files changed

Lines changed: 37 additions & 42 deletions

File tree

zjit/src/codegen.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
601601
Insn::LoadEC => gen_load_ec(),
602602
Insn::LoadSP => gen_load_sp(),
603603
&Insn::GetEP { level } => gen_get_ep(asm, level),
604-
Insn::GetLEP => gen_get_lep(jit, asm),
605604
Insn::LoadSelf => gen_load_self(),
606605
&Insn::LoadField { recv, id, offset, return_type } => gen_load_field(asm, opnd!(recv), id, offset, return_type),
607606
&Insn::StoreField { recv, id, offset, val } => no_output!(gen_store_field(asm, opnd!(recv), id, offset, opnd!(val), function.type_of(val))),
@@ -630,18 +629,6 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
630629
/// Gets the EP of the ISeq of the containing method, or "local level".
631630
/// Equivalent of GET_LEP() macro.
632631
fn gen_get_lep(jit: &JITState, asm: &mut Assembler) -> Opnd {
633-
// Equivalent of get_lvar_level() in compile.c
634-
fn get_lvar_level(mut iseq: IseqPtr) -> u32 {
635-
let local_iseq = unsafe { rb_get_iseq_body_local_iseq(iseq) };
636-
let mut level = 0;
637-
while iseq != local_iseq {
638-
iseq = unsafe { rb_get_iseq_body_parent_iseq(iseq) };
639-
level += 1;
640-
}
641-
642-
level
643-
}
644-
645632
let level = get_lvar_level(jit.iseq);
646633
gen_get_ep(asm, level)
647634
}

zjit/src/cruby.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,18 @@ pub fn iseq_name(iseq: IseqPtr) -> String {
831831
}
832832
}
833833

834+
// Equivalent of get_lvar_level() in compile.c
835+
pub fn get_lvar_level(mut iseq: IseqPtr) -> u32 {
836+
let local_iseq = unsafe { rb_get_iseq_body_local_iseq(iseq) };
837+
let mut level = 0;
838+
while iseq != local_iseq {
839+
iseq = unsafe { rb_get_iseq_body_parent_iseq(iseq) };
840+
level += 1;
841+
}
842+
843+
level
844+
}
845+
834846
// Location is the file defining the method, colon, method name.
835847
// Filenames are sometimes internal strings supplied to eval,
836848
// so be careful with them.

zjit/src/cruby_methods.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ fn inline_kernel_block_given_p(fun: &mut hir::Function, block: hir::BlockId, _re
333333

334334
let local_iseq = unsafe { rb_get_iseq_body_local_iseq(fun.iseq()) };
335335
if unsafe { rb_get_iseq_body_type(local_iseq) } == ISEQ_TYPE_METHOD {
336-
let lep = fun.push_insn(block, hir::Insn::GetLEP);
336+
// Get the EP of the ISeq of the containing method, or "local level", skipping over block-level EPs.
337+
// Equivalent of GET_LEP() macro.
338+
let level = crate::cruby::get_lvar_level(fun.iseq());
339+
let lep = fun.push_insn(block, hir::Insn::GetEP { level });
337340
Some(fun.push_insn(block, hir::Insn::IsBlockGiven { lep }))
338341
} else {
339342
Some(fun.push_insn(block, hir::Insn::Const { val: hir::Const::Value(Qfalse) }))

zjit/src/hir.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -884,10 +884,6 @@ pub enum Insn {
884884
/// Get the EP at the given level from the current CFP.
885885
GetEP { level: u32 },
886886

887-
/// Get the EP of the ISeq of the containing method, or "local level", skipping over block-level EPs.
888-
/// Equivalent of GET_LEP() macro.
889-
GetLEP,
890-
891887
/// Own a FrameState so that instructions can look up their dominating FrameState when
892888
/// generating deopt side-exits and frame reconstruction metadata. Does not directly generate
893889
/// any code.
@@ -1179,7 +1175,6 @@ impl Insn {
11791175
Insn::LoadEC { .. } => effects::Empty,
11801176
Insn::LoadSP { .. } => effects::Empty,
11811177
Insn::GetEP { .. } => effects::Empty,
1182-
Insn::GetLEP { .. } => effects::Empty,
11831178
Insn::LoadSelf { .. } => Effect::read_write(abstract_heaps::Frame, abstract_heaps::Empty),
11841179
Insn::LoadField { .. } => Effect::read_write(abstract_heaps::Memory, abstract_heaps::Empty),
11851180
Insn::StoreField { .. } => effects::Any,
@@ -1666,7 +1661,6 @@ impl<'a> std::fmt::Display for InsnPrinter<'a> {
16661661
Insn::LoadEC => write!(f, "LoadEC"),
16671662
Insn::LoadSP => write!(f, "LoadSP"),
16681663
&Insn::GetEP { level } => write!(f, "GetEP {level}"),
1669-
Insn::GetLEP => write!(f, "GetLEP"),
16701664
Insn::LoadSelf => write!(f, "LoadSelf"),
16711665
&Insn::LoadField { recv, id, offset, return_type: _ } => {
16721666
let field_name = if id_is_empty(id) {
@@ -2259,7 +2253,6 @@ impl Function {
22592253
| LoadSP
22602254
| LoadEC
22612255
| GetEP {..}
2262-
| GetLEP
22632256
| LoadSelf
22642257
| IncrCounterPtr {..}
22652258
| IncrCounter(_)) => result.clone(),
@@ -2599,7 +2592,6 @@ impl Function {
25992592
Insn::LoadSP => types::CPtr,
26002593
Insn::LoadEC => types::CPtr,
26012594
Insn::GetEP { .. } => types::CPtr,
2602-
Insn::GetLEP => types::CPtr,
26032595
Insn::LoadSelf => types::BasicObject,
26042596
&Insn::LoadField { return_type, .. } => return_type,
26052597
Insn::GetSpecialSymbol { .. } => types::BasicObject,
@@ -3537,7 +3529,10 @@ impl Function {
35373529
state
35383530
});
35393531

3540-
let lep = fun.push_insn(block, Insn::GetLEP);
3532+
// Get the EP of the ISeq of the containing method, or "local level", skipping over block-level EPs.
3533+
// Equivalent of GET_LEP() macro.
3534+
let level = get_lvar_level(fun.iseq);
3535+
let lep = fun.push_insn(block, Insn::GetEP { level });
35413536
// Load ep[VM_ENV_DATA_INDEX_ME_CREF]
35423537
let method_entry = fun.push_insn(block, Insn::LoadField { recv: lep, id: ID!(_ep_method_entry), offset: SIZEOF_VALUE_I32 * VM_ENV_DATA_INDEX_ME_CREF, return_type: types::RubyValue });
35433538
// Guard that it matches the expected CME
@@ -4733,7 +4728,6 @@ impl Function {
47334728
| &Insn::LoadSP
47344729
| &Insn::LoadEC
47354730
| &Insn::GetEP { .. }
4736-
| &Insn::GetLEP
47374731
| &Insn::LoadSelf
47384732
| &Insn::PutSpecialObject { .. }
47394733
| &Insn::IncrCounter(_)
@@ -5601,7 +5595,6 @@ impl Function {
56015595
| Insn::LoadSP
56025596
| Insn::LoadEC
56035597
| Insn::GetEP { .. }
5604-
| Insn::GetLEP
56055598
| Insn::LoadSelf
56065599
| Insn::Snapshot { .. }
56075600
| Insn::Jump { .. }

zjit/src/hir/opt_tests.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,7 @@ mod hir_opt_tests {
32363236
PatchPoint NoSingletonClass(Object@0x1000)
32373237
PatchPoint MethodRedefined(Object@0x1000, block_given?@0x1008, cme:0x1010)
32383238
v20:HeapObject[class_exact*:Object@VALUE(0x1000)] = GuardType v6, HeapObject[class_exact*:Object@VALUE(0x1000)]
3239-
v21:CPtr = GetLEP
3239+
v21:CPtr = GetEP 0
32403240
v22:BoolExact = IsBlockGiven v21
32413241
IncrCounter inline_cfunc_optimized_send_count
32423242
CheckInterrupts
@@ -8753,7 +8753,7 @@ mod hir_opt_tests {
87538753
test = PushSubArray.new
87548754
test << 1
87558755
");
8756-
assert_snapshot!(hir_string_proc("PushSubArray.new.method(:<<)"), @"
8756+
assert_snapshot!(hir_string_proc("PushSubArray.new.method(:<<)"), @r"
87578757
fn <<@<compiled>:3:
87588758
bb1():
87598759
EntryPoint interpreter
@@ -8768,7 +8768,7 @@ mod hir_opt_tests {
87688768
Jump bb3(v6, v7)
87698769
bb3(v9:BasicObject, v10:BasicObject):
87708770
PatchPoint MethodRedefined(Array@0x1008, <<@0x1010, cme:0x1018)
8771-
v23:CPtr = GetLEP
8771+
v23:CPtr = GetEP 0
87728772
v24:RubyValue = LoadField v23, :_ep_method_entry@0x1040
87738773
v25:CallableMethodEntry[VALUE(0x1048)] = GuardBitEquals v24, Value(VALUE(0x1048))
87748774
v26:RubyValue = LoadField v23, :_ep_specval@0x1050
@@ -8802,12 +8802,12 @@ mod hir_opt_tests {
88028802
Jump bb3(v4)
88038803
bb3(v6:BasicObject):
88048804
PatchPoint MethodRedefined(Array@0x1000, pop@0x1008, cme:0x1010)
8805-
v18:CPtr = GetLEP
8805+
v18:CPtr = GetEP 0
88068806
v19:RubyValue = LoadField v18, :_ep_method_entry@0x1038
88078807
v20:CallableMethodEntry[VALUE(0x1040)] = GuardBitEquals v19, Value(VALUE(0x1040))
88088808
v21:RubyValue = LoadField v18, :_ep_specval@0x1048
88098809
v22:FalseClass = GuardBitEquals v21, Value(false)
8810-
v28:CPtr = GetLEP
8810+
v28:CPtr = GetEP 0
88118811
v29:RubyValue = LoadField v28, :_ep_method_entry@0x1038
88128812
v30:CallableMethodEntry[VALUE(0x1040)] = GuardBitEquals v29, Value(VALUE(0x1040))
88138813
v31:RubyValue = LoadField v28, :_ep_specval@0x1048
@@ -8831,7 +8831,7 @@ mod hir_opt_tests {
88318831
test = ArefSubArray.new([1])
88328832
test[0]
88338833
");
8834-
assert_snapshot!(hir_string_proc("ArefSubArray.new.method(:[])"), @"
8834+
assert_snapshot!(hir_string_proc("ArefSubArray.new.method(:[])"), @r"
88358835
fn []@<compiled>:3:
88368836
bb1():
88378837
EntryPoint interpreter
@@ -8846,12 +8846,12 @@ mod hir_opt_tests {
88468846
Jump bb3(v6, v7)
88478847
bb3(v9:BasicObject, v10:BasicObject):
88488848
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
8849-
v23:CPtr = GetLEP
8849+
v23:CPtr = GetEP 0
88508850
v24:RubyValue = LoadField v23, :_ep_method_entry@0x1040
88518851
v25:CallableMethodEntry[VALUE(0x1048)] = GuardBitEquals v24, Value(VALUE(0x1048))
88528852
v26:RubyValue = LoadField v23, :_ep_specval@0x1050
88538853
v27:FalseClass = GuardBitEquals v26, Value(false)
8854-
v37:CPtr = GetLEP
8854+
v37:CPtr = GetEP 0
88558855
v38:RubyValue = LoadField v37, :_ep_method_entry@0x1040
88568856
v39:CallableMethodEntry[VALUE(0x1048)] = GuardBitEquals v38, Value(VALUE(0x1048))
88578857
v40:RubyValue = LoadField v37, :_ep_specval@0x1050
@@ -8879,7 +8879,7 @@ mod hir_opt_tests {
88798879
test = ArefSubArrayRange.new([1, 2, 3])
88808880
test[0..1]
88818881
");
8882-
assert_snapshot!(hir_string_proc("ArefSubArrayRange.new.method(:[])"), @"
8882+
assert_snapshot!(hir_string_proc("ArefSubArrayRange.new.method(:[])"), @r"
88838883
fn []@<compiled>:3:
88848884
bb1():
88858885
EntryPoint interpreter
@@ -8894,7 +8894,7 @@ mod hir_opt_tests {
88948894
Jump bb3(v6, v7)
88958895
bb3(v9:BasicObject, v10:BasicObject):
88968896
PatchPoint MethodRedefined(Array@0x1008, []@0x1010, cme:0x1018)
8897-
v23:CPtr = GetLEP
8897+
v23:CPtr = GetEP 0
88988898
v24:RubyValue = LoadField v23, :_ep_method_entry@0x1040
88998899
v25:CallableMethodEntry[VALUE(0x1048)] = GuardBitEquals v24, Value(VALUE(0x1048))
89008900
v26:RubyValue = LoadField v23, :_ep_specval@0x1050
@@ -12629,7 +12629,7 @@ mod hir_opt_tests {
1262912629
Jump bb3(v4)
1263012630
bb3(v6:BasicObject):
1263112631
PatchPoint MethodRedefined(A@0x1000, foo@0x1008, cme:0x1010)
12632-
v18:CPtr = GetLEP
12632+
v18:CPtr = GetEP 0
1263312633
v19:RubyValue = LoadField v18, :_ep_method_entry@0x1038
1263412634
v20:CallableMethodEntry[VALUE(0x1040)] = GuardBitEquals v19, Value(VALUE(0x1040))
1263512635
v21:RubyValue = LoadField v18, :_ep_specval@0x1048
@@ -12686,7 +12686,7 @@ mod hir_opt_tests {
1268612686
assert!(!hir.contains("InvokeSuper "), "InvokeSuper should optimize to SendDirect but got:\n{hir}");
1268712687
assert!(hir.contains("SendDirect"), "Should optimize to SendDirect for call without args or block:\n{hir}");
1268812688

12689-
assert_snapshot!(hir, @"
12689+
assert_snapshot!(hir, @r"
1269012690
fn foo@<compiled>:10:
1269112691
bb1():
1269212692
EntryPoint interpreter
@@ -12701,7 +12701,7 @@ mod hir_opt_tests {
1270112701
Jump bb3(v6, v7)
1270212702
bb3(v9:BasicObject, v10:BasicObject):
1270312703
PatchPoint MethodRedefined(A@0x1008, foo@0x1010, cme:0x1018)
12704-
v28:CPtr = GetLEP
12704+
v28:CPtr = GetEP 0
1270512705
v29:RubyValue = LoadField v28, :_ep_method_entry@0x1040
1270612706
v30:CallableMethodEntry[VALUE(0x1048)] = GuardBitEquals v29, Value(VALUE(0x1048))
1270712707
v31:RubyValue = LoadField v28, :_ep_specval@0x1050
@@ -12827,7 +12827,7 @@ mod hir_opt_tests {
1282712827
Jump bb3(v4)
1282812828
bb3(v6:BasicObject):
1282912829
PatchPoint MethodRedefined(Hash@0x1000, size@0x1008, cme:0x1010)
12830-
v18:CPtr = GetLEP
12830+
v18:CPtr = GetEP 0
1283112831
v19:RubyValue = LoadField v18, :_ep_method_entry@0x1038
1283212832
v20:CallableMethodEntry[VALUE(0x1040)] = GuardBitEquals v19, Value(VALUE(0x1040))
1283312833
v21:RubyValue = LoadField v18, :_ep_specval@0x1048
@@ -12862,7 +12862,7 @@ mod hir_opt_tests {
1286212862
Jump bb3(v4)
1286312863
bb3(v6:BasicObject):
1286412864
PatchPoint MethodRedefined(BasicObject@0x1000, initialize@0x1008, cme:0x1010)
12865-
v18:CPtr = GetLEP
12865+
v18:CPtr = GetEP 0
1286612866
v19:RubyValue = LoadField v18, :_ep_method_entry@0x1038
1286712867
v20:CallableMethodEntry[VALUE(0x1040)] = GuardBitEquals v19, Value(VALUE(0x1040))
1286812868
v21:RubyValue = LoadField v18, :_ep_specval@0x1048
@@ -12890,7 +12890,7 @@ mod hir_opt_tests {
1289012890
assert!(!hir.contains("InvokeSuper "), "InvokeSuper should optimize to CCallVariadic but got:\n{hir}");
1289112891
assert!(hir.contains("CCallVariadic"), "Should optimize to CCallVariadic for variadic cfunc:\n{hir}");
1289212892

12893-
assert_snapshot!(hir, @"
12893+
assert_snapshot!(hir, @r"
1289412894
fn byteindex@<compiled>:3:
1289512895
bb1():
1289612896
EntryPoint interpreter
@@ -12920,7 +12920,7 @@ mod hir_opt_tests {
1292012920
Jump bb5(v16, v17, v18)
1292112921
bb5(v28:BasicObject, v29:BasicObject, v30:BasicObject):
1292212922
PatchPoint MethodRedefined(String@0x1018, byteindex@0x1020, cme:0x1028)
12923-
v44:CPtr = GetLEP
12923+
v44:CPtr = GetEP 0
1292412924
v45:RubyValue = LoadField v44, :_ep_method_entry@0x1050
1292512925
v46:CallableMethodEntry[VALUE(0x1058)] = GuardBitEquals v45, Value(VALUE(0x1058))
1292612926
v47:RubyValue = LoadField v44, :_ep_specval@0x1060

0 commit comments

Comments
 (0)