summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_opt_peephole_select.c
diff options
context:
space:
mode:
authorConnor Abbott <cwabbott0@gmail.com>2016-04-12 15:03:41 -0400
committerJason Ekstrand <jason.ekstrand@intel.com>2016-04-28 15:52:17 -0700
commit480a182ccd50a084e260f154b4f288b6de1c2d2f (patch)
tree1b9da3d29ea2cd9fb644a5170a86609f79174eb3 /src/compiler/nir/nir_opt_peephole_select.c
parente5f37701ab6300c64e02d1c527ccc30fbda32fd3 (diff)
downloadexternal_mesa3d-480a182ccd50a084e260f154b4f288b6de1c2d2f.zip
external_mesa3d-480a182ccd50a084e260f154b4f288b6de1c2d2f.tar.gz
external_mesa3d-480a182ccd50a084e260f154b4f288b6de1c2d2f.tar.bz2
nir/opt_peephole_select: fixup for new foreach_block()
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/compiler/nir/nir_opt_peephole_select.c')
-rw-r--r--src/compiler/nir/nir_opt_peephole_select.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/compiler/nir/nir_opt_peephole_select.c b/src/compiler/nir/nir_opt_peephole_select.c
index c1353b5..d783f7b 100644
--- a/src/compiler/nir/nir_opt_peephole_select.c
+++ b/src/compiler/nir/nir_opt_peephole_select.c
@@ -47,11 +47,6 @@
* swizzle.
*/
-struct peephole_select_state {
- void *mem_ctx;
- bool progress;
-};
-
static bool
block_check_for_allowed_instrs(nir_block *block)
{
@@ -130,23 +125,21 @@ block_check_for_allowed_instrs(nir_block *block)
}
static bool
-nir_opt_peephole_select_block(nir_block *block, void *void_state)
+nir_opt_peephole_select_block(nir_block *block, void *mem_ctx)
{
- struct peephole_select_state *state = void_state;
-
/* If the block is empty, then it certainly doesn't have any phi nodes,
* so we can skip it. This also ensures that we do an early skip on the
* end block of the function which isn't actually attached to the CFG.
*/
if (exec_list_is_empty(&block->instr_list))
- return true;
+ return false;
if (nir_cf_node_is_first(&block->cf_node))
- return true;
+ return false;
nir_cf_node *prev_node = nir_cf_node_prev(&block->cf_node);
if (prev_node->type != nir_cf_node_if)
- return true;
+ return false;
nir_if *if_stmt = nir_cf_node_as_if(prev_node);
nir_cf_node *then_node = nir_if_first_then_node(if_stmt);
@@ -155,7 +148,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
/* We can only have one block in each side ... */
if (nir_if_last_then_node(if_stmt) != then_node ||
nir_if_last_else_node(if_stmt) != else_node)
- return true;
+ return false;
nir_block *then_block = nir_cf_node_as_block(then_node);
nir_block *else_block = nir_cf_node_as_block(else_node);
@@ -163,7 +156,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
/* ... and those blocks must only contain "allowed" instructions. */
if (!block_check_for_allowed_instrs(then_block) ||
!block_check_for_allowed_instrs(else_block))
- return true;
+ return false;
/* At this point, we know that the previous CFG node is an if-then
* statement containing only moves to phi nodes in this block. We can
@@ -195,7 +188,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
break;
nir_phi_instr *phi = nir_instr_as_phi(instr);
- nir_alu_instr *sel = nir_alu_instr_create(state->mem_ctx, nir_op_bcsel);
+ nir_alu_instr *sel = nir_alu_instr_create(mem_ctx, nir_op_bcsel);
nir_src_copy(&sel->src[0].src, &if_stmt->condition, sel);
/* Splat the condition to all channels */
memset(sel->src[0].swizzle, 0, sizeof sel->src[0].swizzle);
@@ -222,25 +215,23 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
}
nir_cf_node_remove(&if_stmt->cf_node);
- state->progress = true;
-
return true;
}
static bool
nir_opt_peephole_select_impl(nir_function_impl *impl)
{
- struct peephole_select_state state;
-
- state.mem_ctx = ralloc_parent(impl);
- state.progress = false;
+ void *mem_ctx = ralloc_parent(impl);
+ bool progress = false;
- nir_foreach_block_call(impl, nir_opt_peephole_select_block, &state);
+ nir_foreach_block_safe(block, impl) {
+ progress |= nir_opt_peephole_select_block(block, mem_ctx);
+ }
- if (state.progress)
+ if (progress)
nir_metadata_preserve(impl, nir_metadata_none);
- return state.progress;
+ return progress;
}
bool