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

Function mem2reg

crates/rustc_codegen_spirv/src/linker/mem2reg.rs:20–46  ·  view source on GitHub ↗
(
    header: &mut ModuleHeader,
    types_global_values: &mut Vec<Instruction>,
    pointer_to_pointee: &FxHashMap<Word, Word>,
    constants: &FxHashMap<Word, u32>,
    func: &mut Function,
)

Source from the content-addressed store, hash-verified

18use std::collections::hash_map;
19
20pub fn mem2reg(
21 header: &mut ModuleHeader,
22 types_global_values: &mut Vec<Instruction>,
23 pointer_to_pointee: &FxHashMap<Word, Word>,
24 constants: &FxHashMap<Word, u32>,
25 func: &mut Function,
26) {
27 let reachable = compute_reachable(&func.blocks);
28 let preds = compute_preds(&func.blocks, &reachable);
29 let idom = compute_idom(&preds, &reachable);
30 let dominance_frontier = compute_dominance_frontier(&preds, &idom);
31 loop {
32 let changed = insert_phis_all(
33 header,
34 types_global_values,
35 pointer_to_pointee,
36 constants,
37 &mut func.blocks,
38 &dominance_frontier,
39 );
40 if !changed {
41 break;
42 }
43 // mem2reg produces minimal SSA form, not pruned, so DCE the dead ones
44 super::dce::dce_phi(func);
45 }
46}
47
48fn label_to_index(blocks: &[Block], id: Word) -> usize {
49 blocks

Callers 1

linkFunction · 0.85

Calls 6

compute_reachableFunction · 0.85
compute_idomFunction · 0.85
insert_phis_allFunction · 0.85
dce_phiFunction · 0.85
compute_predsFunction · 0.70

Tested by

no test coverage detected