summaryrefslogtreecommitdiff
path: root/src/compiler/nir/nir_remove_dead_variables.c
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2017-10-16 15:32:30 -0700
committerEric Anholt <eric@anholt.net>2017-10-20 16:26:07 -0700
commitd9ce4ac990090b3fa940a662655b61359f296be0 (patch)
treee508ee2f667c9deb4a0ce0ffad71676b578596b7 /src/compiler/nir/nir_remove_dead_variables.c
parenta2c6fbb3ee16a58a9098b031a6382618d570bee8 (diff)
nir: Add a safety check that we don't remove dead I/O vars after lowering.
The pass only looks at var load/store intrinsics, not input load/store intrinsics, so assert that we don't see the other type. v2: Adjust comment indentation. Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Diffstat (limited to 'src/compiler/nir/nir_remove_dead_variables.c')
-rw-r--r--src/compiler/nir/nir_remove_dead_variables.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c
index a1fe0de9c61..eff66f92d43 100644
--- a/src/compiler/nir/nir_remove_dead_variables.c
+++ b/src/compiler/nir/nir_remove_dead_variables.c
@@ -28,7 +28,8 @@
#include "nir.h"
static void
-add_var_use_intrinsic(nir_intrinsic_instr *instr, struct set *live)
+add_var_use_intrinsic(nir_intrinsic_instr *instr, struct set *live,
+ nir_variable_mode modes)
{
unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables;
@@ -47,6 +48,14 @@ add_var_use_intrinsic(nir_intrinsic_instr *instr, struct set *live)
break;
}
+ /* This pass can't be used on I/O variables after they've been lowered. */
+ case nir_intrinsic_load_input:
+ assert(!(modes & nir_var_shader_in));
+ break;
+ case nir_intrinsic_store_output:
+ assert(!(modes & nir_var_shader_out));
+ break;
+
default:
for (unsigned i = 0; i < num_vars; i++) {
_mesa_set_add(live, instr->variables[i]->var);
@@ -84,7 +93,7 @@ add_var_use_tex(nir_tex_instr *instr, struct set *live)
}
static void
-add_var_use_shader(nir_shader *shader, struct set *live)
+add_var_use_shader(nir_shader *shader, struct set *live, nir_variable_mode modes)
{
nir_foreach_function(function, shader) {
if (function->impl) {
@@ -92,7 +101,8 @@ add_var_use_shader(nir_shader *shader, struct set *live)
nir_foreach_instr(instr, block) {
switch(instr->type) {
case nir_instr_type_intrinsic:
- add_var_use_intrinsic(nir_instr_as_intrinsic(instr), live);
+ add_var_use_intrinsic(nir_instr_as_intrinsic(instr), live,
+ modes);
break;
case nir_instr_type_call:
@@ -162,7 +172,7 @@ nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes)
struct set *live =
_mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
- add_var_use_shader(shader, live);
+ add_var_use_shader(shader, live, modes);
if (modes & nir_var_uniform)
progress = remove_dead_vars(&shader->uniforms, live) || progress;