summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2017-07-06 13:45:08 +0200
committerNicolai Hähnle <nicolai.haehnle@amd.com>2017-07-13 13:27:47 +0200
commit8f483794440016a217625e349ab7ad76a88cd491 (patch)
tree2a091036396edc21f0e281a220cdd70bd33ad38b
parent556ece4be47c44c0971ebfd24421d19560bb9c32 (diff)
nir/linker: remove dead variables
-rw-r--r--src/compiler/glsl/linker.cpp2
-rw-r--r--src/compiler/glsl/nir_linker.cpp38
-rw-r--r--src/compiler/glsl/nir_linker.h3
3 files changed, 42 insertions, 1 deletions
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index e47e6e0958..d1462a2b42 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -5049,7 +5049,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
}
if (spirv) {
- fprintf(stderr, "todo: nir_remove_dead_variables\n"); /* see opt_dead_code.cpp */
+ nir_linker_remove_dead_variables(prog, prog->_LinkedShaders[i]);
} else {
/* Call opts before lowering const arrays to uniforms so we can const
* propagate any elements accessed directly.
diff --git a/src/compiler/glsl/nir_linker.cpp b/src/compiler/glsl/nir_linker.cpp
index c197c3c21f..698c71ab37 100644
--- a/src/compiler/glsl/nir_linker.cpp
+++ b/src/compiler/glsl/nir_linker.cpp
@@ -265,6 +265,44 @@ create_linked_nir_shader(void *mem_ctx,
return linked;
}
+void
+nir_linker_remove_dead_variables(gl_shader_program *prog, gl_linked_shader *sh)
+{
+ /* TODO don't remove if ir_var->data.always_active_io, nor uniforms with
+ * constant initializers
+ */
+ nir_remove_dead_variables(sh->nir, nir_var_all);
+
+ /* Cleanup the IR shadows. */
+ exec_list live;
+
+ nir_foreach_variable(var, &sh->nir->inputs) {
+ ir_variable *ir_var = find_ir_variable(sh, var);
+ if (ir_var) {
+ ir_var->remove();
+ live.push_tail(ir_var);
+ }
+ }
+
+ nir_foreach_variable(var, &sh->nir->outputs) {
+ ir_variable *ir_var = find_ir_variable(sh, var);
+ if (ir_var) {
+ ir_var->remove();
+ live.push_tail(ir_var);
+ }
+ }
+
+ nir_foreach_variable(var, &sh->nir->uniforms) {
+ ir_variable *ir_var = find_ir_variable(sh, var);
+ if (ir_var) {
+ ir_var->remove();
+ live.push_tail(ir_var);
+ }
+ }
+
+ live.move_nodes_to(sh->ir);
+}
+
/**
* After linking has completed, update the NIR shader with information from
* the shadow IR variables.
diff --git a/src/compiler/glsl/nir_linker.h b/src/compiler/glsl/nir_linker.h
index a20095b9c1..2d256b804f 100644
--- a/src/compiler/glsl/nir_linker.h
+++ b/src/compiler/glsl/nir_linker.h
@@ -47,4 +47,7 @@ void
find_nir_assignments(struct nir_shader *nir, unsigned num_variables,
struct find_variable * const *variables);
+void
+nir_linker_remove_dead_variables(gl_shader_program *prog, gl_linked_shader *sh);
+
#endif /* NIR_LINKER_H */