(module: &Module, rooted: &mut FxIndexSet<Word>)
| 54 | } |
| 55 | |
| 56 | fn 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 | |
| 85 | fn root(inst: &Instruction, rooted: &mut FxIndexSet<Word>) -> bool { |
| 86 | let mut any = false; |
no test coverage detected