Skip to content

Commit c7cd7aa

Browse files
committed
Add chase and update tests
1 parent f39697d commit c7cd7aa

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

zjit/src/hir.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,7 +5068,7 @@ impl Function {
50685068
let insn_id = insns[i];
50695069
match self.find(insn_id) {
50705070
Insn::StoreField { recv, offset, .. } => {
5071-
let key = StoreHeap { object: recv, offset };
5071+
let key = StoreHeap { object: self.chase_insn(recv), offset };
50725072
// If an older store is being tracked, then there have
50735073
// been no usees between stores and the first store is
50745074
// dead.
@@ -5093,7 +5093,7 @@ impl Function {
50935093
// based alias analysis and the following call to prune
50945094
// stores is no longer used.
50955095
// Insn::LoadField { recv, offset, .. } => {
5096-
// let key = StoreHeap { object: recv, offset };
5096+
// let key = StoreHeap { object: self.chase_insn(recv), offset };
50975097
// active_stores.remove(&key);
50985098
Insn::LoadField{ offset, .. } => {
50995099
// Because we don't have type based alias analysis, we
@@ -5102,6 +5102,15 @@ impl Function {
51025102
// such keys that could alias.
51035103
prune_stores(&mut active_stores, offset);
51045104
}
5105+
Insn::WriteBarrier { .. } => {
5106+
// Currently, WriteBarrier write effects are Allocator and Memory when we'd really like them to be flags.
5107+
// We don't use LoadField for mark bits so we can ignore them for now.
5108+
// But flags does not exist in our effects abstract heap modeling and we don't want to add special casing to effects.
5109+
// This special casing in this pass here should be removed once we refine our effects system to provide greater granularity for WriteBarrier.
5110+
// TODO: use TBAA
5111+
let offset = RUBY_OFFSET_RBASIC_FLAGS;
5112+
prune_stores(&mut active_stores, offset);
5113+
},
51055114
insn => {
51065115
// If the instruction can read memory, we cannot assume
51075116
// entries of active_stores are not loaded.
@@ -5112,7 +5121,7 @@ impl Function {
51125121

51135122
}
51145123
}
5115-
// TODO: Figure out if we need to handle a write barrier special case. Do these also need to be removed after removing stores?
5124+
// TODO: Figure out how to remove extraneous write barriers
51165125
// Prune away any dead stores
51175126
insns.retain(|i| !dead_stores.contains(i));
51185127
self.blocks[block.0].insns = insns;

zjit/src/hir/opt_tests.rs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5287,14 +5287,12 @@ mod hir_opt_tests {
52875287
v30:CShape[0x1001] = GuardBitEquals v29, CShape(0x1001)
52885288
StoreField v28, :@foo@0x1002, v10
52895289
WriteBarrier v28, v10
5290-
v33:CShape[0x1003] = Const CShape(0x1003)
5291-
StoreField v28, :_shape_id@0x1000, v33
52925290
v14:HeapBasicObject = RefineType v6, HeapBasicObject
52935291
v17:Fixnum[2] = Const Value(2)
52945292
PatchPoint SingleRactorMode
5295-
StoreField v14, :@bar@0x1004, v17
5293+
StoreField v14, :@bar@0x1003, v17
52965294
WriteBarrier v14, v17
5297-
v40:CShape[0x1005] = Const CShape(0x1005)
5295+
v40:CShape[0x1004] = Const CShape(0x1004)
52985296
StoreField v14, :_shape_id@0x1000, v40
52995297
CheckInterrupts
53005298
Return v17
@@ -14401,21 +14399,17 @@ mod hir_opt_tests {
1440114399
v44:CShape[0x1001] = GuardBitEquals v43, CShape(0x1001)
1440214400
StoreField v42, :@a@0x1002, v10
1440314401
WriteBarrier v42, v10
14404-
v47:CShape[0x1003] = Const CShape(0x1003)
14405-
StoreField v42, :_shape_id@0x1000, v47
1440614402
v14:HeapBasicObject = RefineType v6, HeapBasicObject
1440714403
v17:Fixnum[2] = Const Value(2)
1440814404
PatchPoint SingleRactorMode
14409-
StoreField v14, :@b@0x1004, v17
14405+
StoreField v14, :@b@0x1003, v17
1441014406
WriteBarrier v14, v17
14411-
v54:CShape[0x1005] = Const CShape(0x1005)
14412-
StoreField v14, :_shape_id@0x1000, v54
1441314407
v21:HeapBasicObject = RefineType v14, HeapBasicObject
1441414408
v24:Fixnum[3] = Const Value(3)
1441514409
PatchPoint SingleRactorMode
14416-
StoreField v21, :@c@0x1006, v24
14410+
StoreField v21, :@c@0x1004, v24
1441714411
WriteBarrier v21, v24
14418-
v61:CShape[0x1007] = Const CShape(0x1007)
14412+
v61:CShape[0x1005] = Const CShape(0x1005)
1441914413
StoreField v21, :_shape_id@0x1000, v61
1442014414
v28:HeapBasicObject = RefineType v21, HeapBasicObject
1442114415
v31:Fixnum[4] = Const Value(4)
@@ -14752,21 +14746,17 @@ C.new
1475214746
v37:CShape[0x1001] = GuardBitEquals v36, CShape(0x1001)
1475314747
StoreField v35, :@a@0x1002, v10
1475414748
WriteBarrier v35, v10
14755-
v40:CShape[0x1003] = Const CShape(0x1003)
14756-
StoreField v35, :_shape_id@0x1000, v40
1475714749
v14:HeapBasicObject = RefineType v6, HeapBasicObject
1475814750
v17:Fixnum[2] = Const Value(2)
1475914751
PatchPoint SingleRactorMode
14760-
StoreField v14, :@b@0x1004, v17
14752+
StoreField v14, :@b@0x1003, v17
1476114753
WriteBarrier v14, v17
14762-
v47:CShape[0x1005] = Const CShape(0x1005)
14763-
StoreField v14, :_shape_id@0x1000, v47
1476414754
v21:HeapBasicObject = RefineType v14, HeapBasicObject
1476514755
v24:Fixnum[3] = Const Value(3)
1476614756
PatchPoint SingleRactorMode
14767-
StoreField v21, :@c@0x1006, v24
14757+
StoreField v21, :@c@0x1004, v24
1476814758
WriteBarrier v21, v24
14769-
v54:CShape[0x1007] = Const CShape(0x1007)
14759+
v54:CShape[0x1005] = Const CShape(0x1005)
1477014760
StoreField v21, :_shape_id@0x1000, v54
1477114761
CheckInterrupts
1477214762
Return v24
@@ -14842,29 +14832,22 @@ C.new
1484214832
v49:HeapBasicObject = GuardType v6, HeapBasicObject
1484314833
v50:CShape = LoadField v49, :_shape_id@0x1000
1484414834
v51:CShape[0x1001] = GuardBitEquals v50, CShape(0x1001)
14845-
StoreField v49, :@a@0x1002, v10
1484614835
WriteBarrier v49, v10
14847-
v54:CShape[0x1003] = Const CShape(0x1003)
14836+
v54:CShape[0x1002] = Const CShape(0x1002)
1484814837
StoreField v49, :_shape_id@0x1000, v54
1484914838
v14:HeapBasicObject = RefineType v6, HeapBasicObject
1485014839
v17:Fixnum[2] = Const Value(2)
1485114840
PatchPoint SingleRactorMode
14852-
StoreField v14, :@a@0x1002, v17
1485314841
WriteBarrier v14, v17
1485414842
v21:HeapBasicObject = RefineType v14, HeapBasicObject
1485514843
v24:Fixnum[3] = Const Value(3)
14856-
PatchPoint SingleRactorMode
14857-
StoreField v21, :@a@0x1002, v24
1485814844
WriteBarrier v21, v24
1485914845
v28:HeapBasicObject = RefineType v21, HeapBasicObject
1486014846
v31:Fixnum[4] = Const Value(4)
14861-
PatchPoint SingleRactorMode
14862-
StoreField v28, :@a@0x1002, v31
1486314847
WriteBarrier v28, v31
1486414848
v35:HeapBasicObject = RefineType v28, HeapBasicObject
1486514849
v38:Fixnum[5] = Const Value(5)
14866-
PatchPoint SingleRactorMode
14867-
StoreField v35, :@a@0x1002, v38
14850+
StoreField v35, :@a@0x1003, v38
1486814851
WriteBarrier v35, v38
1486914852
CheckInterrupts
1487014853
Return v38

0 commit comments

Comments
 (0)