aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/nir
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/nir')
-rw-r--r--mesalib/src/glsl/nir/glsl_to_nir.cpp10
-rw-r--r--mesalib/src/glsl/nir/nir.c1
-rw-r--r--mesalib/src/glsl/nir/nir.h11
-rw-r--r--mesalib/src/glsl/nir/nir_from_ssa.c29
-rw-r--r--mesalib/src/glsl/nir/nir_intrinsics.h2
-rw-r--r--mesalib/src/glsl/nir/nir_live_variables.c5
-rw-r--r--mesalib/src/glsl/nir/nir_lower_vars_to_ssa.c11
-rw-r--r--mesalib/src/glsl/nir/nir_opt_copy_propagate.c45
-rw-r--r--mesalib/src/glsl/nir/nir_opt_gcm.c4
-rw-r--r--mesalib/src/glsl/nir/nir_vla.h54
10 files changed, 132 insertions, 40 deletions
diff --git a/mesalib/src/glsl/nir/glsl_to_nir.cpp b/mesalib/src/glsl/nir/glsl_to_nir.cpp
index 544d0d932..adef19c80 100644
--- a/mesalib/src/glsl/nir/glsl_to_nir.cpp
+++ b/mesalib/src/glsl/nir/glsl_to_nir.cpp
@@ -563,8 +563,14 @@ nir_visitor::visit(ir_discard *ir)
* discards will be immediately followed by a return.
*/
- nir_intrinsic_instr *discard =
- nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard);
+ nir_intrinsic_instr *discard;
+ if (ir->condition) {
+ discard = nir_intrinsic_instr_create(this->shader,
+ nir_intrinsic_discard_if);
+ discard->src[0] = evaluate_rvalue(ir->condition);
+ } else {
+ discard = nir_intrinsic_instr_create(this->shader, nir_intrinsic_discard);
+ }
nir_instr_insert_after_cf_list(this->cf_node_list, &discard->instr);
}
diff --git a/mesalib/src/glsl/nir/nir.c b/mesalib/src/glsl/nir/nir.c
index 5b0e4bc50..ab57fd4e2 100644
--- a/mesalib/src/glsl/nir/nir.c
+++ b/mesalib/src/glsl/nir/nir.c
@@ -63,6 +63,7 @@ reg_create(void *mem_ctx, struct exec_list *list)
{
nir_register *reg = ralloc(mem_ctx, nir_register);
+ reg->parent_instr = NULL;
reg->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
reg->defs = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
diff --git a/mesalib/src/glsl/nir/nir.h b/mesalib/src/glsl/nir/nir.h
index d74caa959..d5df59609 100644
--- a/mesalib/src/glsl/nir/nir.h
+++ b/mesalib/src/glsl/nir/nir.h
@@ -66,6 +66,7 @@ name(const in_type *parent) \
struct nir_function_overload;
struct nir_function;
struct nir_shader;
+struct nir_instr;
/**
@@ -386,6 +387,14 @@ typedef struct {
*/
bool is_packed;
+ /**
+ * If this pointer is non-NULL then this register has exactly one
+ * definition and that definition dominates all of its uses. This is
+ * set by the out-of-SSA pass so that backends can get SSA-like
+ * information even once they have gone out of SSA.
+ */
+ struct nir_instr *parent_instr;
+
/** set of nir_instr's where this register is used (read from) */
struct set *uses;
@@ -408,7 +417,7 @@ typedef enum {
nir_instr_type_parallel_copy,
} nir_instr_type;
-typedef struct {
+typedef struct nir_instr {
struct exec_node node;
nir_instr_type type;
struct nir_block *block;
diff --git a/mesalib/src/glsl/nir/nir_from_ssa.c b/mesalib/src/glsl/nir/nir_from_ssa.c
index 7c5009577..c3090fb06 100644
--- a/mesalib/src/glsl/nir/nir_from_ssa.c
+++ b/mesalib/src/glsl/nir/nir_from_ssa.c
@@ -26,6 +26,7 @@
*/
#include "nir.h"
+#include "nir_vla.h"
/*
* This file implements an out-of-SSA pass as described in "Revisiting
@@ -181,7 +182,7 @@ merge_merge_sets(merge_set *a, merge_set *b)
static bool
merge_sets_interfere(merge_set *a, merge_set *b)
{
- merge_node *dom[a->size + b->size];
+ NIR_VLA(merge_node *, dom, a->size + b->size);
int dom_idx = -1;
struct exec_node *an = exec_list_get_head(&a->nodes);
@@ -508,6 +509,13 @@ get_register_for_ssa_def(nir_ssa_def *def, struct from_ssa_state *state)
reg->num_components = def->num_components;
reg->num_array_elems = 0;
+ /* This register comes from an SSA definition that was not part of a
+ * phi-web. Therefore, we know it has a single unique definition
+ * that dominates all of its uses. Therefore, we can copy the
+ * parent_instr from the SSA def safely.
+ */
+ reg->parent_instr = def->parent_instr;
+
_mesa_hash_table_insert(state->ssa_table, def, reg);
return reg;
}
@@ -666,21 +674,16 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
}
/* The register/source corresponding to the given index */
- nir_src values[num_copies * 2];
- memset(values, 0, sizeof values);
-
- /* The current location of a given piece of data */
- int loc[num_copies * 2];
+ NIR_VLA_ZERO(nir_src, values, num_copies * 2);
- /* The piece of data that the given piece of data is to be copied from */
- int pred[num_copies * 2];
+ /* The current location of a given piece of data. We will use -1 for "null" */
+ NIR_VLA_FILL(int, loc, num_copies * 2, -1);
- /* Initialize loc and pred. We will use -1 for "null" */
- memset(loc, -1, sizeof loc);
- memset(pred, -1, sizeof pred);
+ /* The piece of data that the given piece of data is to be copied from. We will use -1 for "null" */
+ NIR_VLA_FILL(int, pred, num_copies * 2, -1);
/* The destinations we have yet to properly fill */
- int to_do[num_copies * 2];
+ NIR_VLA(int, to_do, num_copies * 2);
int to_do_idx = -1;
/* Now we set everything up:
@@ -730,7 +733,7 @@ resolve_parallel_copy(nir_parallel_copy_instr *pcopy,
}
/* Currently empty destinations we can go ahead and fill */
- int ready[num_copies * 2];
+ NIR_VLA(int, ready, num_copies * 2);
int ready_idx = -1;
/* Mark the ones that are ready for copying. We know an index is a
diff --git a/mesalib/src/glsl/nir/nir_intrinsics.h b/mesalib/src/glsl/nir/nir_intrinsics.h
index d94866c85..3bf102fc1 100644
--- a/mesalib/src/glsl/nir/nir_intrinsics.h
+++ b/mesalib/src/glsl/nir/nir_intrinsics.h
@@ -68,6 +68,8 @@ INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0,
#define BARRIER(name) INTRINSIC(name, 0, ARR(), false, 0, 0, 0, 0)
BARRIER(discard)
+/** A conditional discard, with a single boolean source. */
+INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, 0)
INTRINSIC(emit_vertex, 0, ARR(), false, 0, 0, 1, 0)
INTRINSIC(end_primitive, 0, ARR(), false, 0, 0, 1, 0)
diff --git a/mesalib/src/glsl/nir/nir_live_variables.c b/mesalib/src/glsl/nir/nir_live_variables.c
index 7402dc087..1c96dcf36 100644
--- a/mesalib/src/glsl/nir/nir_live_variables.c
+++ b/mesalib/src/glsl/nir/nir_live_variables.c
@@ -26,6 +26,7 @@
#include "nir.h"
#include "nir_worklist.h"
+#include "nir_vla.h"
/*
* Basic liveness analysis. This works only in SSA form.
@@ -130,8 +131,8 @@ static bool
propagate_across_edge(nir_block *pred, nir_block *succ,
struct live_variables_state *state)
{
- BITSET_WORD live[state->bitset_words];
- memcpy(live, succ->live_in, sizeof live);
+ NIR_VLA(BITSET_WORD, live, state->bitset_words);
+ memcpy(live, succ->live_in, state->bitset_words * sizeof *live);
nir_foreach_instr(succ, instr) {
if (instr->type != nir_instr_type_phi)
diff --git a/mesalib/src/glsl/nir/nir_lower_vars_to_ssa.c b/mesalib/src/glsl/nir/nir_lower_vars_to_ssa.c
index 8af753029..9e9a418e3 100644
--- a/mesalib/src/glsl/nir/nir_lower_vars_to_ssa.c
+++ b/mesalib/src/glsl/nir/nir_lower_vars_to_ssa.c
@@ -26,6 +26,8 @@
*/
#include "nir.h"
+#include "nir_vla.h"
+
struct deref_node {
struct deref_node *parent;
@@ -899,8 +901,8 @@ rename_variables_block(nir_block *block, struct lower_variables_state *state)
static void
insert_phi_nodes(struct lower_variables_state *state)
{
- unsigned work[state->impl->num_blocks];
- unsigned has_already[state->impl->num_blocks];
+ NIR_VLA_ZERO(unsigned, work, state->impl->num_blocks);
+ NIR_VLA_ZERO(unsigned, has_already, state->impl->num_blocks);
/*
* Since the work flags already prevent us from inserting a node that has
@@ -910,10 +912,7 @@ insert_phi_nodes(struct lower_variables_state *state)
* function. So all we need to handle W is an array and a pointer to the
* next element to be inserted and the next element to be removed.
*/
- nir_block *W[state->impl->num_blocks];
-
- memset(work, 0, sizeof work);
- memset(has_already, 0, sizeof has_already);
+ NIR_VLA(nir_block *, W, state->impl->num_blocks);
unsigned w_start, w_end;
unsigned iter_count = 0;
diff --git a/mesalib/src/glsl/nir/nir_opt_copy_propagate.c b/mesalib/src/glsl/nir/nir_opt_copy_propagate.c
index dd0ec01ef..ee78e5aa0 100644
--- a/mesalib/src/glsl/nir/nir_opt_copy_propagate.c
+++ b/mesalib/src/glsl/nir/nir_opt_copy_propagate.c
@@ -53,22 +53,6 @@ static bool is_move(nir_alu_instr *instr)
}
-static bool
-is_swizzleless_move(nir_alu_instr *instr)
-{
- if (!is_move(instr))
- return false;
-
- for (unsigned i = 0; i < 4; i++) {
- if (!((instr->dest.write_mask >> i) & 1))
- break;
- if (instr->src[0].swizzle[i] != i)
- return false;
- }
-
- return true;
-}
-
static bool is_vec(nir_alu_instr *instr)
{
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++)
@@ -80,6 +64,35 @@ static bool is_vec(nir_alu_instr *instr)
instr->op == nir_op_vec4;
}
+static bool
+is_swizzleless_move(nir_alu_instr *instr)
+{
+ if (is_move(instr)) {
+ for (unsigned i = 0; i < 4; i++) {
+ if (!((instr->dest.write_mask >> i) & 1))
+ break;
+ if (instr->src[0].swizzle[i] != i)
+ return false;
+ }
+ return true;
+ } else if (is_vec(instr)) {
+ nir_ssa_def *def = NULL;
+ for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
+ if (instr->src[i].swizzle[0] != i)
+ return false;
+
+ if (def == NULL) {
+ def = instr->src[i].src.ssa;
+ } else if (instr->src[i].src.ssa != def) {
+ return false;
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
typedef struct {
nir_ssa_def *def;
bool found;
diff --git a/mesalib/src/glsl/nir/nir_opt_gcm.c b/mesalib/src/glsl/nir/nir_opt_gcm.c
index bf565b969..b4f5fd3d5 100644
--- a/mesalib/src/glsl/nir/nir_opt_gcm.c
+++ b/mesalib/src/glsl/nir/nir_opt_gcm.c
@@ -121,9 +121,11 @@ gcm_pin_instructions_block(nir_block *block, void *void_state)
case nir_op_fddy_coarse:
/* These can only go in uniform control flow; pin them for now */
instr->pass_flags = GCM_INSTR_PINNED;
+ break;
default:
instr->pass_flags = 0;
+ break;
}
break;
@@ -134,9 +136,11 @@ gcm_pin_instructions_block(nir_block *block, void *void_state)
case nir_texop_lod:
/* These two take implicit derivatives so they need to be pinned */
instr->pass_flags = GCM_INSTR_PINNED;
+ break;
default:
instr->pass_flags = 0;
+ break;
}
break;
diff --git a/mesalib/src/glsl/nir/nir_vla.h b/mesalib/src/glsl/nir/nir_vla.h
new file mode 100644
index 000000000..753783316
--- /dev/null
+++ b/mesalib/src/glsl/nir/nir_vla.h
@@ -0,0 +1,54 @@
+/**************************************************************************
+ *
+ * Copyright 2015 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#pragma once
+
+
+#include "c99_alloca.h"
+
+
+/* Declare a variable length array, with no initialization */
+#define NIR_VLA(_type, _name, _length) \
+ _type *_name = alloca((_length) * sizeof *_name)
+
+
+/* Declare a variable length array, and initialize it with the given byte.
+ *
+ * _length is evaluated twice, so expressions with side-effects must be
+ * avoided.
+ */
+#define NIR_VLA_FILL(_type, _name, _length, _byte) \
+ _type *_name = memset(alloca((_length) * sizeof *_name), _byte, (_length) * sizeof *_name)
+
+
+/* Declare a variable length array, and zero it.
+ *
+ * Just like NIR_VLA_FILL, _length is evaluated twice, so expressions with
+ * side-effects must be avoided.
+ */
+#define NIR_VLA_ZERO(_type, _name, _length) \
+ NIR_VLA_FILL(_type, _name, _length, 0)