(
function: &mut Function,
cfg: &HashMap<String, BasicBlockInfo>,
analysis_result: &DataflowResult,
data_types: &HashMap<String, DataType>,
)
| 102 | let mut optimized_blocks_intermediate: HashMap<String, BasicBlock> = HashMap::default(); |
| 103 | let mut optimized_successors: HashMap<String, HashSet<String>> = HashMap::default(); |
| 104 | let debug_locals = function |
| 105 | .debug_variables |
| 106 | .iter() |
| 107 | .map(|variable| variable.oomir_name.clone()) |
| 108 | .collect::<HashSet<_>>(); |
| 109 | // Populate all labels from the original CFG before the loop |
| 110 | let all_original_labels: HashSet<String> = cfg.keys().cloned().collect(); |
| 111 | |
| 112 | for (label, info) in cfg { |
| 113 | // Iterate using original CFG structure |
| 114 | let block_entry_state = analysis_result |
| 115 | .get(label) |
| 116 | .expect("Analysis result missing for block"); |
| 117 | |
| 118 | let (_, transformed_instructions) = |
| 119 | process_block_instructions(info, block_entry_state, true, data_types, &debug_locals); |
| 120 | |
| 121 | let optimized_block = BasicBlock { |
| 122 | label: label.clone(), |
| 123 | instructions: transformed_instructions, |
| 124 | }; |
| 125 | // Store the potentially optimized block using its original label |
| 126 | optimized_blocks_intermediate.insert(label.clone(), optimized_block); |
| 127 | |
| 128 | let mut current_successors = HashSet::default(); |
| 129 | // Get the block we just inserted to find its *new* terminator |
| 130 | if let Some(opt_block) = optimized_blocks_intermediate.get(label) { |
| 131 | if !opt_block.instructions.is_empty() { |
| 132 | let succ_labels = get_block_successors(opt_block); |
| 133 | // Filter successors against the set of original labels. |
| 134 | // This ensures edges are kept even if the target block hasn't |
| 135 | // been visited in this loop iteration yet. |
| 136 | current_successors.extend( |
| 137 | succ_labels |
| 138 | .into_iter() |
| 139 | .filter(|s| all_original_labels.contains(s)), |
| 140 | ); |
| 141 | } |
| 142 | } else { |
| 143 | // This case should likely not happen if we just inserted it |
| 144 | breadcrumbs::log!( |
| 145 | breadcrumbs::LogLevel::Warn, |
| 146 | "optimisation", |
| 147 | format!( |
| 148 | "Internal Warning: optimized block {} not found immediately after insertion.", |
| 149 | label |
| 150 | ) |
| 151 | ); |
| 152 | } |
| 153 | optimized_successors.insert(label.clone(), current_successors); |
| 154 | } |
| 155 | |
| 156 | let reachable_labels = find_reachable_blocks( |
| 157 | &function.body.entry, |
| 158 | &optimized_successors, |
| 159 | &all_original_labels, |
| 160 | ); |
| 161 |
no test coverage detected