2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /** @file brw_dead_control_flow.cpp
26 * This file implements the dead control flow elimination optimization pass.
29 #include "brw_shader.h"
32 /* Look for and eliminate dead control flow:
35 * . else in else/endif
39 dead_control_flow_eliminate(backend_visitor
*v
)
41 bool progress
= false;
45 for (int b
= 0; b
< v
->cfg
->num_blocks
; b
++) {
46 bblock_t
*block
= v
->cfg
->blocks
[b
];
49 /* ENDIF instructions, by definition, can only be found at the start of
52 backend_instruction
*endif_inst
= block
->start
;
53 if (endif_inst
->opcode
!= BRW_OPCODE_ENDIF
)
56 backend_instruction
*if_inst
= NULL
, *else_inst
= NULL
;
57 backend_instruction
*prev_inst
= (backend_instruction
*) endif_inst
->prev
;
58 if (prev_inst
->opcode
== BRW_OPCODE_ELSE
) {
59 else_inst
= prev_inst
;
62 prev_inst
= (backend_instruction
*) prev_inst
->prev
;
65 if (prev_inst
->opcode
== BRW_OPCODE_IF
) {
69 /* Don't remove the ENDIF if we didn't find a dead IF. */
85 v
->invalidate_live_intervals();