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

Function spread_roots

crates/rustc_codegen_spirv/src/linker/dce.rs:56–83  ·  view source on GitHub ↗
(module: &Module, rooted: &mut FxIndexSet<Word>)

Source from the content-addressed store, hash-verified

54}
55
56fn spread_roots(module: &Module, rooted: &mut FxIndexSet<Word>) -> bool {
57 let mut any = false;
58 for inst in module.global_inst_iter() {
59 if let Some(id) = inst.result_id {
60 if rooted.contains(&id) {
61 any |= root(inst, rooted);
62 }
63 }
64 }
65 for func in &module.functions {
66 if rooted.contains(&func.def_id().unwrap()) {
67 // NB (Mobius 2021) - since later insts are much more likely to reference
68 // earlier insts, by reversing the iteration order, we're more likely to root the
69 // entire relevant function at once.
70 // See https://github.com/EmbarkStudios/rust-gpu/pull/691#discussion_r681477091
71 for inst in all_inst_iter(func).rev() {
72 if !instruction_is_pure(inst) {
73 any |= root(inst, rooted);
74 } else if let Some(id) = inst.result_id {
75 if rooted.contains(&id) {
76 any |= root(inst, rooted);
77 }
78 }
79 }
80 }
81 }
82 any
83}
84
85fn root(inst: &Instruction, rooted: &mut FxIndexSet<Word>) -> bool {
86 let mut any = false;

Callers 1

dceFunction · 0.85

Calls 3

rootFunction · 0.85
all_inst_iterFunction · 0.85
instruction_is_pureFunction · 0.85

Tested by

no test coverage detected