Debian Codegraph @

src/imagination/pco/pco_opt.c

raw
1 /*
2 * Copyright © 2024 Imagination Technologies Ltd.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 /**
8 * \file pco_opt.c
9 *
10 * \brief PCO optimization passes.
11 */
12
13 #include "pco.h"
14 #include "pco_builder.h"
15 #include "util/bitscan.h"
16 #include "util/bitset.h"
17 #include "util/macros.h"
18 #include "util/ralloc.h"
19 #include "util/u_dynarray.h"
20
21 #include <assert.h>
22 #include <stdbool.h>
23
24 /** Source use. */
25 struct pco_use {
26 pco_instr *instr;
27 pco_ref *psrc;
28 };
29
30 /** Shared optimization context. */
31 struct pco_opt_ctx {
32 void *mem_ctx;
33 struct util_dynarray mods;
34 };
35
36 /**
37 * \brief Prepares modifiers and their users for propagation.
38 *
39 * Instructions with commutative sources may use a modifier in the source which
40 * can't have said modifier applied to it, e.g. fadd can have {abs,neg,flr} set
41 * in src0, but src1 only supports abs.
42 *
43 * \param[in,out] shader PCO shader.
44 * \param[in,out] ctx Shared optimization context.
45 * \return True if any instructions were modified.
46 */
47 static inline bool pco_opt_prep_mods(pco_shader *shader,
48 struct pco_opt_ctx *ctx)
49 {
50 bool progress = false;
51
52 util_dynarray_init(&ctx->mods, ctx->mem_ctx);
53
54 /* TODO: support for more modifiers/ops. */
55 /* TODO: support cases where > 1 modifier can be applied (e.g. .abs.neg),
56 * and where modifiers might need to be applied on more than one source.
57 */
58 pco_foreach_func_in_shader (func, shader) {
59 pco_foreach_instr_in_func_safe (mod, func) {
60 if (mod->op != PCO_OP_FNEG && mod->op != PCO_OP_FABS &&
61 mod->op != PCO_OP_FFLR)
62 continue;
63
64 pco_foreach_instr_in_func_from (instr, mod) {
65 if (instr->op != PCO_OP_FADD && instr->op != PCO_OP_FMUL)
66 continue;
67
68 pco_ref *match_src = NULL;
69 pco_ref *other_src = NULL;
70 pco_foreach_instr_src (psrc, instr) {
71 if (!pco_ref_is_ssa(*psrc) || psrc->val != mod->dest[0].val)
72 other_src = psrc;
73 else
74 match_src = psrc;
75 }
76
77 /* Instruction doesn't use the mod. */
78 if (!match_src)
79 continue;
80
81 /* Mod used in *both* sources; swapping would do nothing. */
82 if (!other_src)
83 continue;
84
85 unsigned match_src_index = match_src - instr->src;
86 unsigned other_src_index = other_src - instr->src;
87
88 bool match_has_mod = false;
89 bool other_has_mod = false;
90
91 switch (mod->op) {
92 case PCO_OP_FNEG:
93 match_has_mod = pco_instr_src_has_neg(instr, match_src_index);
94 other_has_mod = pco_instr_src_has_neg(instr, other_src_index);
95 break;
96
97 case PCO_OP_FABS:
98 match_has_mod = pco_instr_src_has_abs(instr, match_src_index);
99 other_has_mod = pco_instr_src_has_abs(instr, other_src_index);
100 break;
101
102 case PCO_OP_FFLR:
103 match_has_mod = pco_instr_src_has_flr(instr, match_src_index);
104 other_has_mod = pco_instr_src_has_flr(instr, other_src_index);
105 break;
106
107 default:
108 UNREACHABLE("");
109 }
110
111 /* Source can already have the mod set. */
112 if (match_has_mod)
113 continue;
114
115 /* Other source can't have the mod set either. */
116 if (!other_has_mod)
117 continue;
118
119 /* Swap the sources. */
120 pco_ref tmp = *match_src;
121 *match_src = *other_src;
122 *other_src = tmp;
123
124 progress = true;
125 }
126
127 /* Rewrite the mod op to a mov. */
128 pco_ref src = mod->src[0];
129 switch (mod->op) {
130 case PCO_OP_FNEG:
131 src = pco_ref_neg(src);
132 break;
133
134 case PCO_OP_FABS:
135 src = pco_ref_abs(src);
136 break;
137
138 case PCO_OP_FFLR:
139 src = pco_ref_flr(src);
140 break;
141
142 default:
143 UNREACHABLE("");
144 }
145
146 pco_builder b = pco_builder_create(func, pco_cursor_before_instr(mod));
147 pco_instr *mov = pco_mov(&b, mod->dest[0], src);
148 util_dynarray_append(&ctx->mods, mov);
149 pco_instr_delete(mod);
150
151 progress = true;
152 }
153 }
154
155 return progress;
156 }
157
158 /**
159 * \brief Lowers modifiers to hardware instructions.
160 *
161 * \param[in,out] shader PCO shader.
162 * \param[in,out] ctx Shared optimization context.
163 * \return True if any instructions were modified.
164 */
165 static inline bool pco_opt_lower_mods(pco_shader *shader,
166 struct pco_opt_ctx *ctx)
167 {
168 bool progress = false;
169
170 util_dynarray_foreach (&ctx->mods, pco_instr *, pmod) {
171 pco_instr *mod = *pmod;
172
173 pco_builder b =
174 pco_builder_create(mod->parent_func, pco_cursor_before_instr(mod));
175
176 if (mod->src[0].flr)
177 pco_fadd(&b, mod->dest[0], mod->src[0], pco_zero);
178 else
179 pco_mbyp(&b, mod->dest[0], mod->src[0]);
180
181 pco_instr_delete(mod);
182
183 progress = true;
184 }
185
186 return progress;
187 }
188
189 /**
190 * \brief Checks if an instruction can be back-propagated.
191 *
192 * \param[in] to Instruction being back-propagated to.
193 * \param[in] from Instruction being back-propagated from.
194 * \return True if from can be back-propagated.
195 */
196 static inline bool can_back_prop_instr(const pco_instr *to,
197 const pco_instr *from)
198 {
199 const struct pco_op_info *info = &pco_op_info[from->op];
200
201 /* Ensure any op mods set in from can also be set in to. */
202 u_foreach_bit64 (mod, info->mods) {
203 if (pco_instr_has_mod(from, mod) && pco_instr_mod_is_set(from, mod) &&
204 !pco_instr_has_mod(to, mod))
205 return false;
206 }
207
208 return true;
209 }
210
211 /**
212 * \brief Transfers any op mods that have been set.
213 *
214 * \param[in] to Instruction receiving the op mods.
215 * \param[in] from Instruction providing the op mods.
216 */
217 static inline void xfer_set_op_mods(pco_instr *to, const pco_instr *from)
218 {
219 const struct pco_op_info *info = &pco_op_info[from->op];
220
221 /* Transfer set op mods. */
222 u_foreach_bit64 (mod, info->mods) {
223 if (pco_instr_has_mod(from, mod) && pco_instr_mod_is_set(from, mod)) {
224 assert(pco_instr_has_mod(to, mod));
225 pco_instr_set_mod(to, mod, pco_instr_get_mod(from, mod));
226 }
227 }
228 }
229
230 /**
231 * \brief Tries to back-propagate an instruction.
232 *
233 * \param[in] uses Global list of uses.
234 * \param[in] instr Instruction to try and back-propagate.
235 * \return True if back-propagation was successful.
236 */
237 static inline bool try_back_prop_instr(struct pco_use *uses, pco_instr *instr)
238 {
239 pco_ref *pdest_to = &instr->dest[0];
240 if (instr->num_dests != 1 || !pco_ref_is_ssa(*pdest_to))
241 return false;
242
243 struct pco_use *use = &uses[pdest_to->val];
244 if (!use->instr)
245 return false;
246
247 /* TODO: allow propagating instructions which can have their dest/op
248 * modifiers set to perform the same operations as use source modifiers.
249 *
250 * Make sure to check in can_back_prop_instr when implementing this.
251 * We're fine for now since mov has no settable dest mods.
252 */
253 if (use->instr->op != PCO_OP_MOV || pco_ref_has_mods_set(*use->psrc))
254 return false;
255
256 if (!can_back_prop_instr(instr, use->instr))
257 return false;
258
259 pco_ref *pdest_from = &use->instr->dest[0];
260
261 if (pco_ref_is_idx_reg(*pdest_from))
262 return false;
263
264 if (pco_ref_is_reg(*pdest_from) &&
265 pco_ref_get_reg_class(*pdest_from) == PCO_REG_CLASS_PIXOUT) {
266 return false;
267
268 bool has_isp_fb = false;
269
270 pco_foreach_instr_in_func_from_rev (rev_instr, use->instr) {
271 if (rev_instr == instr)
272 break;
273
274 if (rev_instr->op == PCO_OP_ALPHAF || rev_instr->op == PCO_OP_DEPTHF) {
275 has_isp_fb = true;
276 break;
277 }
278 }
279
280 if (has_isp_fb)
281 return false;
282
283 /* Don't move pixout regs into instructions that already use them. */
284 pco_foreach_instr_src (psrc, instr) {
285 if (pco_ref_is_reg(*psrc) &&
286 pco_ref_get_reg_class(*psrc) == PCO_REG_CLASS_PIXOUT) {
287 return false;
288 }
289 }
290 }
291
292 assert(pco_ref_get_bits(*pdest_from) == pco_ref_get_bits(*pdest_to));
293 assert(pco_ref_get_chans(*pdest_from) == pco_ref_get_chans(*pdest_to));
294 assert(!pco_ref_has_mods_set(*pdest_from) &&
295 !pco_ref_has_mods_set(*pdest_to));
296
297 /* Propagate the destination and the set op mods. */
298 /* TODO: types? */
299 *pdest_to = *pdest_from;
300 xfer_set_op_mods(instr, use->instr);
301 pco_instr_delete(use->instr);
302
303 return true;
304 }
305
306 /**
307 * \brief Instruction back-propagation pass.
308 *
309 * \param[in,out] shader PCO shader.
310 * \return True if any back-propagations were performed.
311 */
312 static inline bool pco_opt_back_prop(pco_shader *shader)
313 {
314 bool progress = false;
315 struct pco_use *uses;
316 BITSET_WORD *multi_uses;
317
318 pco_foreach_func_in_shader_rev (func, shader) {
319 uses = rzalloc_array_size(NULL, sizeof(*uses), func->next_ssa);
320 multi_uses = rzalloc_array_size(uses,
321 sizeof(*multi_uses),
322 BITSET_WORDS(func->next_ssa));
323
324 pco_foreach_instr_in_func_safe_rev (instr, func) {
325 pco_foreach_instr_src_ssa (psrc, instr) {
326 if (BITSET_TEST(multi_uses, psrc->val) || uses[psrc->val].instr) {
327 BITSET_SET(multi_uses, psrc->val);
328 uses[psrc->val].instr = NULL;
329 continue;
330 }
331
332 uses[psrc->val] = (struct pco_use){
333 .instr = instr,
334 .psrc = psrc,
335 };
336 }
337
338 progress |= try_back_prop_instr(uses, instr);
339 }
340
341 ralloc_free(uses);
342 }
343
344 return progress;
345 }
346
347 /**
348 * \brief Checks if a source can be forward-propagated.
349 *
350 * \param[in] to_instr Instruction being forward-propagated to.
351 * \param[in] to Source being forward-propagated to.
352 * \param[in] from Source being forward-propagated from.
353 * \return True if from can be forward-propagated.
354 */
355 static inline bool can_fwd_prop_src(const pco_instr *to_instr,
356 const pco_ref *to,
357 const pco_ref *from)
358 {
359 /* Check sizes. */
360 if (pco_ref_get_bits(*from) != pco_ref_get_bits(*to))
361 return false;
362
363 if (pco_ref_get_chans(*from) != pco_ref_get_chans(*to))
364 return false;
365
366 /* See if the modifiers can be propagated. */
367 unsigned to_src_index = to - to_instr->src;
368 if (pco_ref_has_mods_set(*from)) {
369 if (from->oneminus && !pco_instr_src_has_oneminus(to_instr, to_src_index))
370 return false;
371 if (from->clamp && !pco_instr_src_has_clamp(to_instr, to_src_index))
372 return false;
373 if (from->flr && !pco_instr_src_has_flr(to_instr, to_src_index))
374 return false;
375 if (from->abs && !pco_instr_src_has_abs(to_instr, to_src_index))
376 return false;
377 if (from->neg && !pco_instr_src_has_neg(to_instr, to_src_index))
378 return false;
379 if (from->elem && !pco_instr_src_has_elem(to_instr, to_src_index))
380 return false;
381 }
382
383 /* TODO: Also need to consider whether the source can be represented in the
384 * propagated instruction.
385 * Or, a legalize pass to insert movs; probably better since
386 * feature/arch-agnostic.
387 */
388
389 if (pco_ref_is_reg(*from) &&
390 pco_ref_get_reg_class(*from) == PCO_REG_CLASS_PIXOUT) {
391 return false;
392 }
393
394 return true;
395 }
396
397 /**
398 * \brief Tries to forward-propagate an instruction.
399 *
400 * \param[in] writes Global list of writes.
401 * \param[in] instr Instruction to try and forward-propagate.
402 * \return True if forward-propagation was successful.
403 */
404 static inline bool try_fwd_prop_instr(pco_instr **writes, pco_instr *instr)
405 {
406 bool progress = false;
407
408 pco_foreach_instr_src_ssa (psrc, instr) {
409 pco_instr *parent_instr = writes[psrc->val];
410
411 if (!parent_instr || parent_instr->op != PCO_OP_MOV)
412 continue;
413
414 if (!can_fwd_prop_src(instr, psrc, &parent_instr->src[0]))
415 continue;
416
417 /* Propagate the source. */
418 pco_ref repl = parent_instr->src[0];
419 if (psrc->flr)
420 repl = pco_ref_flr(repl);
421 else if (psrc->abs)
422 repl = pco_ref_abs(repl);
423
424 repl.neg ^= psrc->neg;
425
426 /* TODO: types? */
427 *psrc = repl;
428
429 if (pco_instr_has_olchk(parent_instr) &&
430 pco_instr_get_olchk(parent_instr)) {
431 assert(pco_instr_has_olchk(instr));
432 pco_instr_set_olchk(instr, true);
433 }
434
435 progress = true;
436 }
437
438 return progress;
439 }
440
441 /**
442 * \brief Instruction forward-propagation pass.
443 *
444 * \param[in,out] shader PCO shader.
445 * \return True if any forward-propagations were performed.
446 */
447 static inline bool pco_opt_fwd_prop(pco_shader *shader)
448 {
449 bool progress = false;
450 pco_instr **writes;
451
452 pco_foreach_func_in_shader (func, shader) {
453 writes = rzalloc_array_size(NULL, sizeof(*writes), func->next_ssa);
454
455 pco_foreach_instr_in_func (instr, func) {
456 pco_foreach_instr_dest_ssa (pdest, instr) {
457 writes[pdest->val] = instr;
458 }
459
460 progress |= try_fwd_prop_instr(writes, instr);
461 }
462
463 ralloc_free(writes);
464 }
465
466 return progress;
467 }
468
469 /**
470 * \brief Tries to propagate a comp instruction referencing hw registers.
471 *
472 * \param[in] src Source to match for replacement.
473 * \param[in] repl Replacement hw register reference.
474 * \param[in] from Instruction to try and propagate from.
475 * \return True if propagation was successful.
476 */
477 static inline bool try_prop_hw_comp(pco_ref src, pco_ref repl, pco_instr *from)
478 {
479 bool progress = false;
480
481 pco_foreach_instr_in_func_from (instr, from) {
482 pco_foreach_instr_src_ssa (psrc, instr) {
483 if (psrc->val != src.val)
484 continue;
485
486 /* Propagate the source. */
487 pco_ref _repl = repl;
488 if (psrc->flr)
489 _repl = pco_ref_flr(_repl);
490 else if (psrc->abs)
491 _repl = pco_ref_abs(_repl);
492
493 _repl.neg ^= psrc->neg;
494
495 /* TODO: types? */
496 *psrc = _repl;
497
498 progress = true;
499 }
500 }
501
502 return progress;
503 }
504
505 /**
506 * \brief Pass to propagate comp instructions referencing hw registers.
507 *
508 * \param[in,out] shader PCO shader.
509 * \return True if any hw reg propagations were performed.
510 */
511 static inline bool pco_opt_prop_hw_comps(pco_shader *shader)
512 {
513 bool progress = false;
514 pco_foreach_func_in_shader (func, shader) {
515 pco_foreach_instr_in_func_safe (instr, func) {
516 if (instr->op != PCO_OP_COMP)
517 continue;
518
519 pco_ref vec_src = instr->src[0];
520 if (pco_ref_is_ssa(vec_src))
521 continue;
522
523 pco_ref dest = instr->dest[0];
524 assert(pco_ref_is_ssa(dest));
525
526 unsigned offset = pco_ref_get_imm(instr->src[1]);
527
528 /* Construct a replacement scalar reference. */
529 pco_ref repl = vec_src;
530 repl = pco_ref_chans(repl, 1);
531 repl = pco_ref_offset(repl, offset);
532
533 progress |= try_prop_hw_comp(dest, repl, instr);
534
535 pco_instr_delete(instr);
536 }
537 }
538
539 return progress;
540 }
541
542 /**
543 * \brief Performs shader optimizations.
544 *
545 * \param[in,out] shader PCO shader.
546 * \return True if the pass made progress.
547 */
548 bool pco_opt(pco_shader *shader)
549 {
550 bool progress = false;
551 struct pco_opt_ctx ctx = { .mem_ctx = ralloc_context(NULL) };
552
553 PCO_PASS(progress, shader, pco_opt_prep_mods, &ctx);
554 PCO_PASS(progress, shader, pco_opt_back_prop);
555 PCO_PASS(progress, shader, pco_opt_fwd_prop);
556 /* TODO: Track whether there are any comp instructions referencing hw
557 * registers resulting from the previous passes, and only run
558 * pco_opt_prop_hw_comps if this is the case.
559 */
560
561 PCO_PASS(progress, shader, pco_opt_prop_hw_comps);
562
563 PCO_PASS(progress, shader, pco_opt_lower_mods, &ctx);
564 ralloc_free(ctx.mem_ctx);
565 return progress;
566 }
567
568 /**
569 * \brief Checks whether an instruction has side-effects.
570 *
571 * \param[in] instr Instruction to check.
572 * \return True if the instruction has side-effects.
573 */
574 static inline bool instr_has_side_effects(pco_instr *instr)
575 {
576 /* Atomic instructions. */
577 if (pco_instr_has_atom(instr) && pco_instr_get_atom(instr))
578 return true;
579
580 switch (instr->op) {
581 case PCO_OP_ATOMIC:
582 case PCO_OP_FDSX:
583 case PCO_OP_FDSY:
584
585 /* TODO: we don't really want to mark this as having side-effects, but
586 * idfwdf does smp without using the results.
587 */
588 case PCO_OP_SMP:
589
590 case PCO_OP_IADD32_ATOMIC:
591 case PCO_OP_XCHG_ATOMIC:
592 case PCO_OP_CMPXCHG_ATOMIC:
593 case PCO_OP_MIN_ATOMIC:
594 case PCO_OP_MAX_ATOMIC:
595 case PCO_OP_LOGICAL_ATOMIC:
596
597 case PCO_OP_OP_ATOMIC_OFFSET:
598
599 return true;
600
601 default:
602 break;
603 }
604
605 /* TODO:
606 * - gradient
607 * - conditional
608 * - sample writes (+ set the destination pointer to point to the write data)
609 * - others
610 */
611 return false;
612 }
613
614 /**
615 * \brief Performs DCE.
616 *
617 * \param[in,out] shader PCO shader.
618 * \return True if the pass made progress.
619 */
620 bool pco_dce(pco_shader *shader)
621 {
622 bool progress = false;
623 BITSET_WORD *ssa_used;
624 BITSET_WORD *vreg_used;
625
626 pco_foreach_func_in_shader (func, shader) {
627 ssa_used = rzalloc_array_size(NULL,
628 sizeof(*ssa_used),
629 BITSET_WORDS(func->next_ssa));
630
631 vreg_used = rzalloc_array_size(NULL,
632 sizeof(*vreg_used),
633 BITSET_WORDS(func->next_vreg));
634
635 /* Collect used SSA/vreg sources. */
636 pco_foreach_instr_in_func (instr, func) {
637 pco_foreach_instr_src_vreg_ssa (psrc, instr) {
638 if (pco_ref_is_ssa(*psrc))
639 BITSET_SET(ssa_used, psrc->val);
640 else
641 BITSET_SET(vreg_used, psrc->val);
642 }
643 }
644
645 pco_foreach_vreg_ssa_if_in_func (pif, func) {
646 if (pco_ref_is_ssa(pif->cond))
647 BITSET_SET(ssa_used, pif->cond.val);
648 else
649 BITSET_SET(vreg_used, pif->cond.val);
650 }
651
652 /* Remove instructions with unused SSA/vreg destinations (if they also
653 * have no side-effects).
654 */
655 pco_foreach_instr_in_func_safe (instr, func) {
656 bool has_dce_dests = false;
657 bool dests_used = false;
658
659 pco_foreach_instr_dest_vreg_ssa (pdest, instr) {
660 has_dce_dests = true;
661 if (pco_ref_is_ssa(*pdest))
662 dests_used |= BITSET_TEST(ssa_used, pdest->val);
663 else
664 dests_used |= BITSET_TEST(vreg_used, pdest->val);
665 }
666
667 if (has_dce_dests && !dests_used && !instr_has_side_effects(instr)) {
668 pco_instr_delete(instr);
669 progress = true;
670 }
671 }
672
673 ralloc_free(vreg_used);
674 ralloc_free(ssa_used);
675 }
676
677 return progress;
678 }
679
680 static inline bool only_uncollated_elems(pco_instr *vec)
681 {
682 pco_foreach_instr_src (psrc, vec) {
683 if (pco_ref_get_chans(*psrc) > 1)
684 return false;
685 }
686
687 return true;
688 }
689
690 /**
691 * \brief Shrinks vectors with unused components.
692 *
693 * \param[in,out] shader PCO shader.
694 * \return True if the pass made progress.
695 */
696 bool pco_shrink_vecs(pco_shader *shader)
697 {
698 bool progress = false;
699
700 pco_foreach_func_in_shader (func, shader) {
701 pco_foreach_instr_in_func (vec, func) {
702 if (vec->op != PCO_OP_VEC)
703 continue;
704
705 /* Can't shrink if has collated elems. */
706 if (!only_uncollated_elems(vec))
707 continue;
708
709 pco_ref *pdest = &vec->dest[0];
710 unsigned chans_used = 0;
711 unsigned chans = pco_ref_get_chans(*pdest);
712 pco_foreach_instr_in_func_from (instr, vec) {
713 if (instr->op == PCO_OP_COMP) {
714 pco_ref src = instr->src[0];
715 if (!pco_ref_is_ssa(src))
716 continue;
717
718 if (src.val != pdest->val)
719 continue;
720
721 unsigned offset = pco_ref_get_imm(instr->src[1]);
722 chans_used = MAX2(chans_used, offset);
723
724 continue;
725 }
726
727 pco_foreach_instr_src_ssa (psrc, instr) {
728 if (psrc->val == pdest->val) {
729 chans_used = MAX2(chans_used, pco_ref_get_chans(*psrc) - 1);
730 }
731 }
732 }
733
734 ++chans_used;
735 assert(chans_used <= chans);
736
737 /* Whole vec used, skip. */
738 if (chans_used == chans)
739 continue;
740
741 /* Update the vec. */
742 vec->num_srcs = chans_used;
743 *pdest = pco_ref_chans(*pdest, chans_used);
744
745 progress = true;
746 }
747 }
748
749 return progress;
750 }
751
752 bool pco_opt_comp_only_vecs(pco_shader *shader)
753 {
754 bool progress = false;
755
756 pco_foreach_func_in_shader (func, shader) {
757 pco_foreach_instr_in_func (vec, func) {
758 if (vec->op != PCO_OP_VEC)
759 continue;
760
761 bool used_by_noncomps = false;
762 pco_ref dest = vec->dest[0];
763
764 struct util_dynarray comps = UTIL_DYNARRAY_INIT;
765
766 pco_foreach_instr_in_func_from (instr, vec) {
767 if (instr->op == PCO_OP_COMP) {
768 if (instr->src[0].val == dest.val) {
769 util_dynarray_append(&comps, instr);
770 }
771
772 continue;
773 }
774
775 pco_foreach_instr_src_ssa (psrc, instr) {
776 if (psrc->val == dest.val) {
777 used_by_noncomps = true;
778 break;
779 }
780 }
781
782 if (used_by_noncomps)
783 break;
784 }
785
786 if (used_by_noncomps) {
787 util_dynarray_fini(&comps);
788 continue;
789 }
790
791 /* Has collated vec, skip. */
792 /* TODO: support this. */
793 if (vec->num_srcs != util_dynarray_num_elements(&comps, pco_instr *)) {
794 util_dynarray_fini(&comps);
795 continue;
796 }
797
798 util_dynarray_foreach (&comps, pco_instr *, _comp) {
799 pco_instr *comp = *_comp;
800 pco_ref dest = comp->dest[0];
801 assert(pco_ref_is_ssa(dest));
802
803 unsigned offset = pco_ref_get_imm(comp->src[1]);
804 assert(offset < vec->num_srcs);
805
806 pco_builder b =
807 pco_builder_create(func, pco_cursor_before_instr(comp));
808 pco_mov(&b, comp->dest[0], vec->src[offset]);
809
810 pco_instr_delete(comp);
811 }
812
813 util_dynarray_fini(&comps);
814 progress = true;
815 }
816 }
817
818 return progress;
819 }