diff options
| author | Max Bernstein <max.bernstein@shopify.com> | 2025-02-11 13:54:24 -0500 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-04-18 21:52:57 +0900 |
| commit | 01fbd0d5eebf5918acacc10b12a6a88daf06ffd9 (patch) | |
| tree | a9095ec5fd85ff369b17ddd2397c116f2dbb4a25 | |
| parent | 805c0baa39fad1c1e179f8cced237f254de02082 (diff) | |
Don't re-visit blocks
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13131
| -rw-r--r-- | zjit/src/ir.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/zjit/src/ir.rs b/zjit/src/ir.rs index 482252cd0b..6c9639e495 100644 --- a/zjit/src/ir.rs +++ b/zjit/src/ir.rs @@ -2,7 +2,7 @@ #![allow(non_upper_case_globals)] use crate::cruby::*; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct InsnId(usize); @@ -284,7 +284,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 = std::collections::HashSet::new(); + let mut jump_targets = 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()) }; @@ -339,8 +339,12 @@ pub fn iseq_to_ssa(iseq: *const rb_iseq_t) -> Result<Function, ParseError> { let mut queue = std::collections::VecDeque::new(); queue.push_back((FrameState::new(), fun.entry_block, /*insn_idx=*/0 as u32)); + let mut visited = HashSet::new(); + let iseq_size = unsafe { get_iseq_encoded_size(iseq) }; while let Some((incoming_state, block, mut insn_idx)) = queue.pop_front() { + if visited.contains(&block) { continue; } + visited.insert(block); let mut state = { let mut result = FrameState::new(); let mut idx = 0; |
