From 4ff0109ffdbafedbd3d2ca489d0b0cc7c980916c Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Fri, 7 Feb 2025 09:45:58 -0500 Subject: De-duplicate block starts --- zjit/src/ir.rs | 10 ++++++---- 1 file 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 { 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 { 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::>(); + result.sort(); + result } pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Function { -- cgit v1.2.3