<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 16, 2016 at 6:24 AM, Timothy Arceri <span dir="ltr"><<a href="mailto:timothy.arceri@collabora.com" target="_blank">timothy.arceri@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
src/compiler/nir/nir.h | 2 ++<br>
src/compiler/nir/nir_clone.c | 41 ++++++++++++++++++++++++++++++<wbr>++++-------<br>
2 files changed, 36 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index 29a6f45..d052cad 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2338,6 +2338,8 @@ void nir_print_instr(const nir_instr *instr, FILE *fp);<br>
<br>
nir_shader *nir_shader_clone(void *mem_ctx, const nir_shader *s);<br>
nir_function_impl *nir_function_impl_clone(const nir_function_impl *fi);<br>
+void nir_clone_loop_list(struct exec_list *dst, const struct exec_list *list,<br>
+ struct hash_table *remap_table, nir_shader *ns);<br>
nir_constant *nir_constant_clone(const nir_constant *c, nir_variable *var);<br>
nir_variable *nir_variable_clone(const nir_variable *c, nir_shader *shader);<br>
<br>
diff --git a/src/compiler/nir/nir_clone.c b/src/compiler/nir/nir_clone.c<br>
index 8808333..7afccbb 100644<br>
--- a/src/compiler/nir/nir_clone.c<br>
+++ b/src/compiler/nir/nir_clone.c<br>
@@ -35,6 +35,11 @@ typedef struct {<br>
/* True if we are cloning an entire shader. */<br>
bool global_clone;<br>
<br>
+ /* This allows us to clone a loop body without having to add srcs from<br>
+ * outside the loop to the remap table. This is useful for loop unrolling.<br>
+ */<br>
+ bool allow_remap_fallback;<br>
+<br>
/* maps orig ptr -> cloned ptr: */<br>
struct hash_table *remap_table;<br>
<br>
@@ -46,11 +51,19 @@ typedef struct {<br>
} clone_state;<br>
<br>
static void<br>
-init_clone_state(clone_state *state, bool global)<br>
+init_clone_state(clone_state *state, struct hash_table *remap_table,<br>
+ bool global, bool allow_remap_fallback)<br>
{<br>
state->global_clone = global;<br>
- state->remap_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,<br>
- _mesa_key_pointer_equal);<br>
+ state->allow_remap_fallback = allow_remap_fallback;<br>
+<br>
+ if (remap_table) {<br>
+ state->remap_table = remap_table;<br>
+ } else {<br>
+ state->remap_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,<br>
+ _mesa_key_pointer_equal);<br>
+ }<br>
+<br>
list_inithead(&state->phi_<wbr>srcs);<br>
}<br>
<br>
@@ -72,9 +85,8 @@ _lookup_ptr(clone_state *state, const void *ptr, bool global)<br>
return (void *)ptr;<br>
<br>
entry = _mesa_hash_table_search(state-<wbr>>remap_table, ptr);<br>
- assert(entry && "Failed to find pointer!");<br>
if (!entry)<br>
- return NULL;<br>
+ return state->allow_remap_fallback ? (void *)ptr : NULL;<br></blockquote><div><br></div><div>How about:<br><br></div><div>if (!entry) {<br></div><div> assert(state->allow_remap_fallback);<br></div><div> return (void *)ptr;<br>}<br><br></div><div>That avoids an extra bit of control flow and keeps us asserting in the regular "clone a shader" case.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
return entry->data;<br>
}<br>
@@ -613,6 +625,21 @@ fixup_phi_srcs(clone_state *state)<br>
assert(list_empty(&state->phi_<wbr>srcs));<br>
}<br>
<br>
+void<br>
+nir_clone_loop_list(struct exec_list *dst, const struct exec_list *list,<br></blockquote><div><br></div><div>Maybe take a nir_loop instead of an exec_list. It would give us a little type-saftey<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ struct hash_table *remap_table, nir_shader *ns)<br></blockquote><div><br></div><div>You could dig the nir_shader out of the loop with nir_cf_node_get_function()<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+{<br>
+ clone_state state;<br>
+ init_clone_state(&state, remap_table, false, true);<br>
+<br>
+ /* We use the same shader */<br>
+ state.ns = ns;<br>
+<br>
+ clone_cf_list(&state, dst, list);<br>
+<br>
+ fixup_phi_srcs(&state);<br>
+}<br>
+<br>
static nir_function_impl *<br>
clone_function_impl(clone_<wbr>state *state, const nir_function_impl *fi)<br>
{<br>
@@ -646,7 +673,7 @@ nir_function_impl *<br>
nir_function_impl_clone(const nir_function_impl *fi)<br>
{<br>
clone_state state;<br>
- init_clone_state(&state, false);<br>
+ init_clone_state(&state, NULL, false, false);<br>
<br>
/* We use the same shader */<br>
state.ns = fi->function->shader;<br>
@@ -686,7 +713,7 @@ nir_shader *<br>
nir_shader_clone(void *mem_ctx, const nir_shader *s)<br>
{<br>
clone_state state;<br>
- init_clone_state(&state, true);<br>
+ init_clone_state(&state, NULL, true, false);<br>
<br>
nir_shader *ns = nir_shader_create(mem_ctx, s->stage, s->options);<br>
state.ns = ns;<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.7.4<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>