Skip to content

Commit 64f548c

Browse files
committed
Remove unnecessary guard from YARVINSN_setlocal_wc_0, remove comments, and update tests.
1 parent 786a0d4 commit 64f548c

3 files changed

Lines changed: 51 additions & 87 deletions

File tree

zjit/src/hir.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6750,11 +6750,11 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
67506750
}
67516751
}
67526752
YARVINSN_setlocal_WC_0 => {
6753-
// TODO(Jacob): Modify this to use guards
67546753
let ep_offset = get_arg(pc, 0).as_u32();
67556754
const level: u32 = 0;
67566755
let ep = fun.push_insn(block, Insn::GetEP { level });
67576756
let val = state.stack_pop()?;
6757+
// In ZJIT, Insn::SetLocal only needs to be executed when ep is escaped
67586758
if ep_escaped || has_blockiseq { // TODO: figure out how to drop has_blockiseq here
67596759
// Write the local using EP
67606760
let exit_id = fun.push_insn(block, Insn::Snapshot { state: exit_state.without_locals() }); // skip spilling locals
@@ -6764,9 +6764,6 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
67646764
} else if local_inval {
67656765
// If there has been any non-leaf call since JIT entry or the last patch point,
67666766
// add a patch point to make sure locals have not been escaped.
6767-
let exit_id = fun.push_insn(block, Insn::Snapshot { state: exit_state.without_locals() }); // skip spilling locals
6768-
let flags = fun.push_insn(block, Insn::LoadField { recv: ep, id: ID!(_env_data_index_flags), offset: SIZEOF_VALUE_I32 * (VM_ENV_DATA_INDEX_FLAGS as i32), return_type: types::CInt64 });
6769-
fun.push_insn(block, Insn::GuardNoBitsSet { val: flags, mask: Const::CUInt64(VM_ENV_FLAG_WB_REQUIRED.into()), reason: SideExitReason::WriteBarrierRequired, state: exit_id });
67706767
fun.push_insn(block, Insn::PatchPoint { invariant: Invariant::NoEPEscape(iseq), state: exit_id });
67716768
local_inval = false;
67726769
}
@@ -6778,7 +6775,6 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
67786775
state.stack_push(fun.push_insn(block, Insn::GetLocal { ep_offset, level: 1, use_sp: false, rest_param: false }));
67796776
}
67806777
YARVINSN_setlocal_WC_1 => {
6781-
// TODO(Jacob): Modify this to use guards
67826778
let ep_offset = get_arg(pc, 0).as_u32();
67836779
const level: u32 = 1;
67846780
let ep = fun.push_insn(block, Insn::GetEP { level });
@@ -6792,8 +6788,6 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
67926788
state.stack_push(fun.push_insn(block, Insn::GetLocal { ep_offset, level, use_sp: false, rest_param: false }));
67936789
}
67946790
YARVINSN_setlocal => {
6795-
// TODO(Jacob): Make sure this works
6796-
// TODO(Jacob): Clean up the offset, levels, ep chasing, etc
67976791
let ep_offset = get_arg(pc, 0).as_u32();
67986792
let level = get_arg(pc, 1).as_u32();
67996793
let ep = fun.push_insn(block, Insn::GetEP { level });

zjit/src/hir/opt_tests.rs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,13 +1778,10 @@ mod hir_opt_tests {
17781778
v16:StringExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
17791779
v17:StringExact = StringCopy v16
17801780
v19:RangeExact = NewRange v14 NewRangeInclusive v17
1781-
v21:CPtr = GetEP 0
1782-
v23:CInt64 = LoadField v21, :_env_data_index_flags@0x1010
1783-
v24:CInt64 = GuardNoBitsSet v23, CUInt64(8)
17841781
PatchPoint NoEPEscape(test)
1785-
v28:Fixnum[0] = Const Value(0)
1782+
v25:Fixnum[0] = Const Value(0)
17861783
CheckInterrupts
1787-
Return v28
1784+
Return v25
17881785
");
17891786
}
17901787

@@ -1838,13 +1835,10 @@ mod hir_opt_tests {
18381835
Jump bb2(v5, v6)
18391836
bb2(v8:BasicObject, v9:NilClass):
18401837
v13:HashExact = NewHash
1841-
v15:CPtr = GetEP 0
1842-
v17:CInt64 = LoadField v15, :_env_data_index_flags@0x1000
1843-
v18:CInt64 = GuardNoBitsSet v17, CUInt64(8)
18441838
PatchPoint NoEPEscape(test)
1845-
v22:Fixnum[5] = Const Value(5)
1839+
v19:Fixnum[5] = Const Value(5)
18461840
CheckInterrupts
1847-
Return v22
1841+
Return v19
18481842
");
18491843
}
18501844

@@ -1873,13 +1867,10 @@ mod hir_opt_tests {
18731867
v19:StaticSymbol[:a] = Const Value(VALUE(0x1000))
18741868
v22:StaticSymbol[:b] = Const Value(VALUE(0x1008))
18751869
v25:HashExact = NewHash v19: v13, v22: v14
1876-
v27:CPtr = GetEP 0
1877-
v29:CInt64 = LoadField v27, :_env_data_index_flags@0x1010
1878-
v30:CInt64 = GuardNoBitsSet v29, CUInt64(8)
18791870
PatchPoint NoEPEscape(test)
1880-
v34:Fixnum[5] = Const Value(5)
1871+
v31:Fixnum[5] = Const Value(5)
18811872
CheckInterrupts
1882-
Return v34
1873+
Return v31
18831874
");
18841875
}
18851876

@@ -2439,13 +2430,10 @@ mod hir_opt_tests {
24392430
PatchPoint NoSingletonClass(Array@0x1000)
24402431
PatchPoint MethodRedefined(Array@0x1000, itself@0x1008, cme:0x1010)
24412432
IncrCounter inline_cfunc_optimized_send_count
2442-
v17:CPtr = GetEP 0
2443-
v19:CInt64 = LoadField v17, :_env_data_index_flags@0x1038
2444-
v20:CInt64 = GuardNoBitsSet v19, CUInt64(8)
24452433
PatchPoint NoEPEscape(test)
2446-
v24:Fixnum[1] = Const Value(1)
2434+
v21:Fixnum[1] = Const Value(1)
24472435
CheckInterrupts
2448-
Return v24
2436+
Return v21
24492437
");
24502438
}
24512439

@@ -2473,18 +2461,15 @@ mod hir_opt_tests {
24732461
bb2(v8:BasicObject, v9:NilClass):
24742462
PatchPoint SingleRactorMode
24752463
PatchPoint StableConstantNames(0x1000, M)
2476-
v32:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
2464+
v29:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
24772465
PatchPoint NoSingletonClass(Module@0x1010)
24782466
PatchPoint MethodRedefined(Module@0x1010, name@0x1018, cme:0x1020)
24792467
IncrCounter inline_cfunc_optimized_send_count
2480-
v37:StringExact|NilClass = CCall v32, :Module#name@0x1048
2481-
v18:CPtr = GetEP 0
2482-
v20:CInt64 = LoadField v18, :_env_data_index_flags@0x1050
2483-
v21:CInt64 = GuardNoBitsSet v20, CUInt64(8)
2468+
v34:StringExact|NilClass = CCall v29, :Module#name@0x1048
24842469
PatchPoint NoEPEscape(test)
2485-
v25:Fixnum[1] = Const Value(1)
2470+
v22:Fixnum[1] = Const Value(1)
24862471
CheckInterrupts
2487-
Return v25
2472+
Return v22
24882473
");
24892474
}
24902475

@@ -7536,18 +7521,15 @@ mod hir_opt_tests {
75367521
Jump bb2(v5, v6)
75377522
bb2(v8:BasicObject, v9:NilClass):
75387523
v13:HashExact = NewHash
7539-
v15:CPtr = GetEP 0
7540-
v17:CInt64 = LoadField v15, :_env_data_index_flags@0x1000
7541-
v18:CInt64 = GuardNoBitsSet v17, CUInt64(8)
75427524
PatchPoint NoEPEscape(test)
7543-
v25:Fixnum[1] = Const Value(1)
7544-
v27:Fixnum[3] = Const Value(3)
7545-
PatchPoint NoSingletonClass(Hash@0x1008)
7546-
PatchPoint MethodRedefined(Hash@0x1008, []=@0x1010, cme:0x1018)
7547-
HashAset v13, v25, v27
7525+
v22:Fixnum[1] = Const Value(1)
7526+
v24:Fixnum[3] = Const Value(3)
7527+
PatchPoint NoSingletonClass(Hash@0x1000)
7528+
PatchPoint MethodRedefined(Hash@0x1000, []=@0x1008, cme:0x1010)
7529+
HashAset v13, v22, v24
75487530
IncrCounter inline_cfunc_optimized_send_count
75497531
CheckInterrupts
7550-
Return v27
7532+
Return v24
75517533
");
75527534
}
75537535

zjit/src/hir/tests.rs

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,12 +2263,10 @@ pub mod hir_build_tests {
22632263
PatchPoint BOPRedefined(ARRAY_REDEFINED_OP_FLAG, BOP_HASH)
22642264
v33:Fixnum = ArrayHash v15, v16
22652265
v35:CPtr = GetEP 0
2266-
v37:CInt64 = LoadField v35, :_env_data_index_flags@0x1000
2267-
v38:CInt64 = GuardNoBitsSet v37, CUInt64(8)
22682266
PatchPoint NoEPEscape(test)
2269-
v43:ArrayExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
2270-
v44:ArrayExact = ArrayDup v43
2271-
v46:BasicObject = SendWithoutBlock v14, :puts, v44 # SendFallbackReason: Uncategorized(opt_send_without_block)
2267+
v40:ArrayExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
2268+
v41:ArrayExact = ArrayDup v40
2269+
v43:BasicObject = SendWithoutBlock v14, :puts, v41 # SendFallbackReason: Uncategorized(opt_send_without_block)
22722270
PatchPoint NoEPEscape(test)
22732271
CheckInterrupts
22742272
Return v33
@@ -2462,12 +2460,10 @@ pub mod hir_build_tests {
24622460
PatchPoint BOPRedefined(ARRAY_REDEFINED_OP_FLAG, BOP_INCLUDE_P)
24632461
v34:BoolExact = ArrayInclude v15, v16 | v16
24642462
v36:CPtr = GetEP 0
2465-
v38:CInt64 = LoadField v36, :_env_data_index_flags@0x1000
2466-
v39:CInt64 = GuardNoBitsSet v38, CUInt64(8)
24672463
PatchPoint NoEPEscape(test)
2468-
v44:ArrayExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
2469-
v45:ArrayExact = ArrayDup v44
2470-
v47:BasicObject = SendWithoutBlock v14, :puts, v45 # SendFallbackReason: Uncategorized(opt_send_without_block)
2464+
v41:ArrayExact[VALUE(0x1000)] = Const Value(VALUE(0x1000))
2465+
v42:ArrayExact = ArrayDup v41
2466+
v44:BasicObject = SendWithoutBlock v14, :puts, v42 # SendFallbackReason: Uncategorized(opt_send_without_block)
24712467
PatchPoint NoEPEscape(test)
24722468
CheckInterrupts
24732469
Return v34
@@ -3223,14 +3219,12 @@ pub mod hir_build_tests {
32233219
PatchPoint SingleRactorMode
32243220
v26:BasicObject = GetIvar v12, :@c
32253221
v29:CPtr = GetEP 0
3226-
v31:CInt64 = LoadField v29, :_env_data_index_flags@0x1000
3227-
v32:CInt64 = GuardNoBitsSet v31, CUInt64(8)
32283222
PatchPoint NoEPEscape(reverse_odd)
3229-
v35:CPtr = GetEP 0
3230-
v37:CPtr = GetEP 0
3231-
v43:ArrayExact = NewArray v20, v23, v26
3223+
v32:CPtr = GetEP 0
3224+
v34:CPtr = GetEP 0
3225+
v40:ArrayExact = NewArray v20, v23, v26
32323226
CheckInterrupts
3233-
Return v43
3227+
Return v40
32343228
32353229
fn reverse_even@<compiled>:8:
32363230
bb0():
@@ -3258,15 +3252,13 @@ pub mod hir_build_tests {
32583252
PatchPoint SingleRactorMode
32593253
v32:BasicObject = GetIvar v14, :@d
32603254
v35:CPtr = GetEP 0
3261-
v37:CInt64 = LoadField v35, :_env_data_index_flags@0x1000
3262-
v38:CInt64 = GuardNoBitsSet v37, CUInt64(8)
32633255
PatchPoint NoEPEscape(reverse_even)
3264-
v41:CPtr = GetEP 0
3265-
v43:CPtr = GetEP 0
3266-
v45:CPtr = GetEP 0
3267-
v52:ArrayExact = NewArray v23, v26, v29, v32
3256+
v38:CPtr = GetEP 0
3257+
v40:CPtr = GetEP 0
3258+
v42:CPtr = GetEP 0
3259+
v49:ArrayExact = NewArray v23, v26, v29, v32
32683260
CheckInterrupts
3269-
Return v52
3261+
Return v49
32703262
");
32713263
}
32723264

@@ -3480,27 +3472,25 @@ pub mod hir_build_tests {
34803472
bb2(v16:BasicObject, v17:BasicObject, v18:BasicObject, v19:BasicObject, v20:BasicObject, v21:NilClass):
34813473
v25:BasicObject = InvokeBuiltin dir_s_open, v16, v17, v18
34823474
v27:CPtr = GetEP 0
3483-
v29:CInt64 = LoadField v27, :_env_data_index_flags@0x1000
3484-
v30:CInt64 = GuardNoBitsSet v29, CUInt64(8)
34853475
PatchPoint NoEPEscape(open)
3486-
v34:CPtr = GetEP 0
3487-
v35:CInt64 = LoadField v34, :_env_data_index_flags@0x1000
3488-
v36:CInt64 = GuardNoBitsSet v35, CUInt64(512)
3489-
v37:CInt64 = LoadField v34, :_env_data_index_specval@0x1001
3490-
v38:CInt64 = GuardAnyBitSet v37, CUInt64(1)
3491-
v39:HeapObject[BlockParamProxy] = Const Value(VALUE(0x1008))
3492-
CheckInterrupts
3493-
v42:CBool[true] = Test v39
3494-
v43 = RefineType v39, Falsy
3495-
IfFalse v42, bb3(v16, v17, v18, v19, v20, v25)
3496-
v45:HeapObject[BlockParamProxy] = RefineType v39, Truthy
3497-
v49:BasicObject = InvokeBlock, v25 # SendFallbackReason: Uncategorized(invokeblock)
3498-
v52:BasicObject = InvokeBuiltin dir_s_close, v16, v25
3476+
v31:CPtr = GetEP 0
3477+
v32:CInt64 = LoadField v31, :_env_data_index_flags@0x1000
3478+
v33:CInt64 = GuardNoBitsSet v32, CUInt64(512)
3479+
v34:CInt64 = LoadField v31, :_env_data_index_specval@0x1001
3480+
v35:CInt64 = GuardAnyBitSet v34, CUInt64(1)
3481+
v36:HeapObject[BlockParamProxy] = Const Value(VALUE(0x1008))
3482+
CheckInterrupts
3483+
v39:CBool[true] = Test v36
3484+
v40 = RefineType v36, Falsy
3485+
IfFalse v39, bb3(v16, v17, v18, v19, v20, v25)
3486+
v42:HeapObject[BlockParamProxy] = RefineType v36, Truthy
3487+
v46:BasicObject = InvokeBlock, v25 # SendFallbackReason: Uncategorized(invokeblock)
3488+
v49:BasicObject = InvokeBuiltin dir_s_close, v16, v25
34993489
CheckInterrupts
3500-
Return v49
3501-
bb3(v58, v59, v60, v61, v62, v63):
3490+
Return v46
3491+
bb3(v55, v56, v57, v58, v59, v60):
35023492
CheckInterrupts
3503-
Return v63
3493+
Return v60
35043494
");
35053495
}
35063496

@@ -3890,10 +3880,8 @@ pub mod hir_build_tests {
38903880
v26:CInt64[0] = Const CInt64(0)
38913881
v27:BasicObject = ArrayAref v21, v26
38923882
v29:CPtr = GetEP 0
3893-
v31:CInt64 = LoadField v29, :_env_data_index_flags@0x1000
3894-
v32:CInt64 = GuardNoBitsSet v31, CUInt64(8)
38953883
PatchPoint NoEPEscape(test)
3896-
v35:CPtr = GetEP 0
3884+
v32:CPtr = GetEP 0
38973885
CheckInterrupts
38983886
Return v13
38993887
");

0 commit comments

Comments
 (0)