nir: rename lower_outputs_to_temporaries -> lower_io_to_temporaries
authorRob Clark <robclark@freedesktop.org>
Fri, 25 Mar 2016 17:52:26 +0000 (13:52 -0400)
committerRob Clark <robclark@freedesktop.org>
Wed, 11 May 2016 16:20:11 +0000 (12:20 -0400)
Since it will gain support to lower inputs, give it a more generic name.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
src/compiler/Makefile.sources
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_io_to_temporaries.c [new file with mode: 0644]
src/compiler/nir/nir_lower_outputs_to_temporaries.c [deleted file]
src/mesa/drivers/dri/i965/brw_nir.c

index fabab777ada45b2c4bf1c5e95efebe523d8adb95..66fbd84c0b113fb4a0bef38f6f9047925b51b9b3 100644 (file)
@@ -199,8 +199,8 @@ NIR_FILES = \
        nir/nir_lower_idiv.c \
        nir/nir_lower_indirect_derefs.c \
        nir/nir_lower_io.c \
+       nir/nir_lower_io_to_temporaries.c \
        nir/nir_lower_io_types.c \
-       nir/nir_lower_outputs_to_temporaries.c \
        nir/nir_lower_passthrough_edgeflags.c \
        nir/nir_lower_phis_to_scalar.c \
        nir/nir_lower_returns.c \
index 68f948e83a5b4361a24120bb4dc67ac1097d0b89..5410f0b8020d2b43eff0a4d663821bd8496df7df 100644 (file)
@@ -2279,8 +2279,8 @@ bool nir_lower_indirect_derefs(nir_shader *shader, nir_variable_mode modes);
 
 bool nir_lower_locals_to_regs(nir_shader *shader);
 
