summaryrefslogtreecommitdiff
path: root/zjit
diff options
context:
space:
mode:
authorMax Bernstein <max.bernstein@shopify.com>2025-02-07 09:45:58 -0500
committerTakashi Kokubun <takashikkbn@gmail.com>2025-04-18 21:52:57 +0900
commit4ff0109ffdbafedbd3d2ca489d0b0cc7c980916c (patch)
treebcba73dc9c53410ca6781c083f34ea32094d462f /zjit
parentfdb4e24d562b1cd9611e24dcac8293e9727eedba (diff)
De-duplicate block starts
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13131
Diffstat (limited to 'zjit')
-rw-r--r--zjit/src/ir.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/zjit/src/ir.rs b/zjit/src/ir.rs
index a7dabd80bd..cd58fc6ab8 100644
--- a/zjit/src/ir.rs
+++ b/zjit/src/ir.rs
@@ -269,7 +269,7 @@ fn insn_idx_at_offset(idx: u32, offset: i64) -> u32 {
fn compute_jump_targets(iseq: *const rb_iseq_t) -> Vec<u32> {
let iseq_size = unsafe { get_iseq_encoded_size(iseq) };
let mut insn_idx = 0;
- let mut jump_targets = vec![];
+ let mut jump_targets = std::collections::HashSet::new();
while insn_idx < iseq_size {
// Get the current pc and opcode
let pc = unsafe { rb_iseq_pc_at_idx(iseq, insn_idx.into()) };
@@ -282,13 +282,15 @@ fn compute_jump_targets(iseq: *const rb_iseq_t) -> Vec<u32> {
match opcode {
YARVINSN_branchunless | YARVINSN_jump | YARVINSN_branchif | YARVINSN_branchnil => {
let offset = get_arg(pc, 0).as_i64();
- jump_targets.push(insn_idx_at_offset(insn_idx, offset));
+ jump_targets.insert(insn_idx_at_offset(insn_idx, offset));
}
- YARVINSN_leave => { jump_targets.push(insn_idx); }
+ YARVINSN_leave => { jump_targets.insert(insn_idx); }
_ => eprintln!("zjit: compute_jump_targets: unknown opcode `{}'", insn_name(opcode as usize)),
}
}
- jump_targets
+ let mut result = jump_targets.into_iter().collect::<Vec<_>>();
+ result.sort();
+ result
}
pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function {