Skip to content

Commit 2ccb44c

Browse files
authored
ZJIT: Don't use find() in infer_types (ruby#16283)
No need to materialize the whole instruction; if/when we need the operands, do the union-find lookup per operand. This saves on allocation time.
1 parent a81c3eb commit 2ccb44c

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

zjit/src/hir.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,9 @@ impl Function {
26992699
let newly_reachable = reachable.insert($target.target);
27002700
let mut target_changed = newly_reachable;
27012701
for (idx, arg) in $target.args.iter().enumerate() {
2702+
let arg = self.union_find.borrow().find_const(*arg);
27022703
let param = $self.blocks[$target.target.0].params[idx];
2704+
let param = self.union_find.borrow().find_const(param);
27032705
let new = self.insn_types[param.0].union(self.insn_types[arg.0]);
27042706
if !self.insn_types[param.0].bit_equal(new) {
27052707
self.insn_types[param.0] = new;
@@ -2717,37 +2719,38 @@ impl Function {
27172719
in_worklist.remove(block);
27182720
if !reachable.get(block) { continue; }
27192721
for insn_id in &self.blocks[block.0].insns {
2720-
let insn_type = match self.find(*insn_id) {
2721-
Insn::IfTrue { val, target } => {
2722+
let insn_id = self.union_find.borrow().find_const(*insn_id);
2723+
let insn_type = match &self.insns[insn_id.0] {
2724+
&Insn::IfTrue { val, ref target } => {
27222725
assert!(!self.type_of(val).bit_equal(types::Empty));
27232726
if self.type_of(val).could_be(Type::from_cbool(true)) {
27242727
enqueue!(self, target);
27252728
}
27262729
continue;
27272730
}
2728-
Insn::IfFalse { val, target } => {
2731+
&Insn::IfFalse { val, ref target } => {
27292732
assert!(!self.type_of(val).bit_equal(types::Empty));
27302733
if self.type_of(val).could_be(Type::from_cbool(false)) {
27312734
enqueue!(self, target);
27322735
}
27332736
continue;
27342737
}
2735-
Insn::Jump(target) => {
2738+
&Insn::Jump(ref target) => {
27362739
enqueue!(self, target);
27372740
continue;
27382741
}
2739-
Insn::Entries { targets } => {
2740-
for target in &targets {
2742+
&Insn::Entries { ref targets } => {
2743+
for target in targets {
27412744
if reachable.insert(*target) {
27422745
worklist_add!(*target);
27432746
}
27442747
}
27452748
continue;
27462749
}
2747-
insn if insn.has_output() => self.infer_type(*insn_id),
2750+
insn if insn.has_output() => self.infer_type(insn_id),
27482751
_ => continue,
27492752
};
2750-
if !self.type_of(*insn_id).bit_equal(insn_type) {
2753+
if !self.type_of(insn_id).bit_equal(insn_type) {
27512754
self.insn_types[insn_id.0] = insn_type;
27522755
}
27532756
}

0 commit comments

Comments
 (0)