MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / insert_phis_all

Function insert_phis_all

crates/rustc_codegen_spirv/src/linker/mem2reg.rs:159–206  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

157
158// Returns true if variables were rewritten
159fn 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)]
209struct VarInfo {

Callers 1

mem2regFunction · 0.85

Calls 9

collect_access_chainsFunction · 0.85
split_copy_memoryFunction · 0.85
insert_phisFunction · 0.85
apply_rewrite_rulesFunction · 0.85
remove_nopsFunction · 0.85
remove_old_variablesFunction · 0.85
iterMethod · 0.80
renameMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected