nir/clone: Add a helper for cloning most instruction types
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 18 May 2020 15:39:43 +0000 (10:39 -0500)
committerEric Anholt <eric@anholt.net>
Wed, 2 Sep 2020 16:59:17 +0000 (09:59 -0700)
@anholt needed it for nir_to_tgsi, and the desire comes up frequently.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6567>

src/compiler/nir/nir.h
src/compiler/nir/nir_clone.c

index 1d1bb6c958470db3b21d30c5dc50ad8a3c55b2ad..cb702ca3023aad2386e5f8310747369b1d9e976d 100644 (file)
@@ -3855,6 +3855,9 @@ void nir_print_shader_annotated(nir_shader *shader, FILE *fp, struct hash_table
 void nir_print_instr(const nir_instr *instr, FILE *fp);
 void nir_print_deref(const nir_deref_instr *deref, FILE *fp);
 
+/** Shallow clone of a single instruction. */
+nir_instr *nir_instr_clone(nir_shader *s, const nir_instr *orig);
+
 /** Shallow clone of a single ALU instruction. */
 nir_alu_instr *nir_alu_instr_clone(nir_shader *s, const nir_alu_instr *orig);
 
index 946b9ebf0a75fc97106ebd1f502004875c7eea8d..05689b097a86b3223ef5e9e3ff018e797280370c 100644 (file)
@@ -517,6 +517,16 @@ clone_instr(clone_state *state, const nir_instr *instr)
    }
 }
 
+nir_instr *
+nir_instr_clone(nir_shader *shader, const nir_instr *orig)
+{
+   clone_state state = {
+      .allow_remap_fallback = true,
+      .ns = shader,
+   };
+   return clone_instr(&state, orig);
+}
+
 static nir_block *
 clone_block(clone_state *state, struct exec_list *cf_list, const nir_block *blk)
 {