pan/midgard: Move DCE into its own file
[mesa.git] / src / panfrost / midgard / midgard_opt_dce.c
1 /*
2 * Copyright (C) 2018 Alyssa Rosenzweig
3 * Copyright (C) 2019 Collabora, Ltd.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25 #include "compiler.h"
26
27 /* Basic dead code elimination on the MIR itself */
28
29 bool
30 midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block)
31 {
32 bool progress = false;
33
34 mir_foreach_instr_in_block_safe(block, ins) {
35 if (ins->type != TAG_ALU_4) continue;
36 if (ins->compact_branch) continue;
37
38 if (ins->ssa_args.dest >= SSA_FIXED_MINIMUM) continue;
39 if (mir_is_live_after(ctx, block, ins, ins->ssa_args.dest)) continue;
40
41 mir_remove_instruction(ins);
42 progress = true;
43 }
44
45 return progress;
46 }