summaryrefslogtreecommitdiff
path: root/lib/mesa/src/compiler/nir/nir_opt_remove_phis.c
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2016-05-29 10:21:21 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2016-05-29 10:21:21 +0000
commit99b70277b7a71ca729b7723c0be213c9db46702c (patch)
tree756afa5d954f14d117bad3856a5eb9d5ab1b1a0d /lib/mesa/src/compiler/nir/nir_opt_remove_phis.c
parent3e40341f9dcd7c1bbc9afb8ddb812304820396cf (diff)
Import Mesa 11.2.2
Diffstat (limited to 'lib/mesa/src/compiler/nir/nir_opt_remove_phis.c')
-rw-r--r--lib/mesa/src/compiler/nir/nir_opt_remove_phis.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/lib/mesa/src/compiler/nir/nir_opt_remove_phis.c b/lib/mesa/src/compiler/nir/nir_opt_remove_phis.c
index b20ff7291..646183707 100644
--- a/lib/mesa/src/compiler/nir/nir_opt_remove_phis.c
+++ b/lib/mesa/src/compiler/nir/nir_opt_remove_phis.c
@@ -26,27 +26,6 @@
*/
#include "nir.h"
-#include "nir_builder.h"
-
-static nir_alu_instr *
-get_parent_mov(nir_ssa_def *ssa)
-{
- if (ssa->parent_instr->type != nir_instr_type_alu)
- return NULL;
-
- nir_alu_instr *alu = nir_instr_as_alu(ssa->parent_instr);
- return (alu->op == nir_op_imov || alu->op == nir_op_fmov) ? alu : NULL;
-}
-
-static bool
-matching_mov(nir_alu_instr *mov1, nir_ssa_def *ssa)
-{
- if (!mov1)
- return false;
-
- nir_alu_instr *mov2 = get_parent_mov(ssa);
- return mov2 && nir_alu_srcs_equal(mov1, mov2, 0, 0);
-}
/*
* This is a pass for removing phi nodes that look like:
@@ -64,21 +43,20 @@ matching_mov(nir_alu_instr *mov1, nir_ssa_def *ssa)
*/
static bool
-remove_phis_block(nir_block *block, nir_builder *b)
+remove_phis_block(nir_block *block, void *state)
{
- bool progress = false;
+ bool *progress = state;
- nir_foreach_instr_safe(instr, block) {
+ nir_foreach_instr_safe(block, instr) {
if (instr->type != nir_instr_type_phi)
break;
nir_phi_instr *phi = nir_instr_as_phi(instr);
nir_ssa_def *def = NULL;
- nir_alu_instr *mov = NULL;
bool srcs_same = true;
- nir_foreach_phi_src(src, phi) {
+ nir_foreach_phi_src(phi, src) {
assert(src->src.is_ssa);
/* For phi nodes at the beginning of loops, we may encounter some
@@ -97,9 +75,8 @@ remove_phis_block(nir_block *block, nir_builder *b)
if (def == NULL) {
def = src->src.ssa;
- mov = get_parent_mov(def);
} else {
- if (src->src.ssa != def && !matching_mov(mov, src->src.ssa)) {
+ if (src->src.ssa != def) {
srcs_same = false;
break;
}
@@ -114,41 +91,22 @@ remove_phis_block(nir_block *block, nir_builder *b)
*/
assert(def != NULL);
- if (mov) {
- /* If the sources were all movs from the same source with the same
- * swizzle, then we can't just pick a random move because it may not
- * dominate the phi node. Instead, we need to emit our own move after
- * the phi which uses the shared source, and rewrite uses of the phi
- * to use the move instead. This is ok, because while the movs may
- * not all dominate the phi node, their shared source does.
- */
-
- b->cursor = nir_after_phis(block);
- def = mov->op == nir_op_imov ?
- nir_imov_alu(b, mov->src[0], def->num_components) :
- nir_fmov_alu(b, mov->src[0], def->num_components);
- }
-
assert(phi->dest.is_ssa);
nir_ssa_def_rewrite_uses(&phi->dest.ssa, nir_src_for_ssa(def));
nir_instr_remove(instr);
- progress = true;
+ *progress = true;
}
- return progress;
+ return true;
}
static bool
remove_phis_impl(nir_function_impl *impl)
{
bool progress = false;
- nir_builder bld;
- nir_builder_init(&bld, impl);
- nir_foreach_block(block, impl) {
- progress |= remove_phis_block(block, &bld);
- }
+ nir_foreach_block(impl, remove_phis_block, &progress);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
@@ -163,7 +121,7 @@ nir_opt_remove_phis(nir_shader *shader)
{
bool progress = false;
- nir_foreach_function(function, shader)
+ nir_foreach_function(shader, function)
if (function->impl)
progress = remove_phis_impl(function->impl) || progress;