aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/nir/nir_opt_peephole_select.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2015-03-22 13:30:59 +0100
committermarha <marha@users.sourceforge.net>2015-03-22 13:30:59 +0100
commit82c8df11062f72a7d467e26cedbbd8b322ff7a70 (patch)
tree7e7a3e408d09d3e50ff0d2f9befeb5b7ab5617a5 /mesalib/src/glsl/nir/nir_opt_peephole_select.c
parent8574eba804031f6b19713f0b02952280730bf62e (diff)
downloadvcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.tar.gz
vcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.tar.bz2
vcxsrv-82c8df11062f72a7d467e26cedbbd8b322ff7a70.zip
randrproto fontconfig libX11 libXdmcp libxcb mesa xkbcomp xserver git update 22 Mar 2015
xserver commit 0a78b599b34cc8b5fe6fe82f90e90234e8ab7a56 libxcb commit a90be9955d2c5a635f791d44db1154633b9d3322 libX11 commit 5a499ca7b064bf7e6a4fcc169f22862dce0c60c5 libXdmcp commit 0c09444d276fbf46a0e8b427a4f6a325d0625742 xkbcomp commit fc3e6ddb2c8e922ea80f2dc5cbc1df2102e30d99 randrproto commit b1ba68df8a5fc113a387123ec2f312195e28e47f fontconfig commit 69ff6b6e260584e383c38b1b7034ddcbb23d214f mesa commit 397b491173f0d2df4deb44d21c170bf16840d507
Diffstat (limited to 'mesalib/src/glsl/nir/nir_opt_peephole_select.c')
-rw-r--r--mesalib/src/glsl/nir/nir_opt_peephole_select.c112
1 files changed, 75 insertions, 37 deletions
diff --git a/mesalib/src/glsl/nir/nir_opt_peephole_select.c b/mesalib/src/glsl/nir/nir_opt_peephole_select.c
index ab08f286f..b89451b09 100644
--- a/mesalib/src/glsl/nir/nir_opt_peephole_select.c
+++ b/mesalib/src/glsl/nir/nir_opt_peephole_select.c
@@ -52,36 +52,66 @@ struct peephole_select_state {
};
static bool
-are_all_move_to_phi(nir_block *block)
+block_check_for_allowed_instrs(nir_block *block)
{
nir_foreach_instr(block, instr) {
- if (instr->type != nir_instr_type_alu)
- return false;
+ switch (instr->type) {
+ case nir_instr_type_intrinsic: {
+ nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+
+ switch (intrin->intrinsic) {
+ case nir_intrinsic_load_var:
+ switch (intrin->variables[0]->var->data.mode) {
+ case nir_var_shader_in:
+ case nir_var_uniform:
+ break;
+
+ default:
+ return false;
+ }
+ break;
+
+ default:
+ return false;
+ }
- /* It must be a move operation */
- nir_alu_instr *mov = nir_instr_as_alu(instr);
- if (mov->op != nir_op_fmov && mov->op != nir_op_imov)
- return false;
+ break;
+ }
- /* Can't handle saturate */
- if (mov->dest.saturate)
- return false;
+ case nir_instr_type_load_const:
+ break;
- /* It must be SSA */
- if (!mov->dest.dest.is_ssa)
- return false;
+ case nir_instr_type_alu: {
+ /* It must be a move operation */
+ nir_alu_instr *mov = nir_instr_as_alu(instr);
+ if (mov->op != nir_op_fmov && mov->op != nir_op_imov)
+ return false;
- /* It cannot have any if-uses */
- if (mov->dest.dest.ssa.if_uses->entries != 0)
- return false;
+ /* Can't handle saturate */
+ if (mov->dest.saturate)
+ return false;
+
+ /* It must be SSA */
+ if (!mov->dest.dest.is_ssa)
+ return false;
- /* The only uses of this definition must be phi's in the successor */
- struct set_entry *entry;
- set_foreach(mov->dest.dest.ssa.uses, entry) {
- const nir_instr *dest_instr = entry->key;
- if (dest_instr->type != nir_instr_type_phi ||
- dest_instr->block != block->successors[0])
+ /* It cannot have any if-uses */
+ if (mov->dest.dest.ssa.if_uses->entries != 0)
return false;
+
+ /* The only uses of this definition must be phi's in the successor */
+ struct set_entry *entry;
+ set_foreach(mov->dest.dest.ssa.uses, entry) {
+ const nir_instr *dest_instr = entry->key;
+ if (dest_instr->type != nir_instr_type_phi ||
+ dest_instr->block != block->successors[0])
+ return false;
+ }
+ break;
+ }
+
+ default:
+ return false;
}
}
@@ -119,8 +149,9 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
nir_block *then_block = nir_cf_node_as_block(then_node);
nir_block *else_block = nir_cf_node_as_block(else_node);
- /* ... and those blocks must only contain move-to-phi. */
- if (!are_all_move_to_phi(then_block) || !are_all_move_to_phi(else_block))
+ /* ... 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;
/* At this point, we know that the previous CFG node is an if-then
@@ -129,6 +160,25 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
* selects.
*/
+ nir_block *prev_block = nir_cf_node_as_block(nir_cf_node_prev(prev_node));
+ assert(prev_block->cf_node.type == nir_cf_node_block);
+
+ /* First, we move the remaining instructions from the blocks to the
+ * block before. We have already guaranteed that this is safe by
+ * calling block_check_for_allowed_instrs()
+ */
+ nir_foreach_instr_safe(then_block, instr) {
+ exec_node_remove(&instr->node);
+ instr->block = prev_block;
+ exec_list_push_tail(&prev_block->instr_list, &instr->node);
+ }
+
+ nir_foreach_instr_safe(else_block, instr) {
+ exec_node_remove(&instr->node);
+ instr->block = prev_block;
+ exec_list_push_tail(&prev_block->instr_list, &instr->node);
+ }
+
nir_foreach_instr_safe(block, instr) {
if (instr->type != nir_instr_type_phi)
break;
@@ -145,19 +195,7 @@ nir_opt_peephole_select_block(nir_block *block, void *void_state)
assert(src->src.is_ssa);
unsigned idx = src->pred == then_block ? 1 : 2;
-
- if (src->src.ssa->parent_instr->block == src->pred) {
- /* We already know that this instruction must be a move with
- * this phi's in this block as its only users.
- */
- nir_alu_instr *mov = nir_instr_as_alu(src->src.ssa->parent_instr);
- assert(mov->instr.type == nir_instr_type_alu);
- assert(mov->op == nir_op_fmov || mov->op == nir_op_imov);
-
- nir_alu_src_copy(&sel->src[idx], &mov->src[0], state->mem_ctx);
- } else {
- nir_src_copy(&sel->src[idx].src, &src->src, state->mem_ctx);
- }
+ nir_src_copy(&sel->src[idx].src, &src->src, state->mem_ctx);
}
nir_ssa_dest_init(&sel->instr, &sel->dest.dest,