-void nir_lower_outputs_to_temporaries(nir_shader *shader,
-                                      nir_function *entrypoint);
+void nir_lower_io_to_temporaries(nir_shader *shader, nir_function *entrypoint);
+
 void nir_shader_gather_info(nir_shader *shader, nir_function_impl *entrypoint);
 
 void nir_assign_var_locations(struct exec_list *var_list,
diff --git a/src/compiler/nir/nir_lower_io_to_temporaries.c b/src/compiler/nir/nir_lower_io_to_temporaries.c
new file mode 100644 (file)
index 0000000..bf16aec
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * 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, sublicense,
+ * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+/*
+ * Implements a pass that lowers output variables to a temporary plus an
+ * output variable with a single copy at each exit point of the shader.
+ * This way the output variable is only ever written.
+ */
+
+#include "nir.h"
+
+struct lower_io_state {
+   nir_shader *shader;
+   struct exec_list old_outputs;
+};
+
+static void
+emit_output_copies(nir_cursor cursor, struct lower_io_state *state)
+{
+   assert(exec_list_length(&state->shader->outputs) ==
+          exec_list_length(&state->old_outputs));
+
+   foreach_two_lists(out_node, &state->shader->outputs,
+                     temp_node, &state->old_outputs) {
+      nir_variable *output = exec_node_data(nir_variable, out_node, node);
+      nir_variable *temp = exec_node_data(nir_variable, temp_node, node);
+
+      nir_intrinsic_instr *copy =
+         nir_intrinsic_instr_create(state->shader, nir_intrinsic_copy_var);
+      copy->variables[0] = nir_deref_var_create(copy, output);
+      copy->variables[1] = nir_deref_var_create(copy, temp);
+
+      nir_instr_insert(cursor, &copy->instr);
+   }
+}
+
+void
+nir_lower_io_to_temporaries(nir_shader *shader, nir_function *entrypoint)
+{
+   struct lower_io_state state;
+
+   if (shader->stage == MESA_SHADER_TESS_CTRL)
+      return;
+
+   state.shader = shader;
+   exec_list_move_nodes_to(&shader->outputs, &state.old_outputs);
+
+   /* Walk over all of the outputs turn each output into a temporary and
+    * make a new variable for the actual output.
+    */
+   nir_foreach_variable(var, &state.old_outputs) {
+      nir_variable *output = ralloc(shader, nir_variable);
+      memcpy(output, var, sizeof *output);
+
+      /* The orignal is now the temporary */
+      nir_variable *temp = var;
+
+      /* Reparent the name to the new variable */
+      ralloc_steal(output, output->name);
+
+      /* Reparent the constant initializer (if any) */
+      ralloc_steal(output, output->constant_initializer);
+
+      /* Give the output a new name with @out-temp appended */
+      temp->name = ralloc_asprintf(var, "%s@out-temp", output->name);
+      temp->data.mode = nir_var_global;
+      temp->constant_initializer = NULL;
+
+      exec_list_push_tail(&shader->outputs, &output->node);
+   }
+
+   nir_foreach_function(function, shader) {
+      if (function->impl == NULL)
+         continue;
+
+      if (shader->stage == MESA_SHADER_GEOMETRY) {
+         /* For geometry shaders, we have to emit the output copies right
+          * before each EmitVertex call.
+          */
+         nir_foreach_block(block, function->impl) {
+            nir_foreach_instr(instr, block) {
+               if (instr->type != nir_instr_type_intrinsic)
+                  continue;
+
+               nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
+               if (intrin->intrinsic == nir_intrinsic_emit_vertex) {
+                  emit_output_copies(nir_before_instr(&intrin->instr),
+                                     &state);
+               }
+            }
+         }
+      } else if (function == entrypoint) {
+         /* For all other shader types, we need to do the copies right before
+          * the jumps to the end block.
+          */
+         struct set_entry *block_entry;
+         set_foreach(function->impl->end_block->predecessors, block_entry) {
+            struct nir_block *block = (void *)block_entry->key;
+            emit_output_copies(nir_after_block_before_jump(block), &state);
+         }
+      }
+
+      nir_metadata_preserve(function->impl, nir_metadata_block_index |
+                                            nir_metadata_dominance);
+   }
+
+   exec_list_append(&shader->globals, &state.old_outputs);
+}
diff --git a/src/compiler/nir/nir_lower_outputs_to_temporaries.c b/src/compiler/nir/nir_lower_outputs_to_temporaries.c
deleted file mode 100644 (file)
index 0dfb7b0..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright © 2015 Intel Corporation
- *
- * 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, sublicense,
- * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-/*
- * Implements a pass that lowers output variables to a temporary plus an
- * output variable with a single copy at each exit point of the shader.
- * This way the output variable is only ever written.
- */
-
-#include "nir.h"
-
-struct lower_outputs_state {
-   nir_shader *shader;
-   struct exec_list old_outputs;
-};
-
-static void
-emit_output_copies(nir_cursor cursor, struct lower_outputs_state *state)
-{
-   assert(exec_list_length(&state->shader->outputs) ==
-          exec_list_length(&state->old_outputs));
-
-   foreach_two_lists(out_node, &state->shader->outputs,
-                     temp_node, &state->old_outputs) {
-      nir_variable *output = exec_node_data(nir_variable, out_node, node);
-      nir_variable *temp = exec_node_data(nir_variable, temp_node, node);
-
-      nir_intrinsic_instr *copy =
-         nir_intrinsic_instr_create(state->shader, nir_intrinsic_copy_var);
-      copy->variables[0] = nir_deref_var_create(copy, output);
-      copy->variables[1] = nir_deref_var_create(copy, temp);
-
-      nir_instr_insert(cursor, &copy->instr);
-   }
-}
-
-void
-nir_lower_outputs_to_temporaries(nir_shader *shader, nir_function *entrypoint)
-{
-   struct lower_outputs_state state;
-
-   if (shader->stage == MESA_SHADER_TESS_CTRL)
-      return;
-
-   state.shader = shader;
-   exec_list_move_nodes_to(&shader->outputs, &state.old_outputs);
-
-   /* Walk over all of the outputs turn each output into a temporary and
-    * make a new variable for the actual output.
-    */
-   nir_foreach_variable(var, &state.old_outputs) {
-      nir_variable *output = ralloc(shader, nir_variable);
-      memcpy(output, var, sizeof *output);
-
-      /* The orignal is now the temporary */
-      nir_variable *temp = var;
-
-      /* Reparent the name to the new variable */
-      ralloc_steal(output, output->name);
-
-      /* Reparent the constant initializer (if any) */
-      ralloc_steal(output, output->constant_initializer);
-
-      /* Give the output a new name with @out-temp appended */
-      temp->name = ralloc_asprintf(var, "%s@out-temp", output->name);
-      temp->data.mode = nir_var_global;
-      temp->constant_initializer = NULL;
-
-      exec_list_push_tail(&shader->outputs, &output->node);
-   }
-
-   nir_foreach_function(function, shader) {
-      if (function->impl == NULL)
-         continue;
-
-      if (shader->stage == MESA_SHADER_GEOMETRY) {
-         /* For geometry shaders, we have to emit the output copies right
-          * before each EmitVertex call.
-          */
-         nir_foreach_block(block, function->impl) {
-            nir_foreach_instr(instr, block) {
-               if (instr->type != nir_instr_type_intrinsic)
-                  continue;
-
-               nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
-               if (intrin->intrinsic == nir_intrinsic_emit_vertex) {
-                  emit_output_copies(nir_before_instr(&intrin->instr),
-                                     &state);
-               }
-            }
-         }
-      } else if (function == entrypoint) {
-         /* For all other shader types, we need to do the copies right before
-          * the jumps to the end block.
-          */
-         struct set_entry *block_entry;
-         set_foreach(function->impl->end_block->predecessors, block_entry) {
-            struct nir_block *block = (void *)block_entry->key;
-            emit_output_copies(nir_after_block_before_jump(block), &state);
-         }
-      }
-
-      nir_metadata_preserve(function->impl, nir_metadata_block_index |
-                                            nir_metadata_dominance);
-   }
-
-   exec_list_append(&shader->globals, &state.old_outputs);
-}
index fb658ec85df302858d64dc462be50d93f7514f5d..07d24b27442b6c921ff7756dd985d997415a8dd9 100644 (file)
@@ -563,7 +563,7 @@ brw_create_nir(struct brw_context *brw,
    /* First, lower the GLSL IR or Mesa IR to NIR */
    if (shader_prog) {
       nir = glsl_to_nir(shader_prog, stage, options);
-      OPT_V(nir_lower_outputs_to_temporaries, nir_shader_get_entrypoint(nir));
+      OPT_V(nir_lower_io_to_temporaries, nir_shader_get_entrypoint(nir));
    } else {
       nir = prog_to_nir(prog, options);
       OPT_V(nir_convert_to_ssa); /* turn registers into SSA */