Returns true if variables were rewritten
(
header: &mut ModuleHeader,
types_global_values: &mut Vec<Instruction>,
pointer_to_pointee: &FxHashMap<Word, Word>,
constants: &FxHashMap<Word, u32>,
blocks: &mut [Block],
dom
| 157 | |
| 158 | // Returns true if variables were rewritten |
| 159 | fn insert_phis_all( |
| 160 | header: &mut ModuleHeader, |
| 161 | types_global_values: &mut Vec<Instruction>, |
| 162 | pointer_to_pointee: &FxHashMap<Word, Word>, |
| 163 | constants: &FxHashMap<Word, u32>, |
| 164 | blocks: &mut [Block], |
| 165 | dominance_frontier: &[FxHashSet<usize>], |
| 166 | ) -> bool { |
| 167 | let var_maps_and_types = blocks[0] |
| 168 | .instructions |
| 169 | .iter() |
| 170 | .filter(|inst| inst.class.opcode == Op::Variable) |
| 171 | .filter_map(|inst| { |
| 172 | let var = inst.result_id.unwrap(); |
| 173 | let var_ty = *pointer_to_pointee.get(&inst.result_type.unwrap()).unwrap(); |
| 174 | Some(( |
| 175 | collect_access_chains(pointer_to_pointee, constants, blocks, var, var_ty)?, |
| 176 | var_ty, |
| 177 | )) |
| 178 | }) |
| 179 | .collect::<Vec<_>>(); |
| 180 | if var_maps_and_types.is_empty() { |
| 181 | return false; |
| 182 | } |
| 183 | for (var_map, _) in &var_maps_and_types { |
| 184 | split_copy_memory(header, blocks, var_map); |
| 185 | } |
| 186 | for &(ref var_map, base_var_type) in &var_maps_and_types { |
| 187 | let blocks_with_phi = insert_phis(blocks, dominance_frontier, var_map); |
| 188 | let mut renamer = Renamer { |
| 189 | header, |
| 190 | types_global_values, |
| 191 | blocks, |
| 192 | blocks_with_phi, |
| 193 | base_var_type, |
| 194 | var_map, |
| 195 | phi_defs: FxHashSet::default(), |
| 196 | visited: FxHashSet::default(), |
| 197 | stack: Vec::new(), |
| 198 | rewrite_rules: FxHashMap::default(), |
| 199 | }; |
| 200 | renamer.rename(0, None); |
| 201 | apply_rewrite_rules(&renamer.rewrite_rules, blocks); |
| 202 | remove_nops(blocks); |
| 203 | } |
| 204 | remove_old_variables(blocks, &var_maps_and_types); |
| 205 | true |
| 206 | } |
| 207 | |
| 208 | #[derive(Debug)] |
| 209 | struct VarInfo { |
no test coverage detected