nir: Separate texture from sampler in nir_tex_instr
[mesa.git] / src / compiler / nir / nir_clone.c
1 /*
2 * Copyright © 2015 Red Hat
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "nir.h"
25 #include "nir_control_flow_private.h"
26
27 /* Secret Decoder Ring:
28 * clone_foo():
29 * Allocate and clone a foo.
30 * __clone_foo():
31 * Clone body of foo (ie. parent class, embedded struct, etc)
32 */
33
34 typedef struct {
35 /* maps orig ptr -> cloned ptr: */
36 struct hash_table *ptr_table;
37
38 /* List of phi sources. */
39 struct list_head phi_srcs;
40
41 /* new shader object, used as memctx for just about everything else: */
42 nir_shader *ns;
43 } clone_state;
44
45 static void
46 init_clone_state(clone_state *state)
47 {
48 state->ptr_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
49 _mesa_key_pointer_equal);
50 list_inithead(&state->phi_srcs);
51 }
52
53 static void
54 free_clone_state(clone_state *state)
55 {
56 _mesa_hash_table_destroy(state->ptr_table, NULL);
57 }
58
59 static void *
60 lookup_ptr(clone_state *state, const void *ptr)
61 {
62 struct hash_entry *entry;
63
64 if (!ptr)
65 return NULL;
66
67 entry = _mesa_hash_table_search(state->ptr_table, ptr);
68 assert(entry && "Failed to find pointer!");
69 if (!entry)
70 return NULL;
71
72 return entry->data;
73 }
74
75 static void
76 store_ptr(clone_state *state, void *nptr, const void *ptr)
77 {
78 _mesa_hash_table_insert(state->ptr_table, ptr, nptr);
79 }
80
81 static nir_constant *
82 clone_constant(clone_state *state, const nir_constant *c, nir_variable *nvar)
83 {
84 nir_constant *nc = ralloc(nvar, nir_constant);
85
86 nc->value = c->value;
87 nc->num_elements = c->num_elements;
88 nc->elements = ralloc_array(nvar, nir_constant *, c->num_elements);
89 for (unsigned i = 0; i < c->num_elements; i++) {
90 nc->elements[i] = clone_constant(state, c->elements[i], nvar);
91 }
92
93 return nc;
94 }
95
96 /* NOTE: for cloning nir_variable's, bypass nir_variable_create to avoid
97 * having to deal with locals and globals separately:
98 */
99 static nir_variable *
100 clone_variable(clone_state *state, const nir_variable *var)
101 {
102 nir_variable *nvar = rzalloc(state->ns, nir_variable);
103 store_ptr(state, nvar, var);
104
105 nvar->type = var->type;
106 nvar->name = ralloc_strdup(nvar, var->name);
107 nvar->data = var->data;
108 nvar->num_state_slots = var->num_state_slots;
109 nvar->state_slots = ralloc_array(nvar, nir_state_slot, var->num_state_slots);
110 memcpy(nvar->state_slots, var->state_slots,
111 var->num_state_slots * sizeof(nir_state_slot));
112 if (var->constant_initializer) {
113 nvar->constant_initializer =
114 clone_constant(state, var->constant_initializer, nvar);
115 }
116 nvar->interface_type = var->interface_type;
117
118 return nvar;
119 }
120
121 /* clone list of nir_variable: */
122 static void
123 clone_var_list(clone_state *state, struct exec_list *dst,
124 const struct exec_list *list)
125 {
126 exec_list_make_empty(dst);
127 foreach_list_typed(nir_variable, var, node, list) {
128 nir_variable *nvar = clone_variable(state, var);
129 exec_list_push_tail(dst, &nvar->node);
130 }
131 }
132
133 /* NOTE: for cloning nir_register's, bypass nir_global/local_reg_create()
134 * to avoid having to deal with locals and globals separately:
135 */
136 static nir_register *
137 clone_register(clone_state *state, const nir_register *reg)
138 {
139 nir_register *nreg = rzalloc(state->ns, nir_register);
140 store_ptr(state, nreg, reg);
141
142 nreg->num_components = reg->num_components;
143 nreg->num_array_elems = reg->num_array_elems;
144 nreg->index = reg->index;
145 nreg->name = ralloc_strdup(nreg, reg->name);
146 nreg->is_global = reg->is_global;
147 nreg->is_packed = reg->is_packed;
148
149 /* reconstructing uses/defs/if_uses handled by nir_instr_insert() */
150 list_inithead(&nreg->uses);
151 list_inithead(&nreg->defs);
152 list_inithead(&nreg->if_uses);
153
154 return nreg;
155 }
156
157 /* clone list of nir_register: */
158 static void
159 clone_reg_list(clone_state *state, struct exec_list *dst,
160 const struct exec_list *list)
161 {
162 exec_list_make_empty(dst);
163 foreach_list_typed(nir_register, reg, node, list) {
164 nir_register *nreg = clone_register(state, reg);
165 exec_list_push_tail(dst, &nreg->node);
166 }
167 }
168
169 static void
170 __clone_src(clone_state *state, void *ninstr_or_if,
171 nir_src *nsrc, const nir_src *src)
172 {
173 nsrc->is_ssa = src->is_ssa;
174 if (src->is_ssa) {
175 nsrc->ssa = lookup_ptr(state, src->ssa);
176 } else {
177 nsrc->reg.reg = lookup_ptr(state, src->reg.reg);
178 if (src->reg.indirect) {
179 nsrc->reg.indirect = ralloc(ninstr_or_if, nir_src);
180 __clone_src(state, ninstr_or_if, nsrc->reg.indirect, src->reg.indirect);
181 }
182 nsrc->reg.base_offset = src->reg.base_offset;
183 }
184 }
185
186 static void
187 __clone_dst(clone_state *state, nir_instr *ninstr,
188 nir_dest *ndst, const nir_dest *dst)
189 {
190 ndst->is_ssa = dst->is_ssa;
191 if (dst->is_ssa) {
192 nir_ssa_dest_init(ninstr, ndst, dst->ssa.num_components, dst->ssa.name);
193 store_ptr(state, &ndst->ssa, &dst->ssa);
194 } else {
195 ndst->reg.reg = lookup_ptr(state, dst->reg.reg);
196 if (dst->reg.indirect) {
197 ndst->reg.indirect = ralloc(ninstr, nir_src);
198 __clone_src(state, ninstr, ndst->reg.indirect, dst->reg.indirect);
199 }
200 ndst->reg.base_offset = dst->reg.base_offset;
201 }
202 }
203
204 static nir_deref *clone_deref(clone_state *state, const nir_deref *deref,
205 nir_instr *ninstr, nir_deref *parent);
206
207 static nir_deref_var *
208 clone_deref_var(clone_state *state, const nir_deref_var *dvar,
209 nir_instr *ninstr)
210 {
211 nir_variable *nvar = lookup_ptr(state, dvar->var);
212 nir_deref_var *ndvar = nir_deref_var_create(ninstr, nvar);
213
214 if (dvar->deref.child)
215 ndvar->deref.child = clone_deref(state, dvar->deref.child,
216 ninstr, &ndvar->deref);
217
218 return ndvar;
219 }
220
221 static nir_deref_array *
222 clone_deref_array(clone_state *state, const nir_deref_array *darr,
223 nir_instr *ninstr, nir_deref *parent)
224 {
225 nir_deref_array *ndarr = nir_deref_array_create(parent);
226
227 ndarr->deref.type = darr->deref.type;
228 if (darr->deref.child)
229 ndarr->deref.child = clone_deref(state, darr->deref.child,
230 ninstr, &ndarr->deref);
231
232 ndarr->deref_array_type = darr->deref_array_type;
233 ndarr->base_offset = darr->base_offset;
234 if (ndarr->deref_array_type == nir_deref_array_type_indirect)
235 __clone_src(state, ninstr, &ndarr->indirect, &darr->indirect);
236
237 return ndarr;
238 }
239
240 static nir_deref_struct *
241 clone_deref_struct(clone_state *state, const nir_deref_struct *dstr,
242 nir_instr *ninstr, nir_deref *parent)
243 {
244 nir_deref_struct *ndstr = nir_deref_struct_create(parent, dstr->index);
245
246 ndstr->deref.type = dstr->deref.type;
247 if (dstr->deref.child)
248 ndstr->deref.child = clone_deref(state, dstr->deref.child,
249 ninstr, &ndstr->deref);
250
251 return ndstr;
252 }
253
254 static nir_deref *
255 clone_deref(clone_state *state, const nir_deref *dref,
256 nir_instr *ninstr, nir_deref *parent)
257 {
258 switch (dref->deref_type) {
259 case nir_deref_type_array:
260 return &clone_deref_array(state, nir_deref_as_array(dref),
261 ninstr, parent)->deref;
262 case nir_deref_type_struct:
263 return &clone_deref_struct(state, nir_deref_as_struct(dref),
264 ninstr, parent)->deref;
265 default:
266 unreachable("bad deref type");
267 return NULL;
268 }
269 }
270
271 static nir_alu_instr *
272 clone_alu(clone_state *state, const nir_alu_instr *alu)
273 {
274 nir_alu_instr *nalu = nir_alu_instr_create(state->ns, alu->op);
275
276 __clone_dst(state, &nalu->instr, &nalu->dest.dest, &alu->dest.dest);
277 nalu->dest.saturate = alu->dest.saturate;
278 nalu->dest.write_mask = alu->dest.write_mask;
279
280 for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
281 __clone_src(state, &nalu->instr, &nalu->src[i].src, &alu->src[i].src);
282 nalu->src[i].negate = alu->src[i].negate;
283 nalu->src[i].abs = alu->src[i].abs;
284 memcpy(nalu->src[i].swizzle, alu->src[i].swizzle,
285 sizeof(nalu->src[i].swizzle));
286 }
287
288 return nalu;
289 }
290
291 static nir_intrinsic_instr *
292 clone_intrinsic(clone_state *state, const nir_intrinsic_instr *itr)
293 {
294 nir_intrinsic_instr *nitr =
295 nir_intrinsic_instr_create(state->ns, itr->intrinsic);
296
297 unsigned num_variables = nir_intrinsic_infos[itr->intrinsic].num_variables;
298 unsigned num_srcs = nir_intrinsic_infos[itr->intrinsic].num_srcs;
299
300 if (nir_intrinsic_infos[itr->intrinsic].has_dest)
301 __clone_dst(state, &nitr->instr, &nitr->dest, &itr->dest);
302
303 nitr->num_components = itr->num_components;
304 memcpy(nitr->const_index, itr->const_index, sizeof(nitr->const_index));
305
306 for (unsigned i = 0; i < num_variables; i++) {
307 nitr->variables[i] = clone_deref_var(state, itr->variables[i],
308 &nitr->instr);
309 }
310
311 for (unsigned i = 0; i < num_srcs; i++)
312 __clone_src(state, &nitr->instr, &nitr->src[i], &itr->src[i]);
313
314 return nitr;
315 }
316
317 static nir_load_const_instr *
318 clone_load_const(clone_state *state, const nir_load_const_instr *lc)
319 {
320 nir_load_const_instr *nlc =
321 nir_load_const_instr_create(state->ns, lc->def.num_components);
322
323 memcpy(&nlc->value, &lc->value, sizeof(nlc->value));
324
325 store_ptr(state, &nlc->def, &lc->def);
326
327 return nlc;
328 }
329
330 static nir_ssa_undef_instr *
331 clone_ssa_undef(clone_state *state, const nir_ssa_undef_instr *sa)
332 {
333 nir_ssa_undef_instr *nsa =
334 nir_ssa_undef_instr_create(state->ns, sa->def.num_components);
335
336 store_ptr(state, &nsa->def, &sa->def);
337
338 return nsa;
339 }
340
341 static nir_tex_instr *
342 clone_tex(clone_state *state, const nir_tex_instr *tex)
343 {
344 nir_tex_instr *ntex = nir_tex_instr_create(state->ns, tex->num_srcs);
345
346 ntex->sampler_dim = tex->sampler_dim;
347 ntex->dest_type = tex->dest_type;
348 ntex->op = tex->op;
349 __clone_dst(state, &ntex->instr, &ntex->dest, &tex->dest);
350 for (unsigned i = 0; i < ntex->num_srcs; i++) {
351 ntex->src[i].src_type = tex->src[i].src_type;
352 __clone_src(state, &ntex->instr, &ntex->src[i].src, &tex->src[i].src);
353 }
354 ntex->coord_components = tex->coord_components;
355 ntex->is_array = tex->is_array;
356 ntex->is_shadow = tex->is_shadow;
357 ntex->is_new_style_shadow = tex->is_new_style_shadow;
358 memcpy(ntex->const_offset, tex->const_offset, sizeof(ntex->const_offset));
359 ntex->component = tex->component;
360
361 ntex->texture_index = tex->texture_index;
362 if (tex->texture)
363 ntex->texture = clone_deref_var(state, tex->texture, &ntex->instr);
364 ntex->texture_array_size = tex->texture_array_size;
365
366 ntex->sampler_index = tex->sampler_index;
367 if (tex->sampler)
368 ntex->sampler = clone_deref_var(state, tex->sampler, &ntex->instr);
369
370 return ntex;
371 }
372
373 static nir_phi_instr *
374 clone_phi(clone_state *state, const nir_phi_instr *phi, nir_block *nblk)
375 {
376 nir_phi_instr *nphi = nir_phi_instr_create(state->ns);
377
378 __clone_dst(state, &nphi->instr, &nphi->dest, &phi->dest);
379
380 /* Cloning a phi node is a bit different from other instructions. The
381 * sources of phi instructions are the only time where we can use an SSA
382 * def before it is defined. In order to handle this, we just copy over
383 * the sources from the old phi instruction directly and then fix them up
384 * in a second pass once all the instrutions in the function have been
385 * properly cloned.
386 *
387 * In order to ensure that the copied sources (which are the same as the
388 * old phi instruction's sources for now) don't get inserted into the old
389 * shader's use-def lists, we have to add the phi instruction *before* we
390 * set up its sources.
391 */
392 nir_instr_insert_after_block(nblk, &nphi->instr);
393
394 foreach_list_typed(nir_phi_src, src, node, &phi->srcs) {
395 nir_phi_src *nsrc = ralloc(nphi, nir_phi_src);
396
397 /* Just copy the old source for now. */
398 memcpy(nsrc, src, sizeof(*src));
399
400 /* Since we're not letting nir_insert_instr handle use/def stuff for us,
401 * we have to set the parent_instr manually. It doesn't really matter
402 * when we do it, so we might as well do it here.
403 */
404 nsrc->src.parent_instr = &nphi->instr;
405
406 /* Stash it in the list of phi sources. We'll walk this list and fix up
407 * sources at the very end of clone_function_impl.
408 */
409 list_add(&nsrc->src.use_link, &state->phi_srcs);
410
411 exec_list_push_tail(&nphi->srcs, &nsrc->node);
412 }
413
414 return nphi;
415 }
416
417 static nir_jump_instr *
418 clone_jump(clone_state *state, const nir_jump_instr *jmp)
419 {
420 nir_jump_instr *njmp = nir_jump_instr_create(state->ns, jmp->type);
421
422 return njmp;
423 }
424
425 static nir_call_instr *
426 clone_call(clone_state *state, const nir_call_instr *call)
427 {
428 nir_function *ncallee = lookup_ptr(state, call->callee);
429 nir_call_instr *ncall = nir_call_instr_create(state->ns, ncallee);
430
431 for (unsigned i = 0; i < ncall->num_params; i++)
432 ncall->params[i] = clone_deref_var(state, call->params[i], &ncall->instr);
433
434 ncall->return_deref = clone_deref_var(state, call->return_deref,
435 &ncall->instr);
436
437 return ncall;
438 }
439
440 static nir_instr *
441 clone_instr(clone_state *state, const nir_instr *instr)
442 {
443 switch (instr->type) {
444 case nir_instr_type_alu:
445 return &clone_alu(state, nir_instr_as_alu(instr))->instr;
446 case nir_instr_type_intrinsic:
447 return &clone_intrinsic(state, nir_instr_as_intrinsic(instr))->instr;
448 case nir_instr_type_load_const:
449 return &clone_load_const(state, nir_instr_as_load_const(instr))->instr;
450 case nir_instr_type_ssa_undef:
451 return &clone_ssa_undef(state, nir_instr_as_ssa_undef(instr))->instr;
452 case nir_instr_type_tex:
453 return &clone_tex(state, nir_instr_as_tex(instr))->instr;
454 case nir_instr_type_phi:
455 unreachable("Cannot clone phis with clone_instr");
456 case nir_instr_type_jump:
457 return &clone_jump(state, nir_instr_as_jump(instr))->instr;
458 case nir_instr_type_call:
459 return &clone_call(state, nir_instr_as_call(instr))->instr;
460 case nir_instr_type_parallel_copy:
461 unreachable("Cannot clone parallel copies");
462 default:
463 unreachable("bad instr type");
464 return NULL;
465 }
466 }
467
468 static nir_block *
469 clone_block(clone_state *state, struct exec_list *cf_list, const nir_block *blk)
470 {
471 /* Don't actually create a new block. Just use the one from the tail of
472 * the list. NIR guarantees that the tail of the list is a block and that
473 * no two blocks are side-by-side in the IR; It should be empty.
474 */
475 nir_block *nblk =
476 exec_node_data(nir_block, exec_list_get_tail(cf_list), cf_node.node);
477 assert(nblk->cf_node.type == nir_cf_node_block);
478 assert(exec_list_is_empty(&nblk->instr_list));
479
480 /* We need this for phi sources */
481 store_ptr(state, nblk, blk);
482
483 nir_foreach_instr(blk, instr) {
484 if (instr->type == nir_instr_type_phi) {
485 /* Phi instructions are a bit of a special case when cloning because
486 * we don't want inserting the instruction to automatically handle
487 * use/defs for us. Instead, we need to wait until all the
488 * blocks/instructions are in so that we can set their sources up.
489 */
490 clone_phi(state, nir_instr_as_phi(instr), nblk);
491 } else {
492 nir_instr *ninstr = clone_instr(state, instr);
493 nir_instr_insert_after_block(nblk, ninstr);
494 }
495 }
496
497 return nblk;
498 }
499
500 static void
501 clone_cf_list(clone_state *state, struct exec_list *dst,
502 const struct exec_list *list);
503
504 static nir_if *
505 clone_if(clone_state *state, struct exec_list *cf_list, const nir_if *i)
506 {
507 nir_if *ni = nir_if_create(state->ns);
508
509 __clone_src(state, ni, &ni->condition, &i->condition);
510
511 nir_cf_node_insert_end(cf_list, &ni->cf_node);
512
513 clone_cf_list(state, &ni->then_list, &i->then_list);
514 clone_cf_list(state, &ni->else_list, &i->else_list);
515
516 return ni;
517 }
518
519 static nir_loop *
520 clone_loop(clone_state *state, struct exec_list *cf_list, const nir_loop *loop)
521 {
522 nir_loop *nloop = nir_loop_create(state->ns);
523
524 nir_cf_node_insert_end(cf_list, &nloop->cf_node);
525
526 clone_cf_list(state, &nloop->body, &loop->body);
527
528 return nloop;
529 }
530
531 /* clone list of nir_cf_node: */
532 static void
533 clone_cf_list(clone_state *state, struct exec_list *dst,
534 const struct exec_list *list)
535 {
536 foreach_list_typed(nir_cf_node, cf, node, list) {
537 switch (cf->type) {
538 case nir_cf_node_block:
539 clone_block(state, dst, nir_cf_node_as_block(cf));
540 break;
541 case nir_cf_node_if:
542 clone_if(state, dst, nir_cf_node_as_if(cf));
543 break;
544 case nir_cf_node_loop:
545 clone_loop(state, dst, nir_cf_node_as_loop(cf));
546 break;
547 default:
548 unreachable("bad cf type");
549 }
550 }
551 }
552
553 static nir_function_impl *
554 clone_function_impl(clone_state *state, const nir_function_impl *fi,
555 nir_function *nfxn)
556 {
557 nir_function_impl *nfi = nir_function_impl_create(nfxn);
558
559 clone_var_list(state, &nfi->locals, &fi->locals);
560 clone_reg_list(state, &nfi->registers, &fi->registers);
561 nfi->reg_alloc = fi->reg_alloc;
562
563 nfi->num_params = fi->num_params;
564 nfi->params = ralloc_array(state->ns, nir_variable *, fi->num_params);
565 for (unsigned i = 0; i < fi->num_params; i++) {
566 nfi->params[i] = lookup_ptr(state, fi->params[i]);
567 }
568 nfi->return_var = lookup_ptr(state, fi->return_var);
569
570 assert(list_empty(&state->phi_srcs));
571
572 clone_cf_list(state, &nfi->body, &fi->body);
573
574 /* After we've cloned almost everything, we have to walk the list of phi
575 * sources and fix them up. Thanks to loops, the block and SSA value for a
576 * phi source may not be defined when we first encounter it. Instead, we
577 * add it to the phi_srcs list and we fix it up here.
578 */
579 list_for_each_entry_safe(nir_phi_src, src, &state->phi_srcs, src.use_link) {
580 src->pred = lookup_ptr(state, src->pred);
581 assert(src->src.is_ssa);
582 src->src.ssa = lookup_ptr(state, src->src.ssa);
583
584 /* Remove from this list and place in the uses of the SSA def */
585 list_del(&src->src.use_link);
586 list_addtail(&src->src.use_link, &src->src.ssa->uses);
587 }
588 assert(list_empty(&state->phi_srcs));
589
590 /* All metadata is invalidated in the cloning process */
591 nfi->valid_metadata = 0;
592
593 return nfi;
594 }
595
596 static nir_function *
597 clone_function(clone_state *state, const nir_function *fxn, nir_shader *ns)
598 {
599 assert(ns == state->ns);
600 nir_function *nfxn = nir_function_create(ns, fxn->name);
601
602 /* Needed for call instructions */
603 store_ptr(state, nfxn, fxn);
604
605 nfxn->num_params = fxn->num_params;
606 nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
607 memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
608
609 nfxn->return_type = fxn->return_type;
610
611 /* At first glance, it looks like we should clone the function_impl here.
612 * However, call instructions need to be able to reference at least the
613 * function and those will get processed as we clone the function_impl's.
614 * We stop here and do function_impls as a second pass.
615 */
616
617 return nfxn;
618 }
619
620 nir_shader *
621 nir_shader_clone(void *mem_ctx, const nir_shader *s)
622 {
623 clone_state state;
624 init_clone_state(&state);
625
626 nir_shader *ns = nir_shader_create(mem_ctx, s->stage, s->options);
627 state.ns = ns;
628
629 clone_var_list(&state, &ns->uniforms, &s->uniforms);
630 clone_var_list(&state, &ns->inputs, &s->inputs);
631 clone_var_list(&state, &ns->outputs, &s->outputs);
632 clone_var_list(&state, &ns->globals, &s->globals);
633 clone_var_list(&state, &ns->system_values, &s->system_values);
634
635 /* Go through and clone functions */
636 foreach_list_typed(nir_function, fxn, node, &s->functions)
637 clone_function(&state, fxn, ns);
638
639 /* Only after all functions are cloned can we clone the actual function
640 * implementations. This is because nir_call_instr's need to reference the
641 * functions of other functions and we don't know what order the functions
642 * will have in the list.
643 */
644 nir_foreach_function(s, fxn) {
645 nir_function *nfxn = lookup_ptr(&state, fxn);
646 clone_function_impl(&state, fxn->impl, nfxn);
647 }
648
649 clone_reg_list(&state, &ns->registers, &s->registers);
650 ns->reg_alloc = s->reg_alloc;
651
652 ns->info = s->info;
653 ns->info.name = ralloc_strdup(ns, ns->info.name);
654 if (ns->info.label)
655 ns->info.label = ralloc_strdup(ns, ns->info.label);
656
657 ns->num_inputs = s->num_inputs;
658 ns->num_uniforms = s->num_uniforms;
659 ns->num_outputs = s->num_outputs;
660
661 free_clone_state(&state);
662
663 return ns;
664 }