Debian Codegraph @

src/nouveau/compiler/nak/opt_crs.rs

raw
1 // Copyright © 2022 Collabora, Ltd.
2 // SPDX-License-Identifier: MIT
3
4 use crate::ir::*;
5
6 use rustc_hash::FxHashSet;
7
8 fn opt_crs(f: &mut Function) {
9 let mut live_targets: FxHashSet<Label> = Default::default();
10 for b in f.blocks.iter() {
11 let Some(instr) = b.instrs.last() else {
12 continue;
13 };
14
15 match &instr.op {
16 Op::Sync(OpSync { target })
17 | Op::Brk(OpBrk { target })
18 | Op::Cont(OpCont { target }) => {
19 live_targets.insert(*target);
20 }
21 _ => (),
22 }
23 }
24
25 f.map_instrs(|instr, _| match &instr.op {
26 Op::SSy(OpSSy { target })
27 | Op::PBk(OpPBk { target })
28 | Op::PCnt(OpPCnt { target }) => {
29 if live_targets.contains(target) {
30 MappedInstrs::One(instr)
31 } else {
32 MappedInstrs::None
33 }
34 }
35 _ => MappedInstrs::One(instr),
36 });
37 }
38
39 impl Shader<'_> {
40 pub fn opt_crs(&mut self) {
41 for f in &mut self.functions {
42 opt_crs(f);
43 }
44 }
45 }