The idea here is two write the C equivalent of "copy constructors" for NIR datatypes. Not everything needs a copy constructor but, at the very least, we at least need to be able to do a deep copy nir_function_impl's and everything they contain. Most of this should be straightforward as it's simply a matter of recursing into data structures and copying everything.
There is a little complication when it comes to variables, registers, and SSA values, however. When we copy functions we will need some sort of a "remap table" so that the copied functions can use the copied variables/registers/SSA values rather than the originals.
Also, we have to be a bit careful with nir_phi_instr's as the SSA definitions they use in their sources may not come before they do in the shader. For these, we have to create the actual instructions first and then fill out their sources as a seperate pass after the rest of the instructions have been created. In fact, it may be easier (for the sake of correctness) to use this sort of two-step copying procedure for all instructions.
I need something along the lines of nir_shader_clone() for my gallium glsl->nir patchset, so I'll start working on this (assuming no one else has.. if I'm stepping on any toes, please speak up!)
Mostly I plan to implement cloning of entire shader (although I think after that cloning nir_function_impl's, etc, should be trivial)
Awesome, thanks Rob!
This has existed for a long time. We're really bad at actually closing feature bugs. Thanks Rob!