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