nir: Add a lowering pass to split 64bit phis
[mesa.git] / src / compiler / nir / nir_clone.c
index d5ae7f177931148ec0997060b23e250ed075530d..9e0bd7bf8918cbf9f61c9f1e9b170ab04c490144 100644 (file)
@@ -85,6 +85,11 @@ _lookup_ptr(clone_state *state, const void *ptr, bool global)
    if (!state->global_clone && global)
       return (void *)ptr;
 
+   if (unlikely(!state->remap_table)) {
+      assert(state->allow_remap_fallback);
+      return (void *)ptr;
+   }
+
    entry = _mesa_hash_table_search(state->remap_table, ptr);
    if (!entry) {
       assert(state->allow_remap_fallback);
@@ -254,7 +259,8 @@ __clone_dst(clone_state *state, nir_instr *ninstr,
    if (dst->is_ssa) {
       nir_ssa_dest_init(ninstr, ndst, dst->ssa.num_components,
                         dst->ssa.bit_size, dst->ssa.name);
-      add_remap(state, &ndst->ssa, &dst->ssa);
+      if (likely(state->remap_table))
+         add_remap(state, &ndst->ssa, &dst->ssa);
    } else {
       ndst->reg.reg = remap_reg(state, dst->reg.reg);
       if (dst->reg.indirect) {
@@ -265,26 +271,6 @@ __clone_dst(clone_state *state, nir_instr *ninstr,
    }
 }
 
-nir_alu_instr *
-nir_alu_instr_clone(nir_shader *shader, const nir_alu_instr *orig)
-{
-   nir_alu_instr *clone = nir_alu_instr_create(shader, orig->op);
-
-   clone->exact = orig->exact;
-
-   for (unsigned i = 0; i < nir_op_infos[orig->op].num_inputs; i++)
-      nir_alu_src_copy(&clone->src[i], &orig->src[i], clone);
-
-   nir_ssa_dest_init(&clone->instr,
-                     &clone->dest.dest,
-                     orig->dest.dest.ssa.num_components,
-                     orig->dest.dest.ssa.bit_size,
-                     orig->dest.dest.ssa.name);
-   clone->dest.write_mask = orig->dest.write_mask;
-
-   return clone;
-}
-
 static nir_alu_instr *
 clone_alu(clone_state *state, const nir_alu_instr *alu)
 {
@@ -308,6 +294,16 @@ clone_alu(clone_state *state, const nir_alu_instr *alu)
    return nalu;
 }
 
+nir_alu_instr *
+nir_alu_instr_clone(nir_shader *shader, const nir_alu_instr *orig)
+{
+   clone_state state = {
+      .allow_remap_fallback = true,
+      .ns = shader,
+   };
+   return clone_alu(&state, orig);
+}
+
 static nir_deref_instr *
 clone_deref_instr(clone_state *state, const nir_deref_instr *deref)
 {
@@ -660,6 +656,9 @@ nir_cf_list_clone(nir_cf_list *dst, nir_cf_list *src, nir_cf_node *parent,
    clone_cf_list(&state, &dst->list, &src->list);
 
    fixup_phi_srcs(&state);
+
+   if (!remap_table)
+      free_clone_state(&state);
 }
 
 static nir_function_impl *
@@ -732,12 +731,7 @@ nir_shader_clone(void *mem_ctx, const nir_shader *s)
    nir_shader *ns = nir_shader_create(mem_ctx, s->info.stage, s->options, NULL);
    state.ns = ns;
 
-   clone_var_list(&state, &ns->uniforms, &s->uniforms);
-   clone_var_list(&state, &ns->inputs,   &s->inputs);
-   clone_var_list(&state, &ns->outputs,  &s->outputs);
-   clone_var_list(&state, &ns->shared,   &s->shared);
-   clone_var_list(&state, &ns->globals,  &s->globals);
-   clone_var_list(&state, &ns->system_values, &s->system_values);
+   clone_var_list(&state, &ns->variables, &s->variables);
 
    /* Go through and clone functions */
    foreach_list_typed(nir_function, fxn, node, &s->functions)
@@ -800,12 +794,7 @@ nir_shader_replace(nir_shader *dst, nir_shader *src)
    /* We have to move all the linked lists over separately because we need the
     * pointers in the list elements to point to the lists in dst and not src.
     */
-   exec_list_move_nodes_to(&src->uniforms,      &dst->uniforms);
-   exec_list_move_nodes_to(&src->inputs,        &dst->inputs);
-   exec_list_move_nodes_to(&src->outputs,       &dst->outputs);
-   exec_list_move_nodes_to(&src->shared,        &dst->shared);
-   exec_list_move_nodes_to(&src->globals,       &dst->globals);
-   exec_list_move_nodes_to(&src->system_values, &dst->system_values);
+   exec_list_move_nodes_to(&src->variables, &dst->variables);
 
    /* Now move the functions over.  This takes a tiny bit more work */
    exec_list_move_nodes_to(&src->functions, &dst->functions);