summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2015-12-18 11:16:16 -0800
committerJason Ekstrand <jason.ekstrand@intel.com>2015-12-23 13:49:56 -0800
commit1749e667ea38ec539d29c92c08f94738afcb91ad (patch)
treed2080fe16854c6f9159b3b08639173966720e549
parent413a9d351746a0e3ecb274a8f39dcefec7010edd (diff)
downloadexternal_mesa3d-1749e667ea38ec539d29c92c08f94738afcb91ad.zip
external_mesa3d-1749e667ea38ec539d29c92c08f94738afcb91ad.tar.gz
external_mesa3d-1749e667ea38ec539d29c92c08f94738afcb91ad.tar.bz2
nir: Add a stub function inlining pass
All it does is remove the return at the end, but it's good enough for simple functions.
-rw-r--r--src/glsl/Makefile.sources1
-rw-r--r--src/glsl/nir/nir.h3
-rw-r--r--src/glsl/nir/nir_lower_returns.c78
3 files changed, 82 insertions, 0 deletions
diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
index e64c31e..32fbf6d 100644
--- a/src/glsl/Makefile.sources
+++ b/src/glsl/Makefile.sources
@@ -44,6 +44,7 @@ NIR_FILES = \
nir/nir_lower_alu_to_scalar.c \
nir/nir_lower_atomics.c \
nir/nir_lower_clip.c \
+ nir/nir_lower_returns.c \
nir/nir_lower_global_vars_to_local.c \
nir/nir_lower_gs_intrinsics.c \
nir/nir_lower_load_const_to_scalar.c \
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 021c428..0cf5f80 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1998,6 +1998,9 @@ int nir_gs_count_vertices(const nir_shader *shader);
bool nir_split_var_copies(nir_shader *shader);
+bool nir_lower_returns_impl(nir_function_impl *impl);
+bool nir_lower_returns(nir_shader *shader);
+
void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, void *mem_ctx);
void nir_lower_var_copies(nir_shader *shader);
diff --git a/src/glsl/nir/nir_lower_returns.c b/src/glsl/nir/nir_lower_returns.c
new file mode 100644
index 0000000..a15d033
--- /dev/null
+++ b/src/glsl/nir/nir_lower_returns.c
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+#include "nir.h"
+
+static bool
+assert_no_returns_block(nir_block *block, void *state)
+{
+ (void)state;
+
+ nir_foreach_instr(block, instr) {
+ if (instr->type != nir_instr_type_jump)
+ continue;
+
+ nir_jump_instr *jump = nir_instr_as_jump(instr);
+ assert(jump->type != nir_jump_return);
+ }
+
+ return true;
+}
+
+bool
+nir_lower_returns_impl(nir_function_impl *impl)
+{
+ bool progress = false;
+
+ assert(impl->end_block->predecessors->entries == 1);
+
+ struct set_entry *entry =
+ _mesa_set_next_entry(impl->end_block->predecessors, NULL);
+
+ nir_block *last_block = (nir_block *)entry->key;
+
+ nir_instr *last_instr = nir_block_last_instr(last_block);
+ if (last_instr && last_instr->type == nir_instr_type_jump) {
+ nir_jump_instr *jump = nir_instr_as_jump(last_instr);
+ assert(jump->type == nir_jump_return);
+ nir_instr_remove(&jump->instr);
+ progress = true;
+ }
+
+ nir_foreach_block(impl, assert_no_returns_block, NULL);
+
+ return progress;
+}
+
+bool
+nir_lower_returns(nir_shader *shader)
+{
+ bool progress = false;
+
+ nir_foreach_overload(shader, overload) {
+ if (overload->impl)
+ progress = nir_lower_returns_impl(overload->impl) || progress;
+ }
+
+ return progress;
+}