Skip to content

Commit f5b48c5

Browse files
committed
Remove dead_stores HashSet and clean up pass
1 parent 45f9fa6 commit f5b48c5

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

zjit/src/hir.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,21 +5235,21 @@ impl Function {
52355235
}
52365236

52375237
for block in self.rpo() {
5238-
let mut dead_stores: HashSet<InsnId> = HashSet::new();
5238+
// TODO: Probably convert this to a vec of tuples? Time complexity is worse but constant factors are better
52395239
let mut active_stores: HashMap<StoreHeap, InsnId> = HashMap::new();
5240-
let mut insns = std::mem::take(&mut self.blocks[block.0].insns);
5241-
// TODO: Figure out if we should make the pass run backwards and do it all in one sweep
5242-
// Or if we should do it from top to bottom for readability, but require a second pass
5243-
for i in (0..insns.len()).rev() {
5244-
let insn_id = insns[i];
5240+
let insns = std::mem::take(&mut self.blocks[block.0].insns);
5241+
let mut new_insns = vec![];
5242+
for insn_id_ref in insns.iter().rev() {
5243+
// TODO: This is ugly, clean this up
5244+
let insn_id = *insn_id_ref;
52455245
match self.find(insn_id) {
52465246
Insn::StoreField { recv, offset, .. } => {
52475247
let key = StoreHeap { object: self.chase_insn(recv), offset };
52485248
// If an older store is being tracked, then there have
52495249
// been no usees between stores and the first store is
5250-
// dead.
5250+
// dead and should not be emitted.
52515251
if active_stores.contains_key(&key) {
5252-
dead_stores.insert(insn_id);
5252+
continue
52535253
}
52545254
// Otherwise, we have a new store to begin tracking.
52555255
// Because we don't have type based alias analysis, we
@@ -5289,18 +5289,21 @@ impl Function {
52895289
},
52905290
insn => {
52915291
// If the instruction can read memory, we cannot assume
5292-
// entries of active_stores are not loaded.
5293-
if insn.effects_of().includes(Effect::write(abstract_heaps::Memory)) {
5292+
// entries of active_stores are not loaded. This is because we use
5293+
// extended basic blocks and we should probably change this to be
5294+
// standard basic blocks.
5295+
if insn.effects_of().includes(Effect::read(abstract_heaps::Memory)) {
5296+
active_stores.clear();
5297+
}
5298+
else if insn.effects_of().includes(effects::Control) {
52945299
active_stores.clear();
52955300
}
52965301
}
5297-
52985302
}
5303+
new_insns.push(insn_id);
52995304
}
5300-
// TODO: Figure out how to remove extraneous write barriers
5301-
// Prune away any dead stores
5302-
insns.retain(|i| !dead_stores.contains(i));
5303-
self.blocks[block.0].insns = insns;
5305+
new_insns.reverse();
5306+
self.blocks[block.0].insns = new_insns;
53045307
}
53055308
}
53065309

0 commit comments

Comments
 (0)