2 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
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:
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
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 #include "midgard_ops.h"
26 #include "util/u_memory.h"
27 #include "util/register_allocate.h"
29 /* Scheduling for Midgard is complicated, to say the least. ALU instructions
30 * must be grouped into VLIW bundles according to following model:
33 * [VADD] [SMUL] [VLUT]
35 * A given instruction can execute on some subset of the units (or a few can
36 * execute on all). Instructions can be either vector or scalar; only scalar
37 * instructions can execute on SADD/SMUL units. Units on a given line execute
38 * in parallel. Subsequent lines execute separately and can pass results
39 * directly via pipeline registers r24/r25, bypassing the register file.
41 * A bundle can optionally have 128-bits of embedded constants, shared across
42 * all of the instructions within a bundle.
44 * Instructions consuming conditionals (branches and conditional selects)
45 * require their condition to be written into the conditional register (r31)
46 * within the same bundle they are consumed.
48 * Fragment writeout requires its argument to be written in full within the
49 * same bundle as the branch, with no hanging dependencies.
51 * Load/store instructions are also in bundles of simply two instructions, and
52 * texture instructions have no bundling.
54 * -------------------------------------------------------------------------
58 /* We create the dependency graph with per-component granularity */
60 #define COMPONENT_COUNT 8
63 add_dependency(struct util_dynarray
*table
, unsigned index
, unsigned mask
, midgard_instruction
**instructions
, unsigned child
)
65 for (unsigned i
= 0; i
< COMPONENT_COUNT
; ++i
) {
66 if (!(mask
& (1 << i
)))
69 struct util_dynarray
*parents
= &table
[(COMPONENT_COUNT
* index
) + i
];
71 util_dynarray_foreach(parents
, unsigned, parent
) {
72 BITSET_WORD
*dependents
= instructions
[*parent
]->dependents
;
74 /* Already have the dependency */
75 if (BITSET_TEST(dependents
, child
))
78 BITSET_SET(dependents
, child
);
79 instructions
[child
]->nr_dependencies
++;
85 mark_access(struct util_dynarray
*table
, unsigned index
, unsigned mask
, unsigned parent
)
87 for (unsigned i
= 0; i
< COMPONENT_COUNT
; ++i
) {
88 if (!(mask
& (1 << i
)))
91 util_dynarray_append(&table
[(COMPONENT_COUNT
* index
) + i
], unsigned, parent
);
96 mir_create_dependency_graph(midgard_instruction
**instructions
, unsigned count
, unsigned node_count
)
98 size_t sz
= node_count
* COMPONENT_COUNT
;
100 struct util_dynarray
*last_read
= calloc(sizeof(struct util_dynarray
), sz
);
101 struct util_dynarray
*last_write
= calloc(sizeof(struct util_dynarray
), sz
);
103 for (unsigned i
= 0; i
< sz
; ++i
) {
104 util_dynarray_init(&last_read
[i
], NULL
);
105 util_dynarray_init(&last_write
[i
], NULL
);
108 /* Initialize dependency graph */
109 for (unsigned i
= 0; i
< count
; ++i
) {
110 instructions
[i
]->dependents
=
111 calloc(BITSET_WORDS(count
), sizeof(BITSET_WORD
));
113 instructions
[i
]->nr_dependencies
= 0;
116 /* Populate dependency graph */
117 for (signed i
= count
- 1; i
>= 0; --i
) {
118 if (instructions
[i
]->compact_branch
)
121 unsigned dest
= instructions
[i
]->dest
;
122 unsigned mask
= instructions
[i
]->mask
;
124 mir_foreach_src((*instructions
), s
) {
125 unsigned src
= instructions
[i
]->src
[s
];
127 if (src
< node_count
) {
128 unsigned readmask
= mir_mask_of_read_components(instructions
[i
], src
);
129 add_dependency(last_write
, src
, readmask
, instructions
, i
);
133 if (dest
< node_count
) {
134 add_dependency(last_read
, dest
, mask
, instructions
, i
);
135 add_dependency(last_write
, dest
, mask
, instructions
, i
);
136 mark_access(last_write
, dest
, mask
, i
);
139 mir_foreach_src((*instructions
), s
) {
140 unsigned src
= instructions
[i
]->src
[s
];
142 if (src
< node_count
) {
143 unsigned readmask
= mir_mask_of_read_components(instructions
[i
], src
);
144 mark_access(last_read
, src
, readmask
, i
);
149 /* If there is a branch, all instructions depend on it, as interblock
150 * execution must be purely in-order */
152 if (instructions
[count
- 1]->compact_branch
) {
153 BITSET_WORD
*dependents
= instructions
[count
- 1]->dependents
;
155 for (signed i
= count
- 2; i
>= 0; --i
) {
156 if (BITSET_TEST(dependents
, i
))
159 BITSET_SET(dependents
, i
);
160 instructions
[i
]->nr_dependencies
++;
164 /* Free the intermediate structures */
165 for (unsigned i
= 0; i
< sz
; ++i
) {
166 util_dynarray_fini(&last_read
[i
]);
167 util_dynarray_fini(&last_write
[i
]);
171 /* Create a mask of accessed components from a swizzle to figure out vector
175 swizzle_to_access_mask(unsigned swizzle
)
177 unsigned component_mask
= 0;
179 for (int i
= 0; i
< 4; ++i
) {
180 unsigned c
= (swizzle
>> (2 * i
)) & 3;
181 component_mask
|= (1 << c
);
184 return component_mask
;
187 /* Does the mask cover more than a scalar? */
190 is_single_component_mask(unsigned mask
)
194 for (int c
= 0; c
< 8; ++c
) {
199 return components
== 1;
202 /* Checks for an SSA data hazard between two adjacent instructions, keeping in
203 * mind that we are a vector architecture and we can write to different
204 * components simultaneously */
207 can_run_concurrent_ssa(midgard_instruction
*first
, midgard_instruction
*second
)
209 /* Writeout has its own rules anyway */
210 if (first
->compact_branch
|| second
->compact_branch
)
213 /* Each instruction reads some registers and writes to a register. See
214 * where the first writes */
216 int source
= first
->dest
;
217 int source_mask
= first
->mask
;
219 /* As long as the second doesn't read from the first, we're okay */
220 for (unsigned i
= 0; i
< ARRAY_SIZE(second
->src
); ++i
) {
221 if (second
->src
[i
] != source
)
224 if (first
->type
!= TAG_ALU_4
)
227 /* Figure out which components we just read from */
229 int q
= (i
== 0) ? second
->alu
.src1
: second
->alu
.src2
;
230 midgard_vector_alu_src
*m
= (midgard_vector_alu_src
*) &q
;
232 /* Check if there are components in common, and fail if so */
233 if (swizzle_to_access_mask(m
->swizzle
) & source_mask
)
237 /* Otherwise, it's safe in that regard. Another data hazard is both
238 * writing to the same place, of course */
240 if (second
->dest
== source
) {
241 /* ...but only if the components overlap */
243 if (second
->mask
& source_mask
)
253 midgard_instruction
**segment
, unsigned segment_size
,
254 midgard_instruction
*ains
)
256 for (int s
= 0; s
< segment_size
; ++s
)
257 if (!can_run_concurrent_ssa(segment
[s
], ains
))
265 /* Fragment writeout (of r0) is allowed when:
267 * - All components of r0 are written in the bundle
268 * - No components of r0 are written in VLUT
269 * - Non-pipelined dependencies of r0 are not written in the bundle
271 * This function checks if these requirements are satisfied given the content
272 * of a scheduled bundle.
276 can_writeout_fragment(compiler_context
*ctx
, midgard_instruction
**bundle
, unsigned count
, unsigned node_count
, unsigned r0
)
278 /* First scan for which components of r0 are written out. Initially
279 * none are written */
281 uint8_t r0_written_mask
= 0x0;
283 /* Simultaneously we scan for the set of dependencies */
285 size_t sz
= sizeof(BITSET_WORD
) * BITSET_WORDS(node_count
);
286 BITSET_WORD
*dependencies
= calloc(1, sz
);
287 memset(dependencies
, 0, sz
);
289 bool success
= false;
291 for (unsigned i
= 0; i
< count
; ++i
) {
292 midgard_instruction
*ins
= bundle
[i
];
297 /* Record written out mask */
298 r0_written_mask
|= ins
->mask
;
300 /* Record dependencies, but only if they won't become pipeline
301 * registers. We know we can't be live after this, because
302 * we're writeout at the very end of the shader. So check if
303 * they were written before us. */
305 unsigned src0
= ins
->src
[0];
306 unsigned src1
= ins
->src
[1];
308 if (!mir_is_written_before(ctx
, bundle
[0], src0
))
311 if (!mir_is_written_before(ctx
, bundle
[0], src1
))
314 if (src0
< node_count
)
315 BITSET_SET(dependencies
, src0
);
317 if (src1
< node_count
)
318 BITSET_SET(dependencies
, src1
);
321 if (ins
->unit
== UNIT_VLUT
)
326 if ((r0_written_mask
& 0xF) != 0xF)
331 for (unsigned i
= 0; i
< count
; ++i
) {
332 unsigned dest
= bundle
[i
]->dest
;
334 if (dest
< node_count
&& BITSET_TEST(dependencies
, dest
))
338 /* Otherwise, we're good to go */
346 /* Helpers for scheudling */
349 mir_is_scalar(midgard_instruction
*ains
)
351 /* Does the op support scalar units? */
352 if (!(alu_opcode_props
[ains
->alu
.op
].props
& UNITS_SCALAR
))
355 /* Do we try to use it as a vector op? */
356 if (!is_single_component_mask(ains
->mask
))
359 /* Otherwise, check mode hazards */
360 bool could_scalar
= true;
362 /* Only 16/32-bit can run on a scalar unit */
363 could_scalar
&= ains
->alu
.reg_mode
!= midgard_reg_mode_8
;
364 could_scalar
&= ains
->alu
.reg_mode
!= midgard_reg_mode_64
;
365 could_scalar
&= ains
->alu
.dest_override
== midgard_dest_override_none
;
367 if (ains
->alu
.reg_mode
== midgard_reg_mode_16
) {
368 /* If we're running in 16-bit mode, we
369 * can't have any 8-bit sources on the
370 * scalar unit (since the scalar unit
371 * doesn't understand 8-bit) */
373 midgard_vector_alu_src s1
=
374 vector_alu_from_unsigned(ains
->alu
.src1
);
376 could_scalar
&= !s1
.half
;
378 midgard_vector_alu_src s2
=
379 vector_alu_from_unsigned(ains
->alu
.src2
);
381 could_scalar
&= !s2
.half
;
387 /* How many bytes does this ALU instruction add to the bundle? */
390 bytes_for_instruction(midgard_instruction
*ains
)
392 if (ains
->unit
& UNITS_ANY_VECTOR
)
393 return sizeof(midgard_reg_info
) + sizeof(midgard_vector_alu
);
394 else if (ains
->unit
== ALU_ENAB_BRANCH
)
395 return sizeof(midgard_branch_extended
);
396 else if (ains
->compact_branch
)
397 return sizeof(ains
->br_compact
);
399 return sizeof(midgard_reg_info
) + sizeof(midgard_scalar_alu
);
402 /* Schedules, but does not emit, a single basic block. After scheduling, the
403 * final tag and size of the block are known, which are necessary for branching
406 static midgard_bundle
407 schedule_bundle(compiler_context
*ctx
, midgard_block
*block
, midgard_instruction
*ins
, int *skip
)
409 int instructions_emitted
= 0, packed_idx
= 0;
410 midgard_bundle bundle
= { 0 };
412 midgard_instruction
*scheduled
[5] = { NULL
};
414 uint8_t tag
= ins
->type
;
416 /* Default to the instruction's tag */
421 uint32_t control
= 0;
422 size_t bytes_emitted
= sizeof(control
);
424 /* TODO: Constant combining */
425 int index
= 0, last_unit
= 0;
427 /* Previous instructions, for the purpose of parallelism */
428 midgard_instruction
*segment
[4] = {0};
429 int segment_size
= 0;
431 instructions_emitted
= -1;
432 midgard_instruction
*pins
= ins
;
434 unsigned constant_count
= 0;
437 midgard_instruction
*ains
= pins
;
439 /* Advance instruction pointer */
441 ains
= mir_next_op(pins
);
445 /* Out-of-work condition */
446 if ((struct list_head
*) ains
== &block
->instructions
)
449 /* Ensure that the chain can continue */
450 if (ains
->type
!= TAG_ALU_4
) break;
452 /* If there's already something in the bundle and we
453 * have weird scheduler constraints, break now */
454 if (ains
->precede_break
&& index
) break;
456 /* According to the presentation "The ARM
457 * Mali-T880 Mobile GPU" from HotChips 27,
458 * there are two pipeline stages. Branching
459 * position determined experimentally. Lines
460 * are executed in parallel:
463 * [ VADD ] [ SMUL ] [ LUT ] [ BRANCH ]
465 * Verify that there are no ordering dependencies here.
467 * TODO: Allow for parallelism!!!
470 /* Pick a unit for it if it doesn't force a particular unit */
472 int unit
= ains
->unit
;
475 int op
= ains
->alu
.op
;
476 int units
= alu_opcode_props
[op
].props
;
477 bool scalar
= mir_is_scalar(ains
);
480 if (last_unit
>= UNIT_VADD
) {
481 if (units
& UNIT_VLUT
)
486 if ((units
& UNIT_VMUL
) && last_unit
< UNIT_VMUL
)
488 else if ((units
& UNIT_VADD
) && !(control
& UNIT_VADD
))
490 else if (units
& UNIT_VLUT
)
496 if (last_unit
>= UNIT_VADD
) {
497 if ((units
& UNIT_SMUL
) && !(control
& UNIT_SMUL
))
499 else if (units
& UNIT_VLUT
)
504 if ((units
& UNIT_VMUL
) && (last_unit
< UNIT_VMUL
))
506 else if ((units
& UNIT_SADD
) && !(control
& UNIT_SADD
) && !midgard_has_hazard(segment
, segment_size
, ains
))
508 else if (units
& UNIT_VADD
)
510 else if (units
& UNIT_SMUL
)
512 else if (units
& UNIT_VLUT
)
519 assert(unit
& units
);
522 /* Late unit check, this time for encoding (not parallelism) */
523 if (unit
<= last_unit
) break;
525 /* Clear the segment */
526 if (last_unit
< UNIT_VADD
&& unit
>= UNIT_VADD
)
529 if (midgard_has_hazard(segment
, segment_size
, ains
))
532 /* We're good to go -- emit the instruction */
535 segment
[segment_size
++] = ains
;
537 /* We try to reuse constants if possible, by adjusting
540 if (ains
->has_blend_constant
) {
541 /* Everything conflicts with the blend constant */
542 if (bundle
.has_embedded_constants
)
545 bundle
.has_blend_constant
= 1;
546 bundle
.has_embedded_constants
= 1;
547 } else if (ains
->has_constants
&& ains
->alu
.reg_mode
== midgard_reg_mode_16
) {
548 /* TODO: DRY with the analysis pass */
550 if (bundle
.has_blend_constant
)
556 /* TODO: Fix packing XXX */
557 uint16_t *bundles
= (uint16_t *) bundle
.constants
;
558 uint32_t *constants
= (uint32_t *) ains
->constants
;
560 /* Copy them wholesale */
561 for (unsigned i
= 0; i
< 4; ++i
)
562 bundles
[i
] = constants
[i
];
564 bundle
.has_embedded_constants
= true;
566 } else if (ains
->has_constants
) {
567 /* By definition, blend constants conflict with
568 * everything, so if there are already
569 * constants we break the bundle *now* */
571 if (bundle
.has_blend_constant
)
574 /* For anything but blend constants, we can do
575 * proper analysis, however */
577 /* TODO: Mask by which are used */
578 uint32_t *constants
= (uint32_t *) ains
->constants
;
579 uint32_t *bundles
= (uint32_t *) bundle
.constants
;
581 uint32_t indices
[4] = { 0 };
582 bool break_bundle
= false;
584 for (unsigned i
= 0; i
< 4; ++i
) {
585 uint32_t cons
= constants
[i
];
586 bool constant_found
= false;
588 /* Search for the constant */
589 for (unsigned j
= 0; j
< constant_count
; ++j
) {
590 if (bundles
[j
] != cons
)
593 /* We found it, reuse */
595 constant_found
= true;
602 /* We didn't find it, so allocate it */
603 unsigned idx
= constant_count
++;
606 /* Uh-oh, out of space */
611 /* We have space, copy it in! */
619 /* Cool, we have it in. So use indices as a
622 unsigned swizzle
= SWIZZLE_FROM_ARRAY(indices
);
623 unsigned r_constant
= SSA_FIXED_REGISTER(REGISTER_CONSTANT
);
625 if (ains
->src
[0] == r_constant
)
626 ains
->alu
.src1
= vector_alu_apply_swizzle(ains
->alu
.src1
, swizzle
);
628 if (ains
->src
[1] == r_constant
)
629 ains
->alu
.src2
= vector_alu_apply_swizzle(ains
->alu
.src2
, swizzle
);
631 bundle
.has_embedded_constants
= true;
634 if (ains
->compact_branch
) {
635 /* All of r0 has to be written out along with
636 * the branch writeout */
638 if (ains
->writeout
&& !can_writeout_fragment(ctx
, scheduled
, index
, ctx
->temp_count
, ains
->src
[0])) {
639 /* We only work on full moves
640 * at the beginning. We could
641 * probably do better */
646 midgard_instruction ins
= v_mov(0, blank_alu_src
, SSA_FIXED_REGISTER(0));
647 ins
.unit
= UNIT_VMUL
;
650 /* TODO don't leak */
651 midgard_instruction
*move
=
652 mem_dup(&ins
, sizeof(midgard_instruction
));
653 bytes_emitted
+= bytes_for_instruction(move
);
654 bundle
.instructions
[packed_idx
++] = move
;
658 bytes_emitted
+= bytes_for_instruction(ains
);
660 /* Defer marking until after writing to allow for break */
661 scheduled
[index
] = ains
;
662 control
|= ains
->unit
;
663 last_unit
= ains
->unit
;
664 ++instructions_emitted
;
670 /* Pad ALU op to nearest word */
672 if (bytes_emitted
& 15) {
673 padding
= 16 - (bytes_emitted
& 15);
674 bytes_emitted
+= padding
;
677 /* Constants must always be quadwords */
678 if (bundle
.has_embedded_constants
)
681 /* Size ALU instruction for tag */
682 bundle
.tag
= (TAG_ALU_4
) + (bytes_emitted
/ 16) - 1;
683 bundle
.padding
= padding
;
684 bundle
.control
= bundle
.tag
| control
;
689 case TAG_LOAD_STORE_4
: {
690 /* Load store instructions have two words at once. If
691 * we only have one queued up, we need to NOP pad.
692 * Otherwise, we store both in succession to save space
693 * and cycles -- letting them go in parallel -- skip
694 * the next. The usefulness of this optimisation is
695 * greatly dependent on the quality of the instruction
699 midgard_instruction
*next_op
= mir_next_op(ins
);
701 if ((struct list_head
*) next_op
!= &block
->instructions
&& next_op
->type
== TAG_LOAD_STORE_4
) {
702 /* TODO: Concurrency check */
703 instructions_emitted
++;
709 case TAG_TEXTURE_4
: {
710 /* Which tag we use depends on the shader stage */
711 bool in_frag
= ctx
->stage
== MESA_SHADER_FRAGMENT
;
712 bundle
.tag
= in_frag
? TAG_TEXTURE_4
: TAG_TEXTURE_4_VTX
;
717 unreachable("Unknown tag");
721 /* Copy the instructions into the bundle */
722 bundle
.instruction_count
= instructions_emitted
+ 1 + packed_idx
;
724 midgard_instruction
*uins
= ins
;
725 for (; packed_idx
< bundle
.instruction_count
; ++packed_idx
) {
726 assert(&uins
->link
!= &block
->instructions
);
727 bundle
.instructions
[packed_idx
] = uins
;
728 uins
= mir_next_op(uins
);
731 *skip
= instructions_emitted
;
736 /* We would like to flatten the linked list of midgard_instructions in a bundle
737 * to an array of pointers on the heap for easy indexing */
739 static midgard_instruction
**
740 flatten_mir(midgard_block
*block
, unsigned *len
)
742 *len
= list_length(&block
->instructions
);
747 midgard_instruction
**instructions
=
748 calloc(sizeof(midgard_instruction
*), *len
);
752 mir_foreach_instr_in_block(block
, ins
)
753 instructions
[i
++] = ins
;
758 /* The worklist is the set of instructions that can be scheduled now; that is,
759 * the set of instructions with no remaining dependencies */
762 mir_initialize_worklist(BITSET_WORD
*worklist
, midgard_instruction
**instructions
, unsigned count
)
764 for (unsigned i
= 0; i
< count
; ++i
) {
765 if (instructions
[i
]->nr_dependencies
== 0)
766 BITSET_SET(worklist
, i
);
770 /* Update the worklist after an instruction terminates. Remove its edges from
771 * the graph and if that causes any node to have no dependencies, add it to the
776 BITSET_WORD
*worklist
, unsigned count
,
777 midgard_instruction
**instructions
, midgard_instruction
*done
)
779 /* Sanity check: if no instruction terminated, there is nothing to do.
780 * If the instruction that terminated had dependencies, that makes no
781 * sense and means we messed up the worklist. Finally, as the purpose
782 * of this routine is to update dependents, we abort early if there are
783 * no dependents defined. */
788 assert(done
->nr_dependencies
== 0);
790 if (!done
->dependents
)
793 /* We have an instruction with dependents. Iterate each dependent to
794 * remove one dependency (`done`), adding dependents to the worklist
799 BITSET_FOREACH_SET(i
, tmp
, done
->dependents
, count
) {
800 assert(instructions
[i
]->nr_dependencies
);
802 if (!(--instructions
[i
]->nr_dependencies
))
803 BITSET_SET(worklist
, i
);
806 free(done
->dependents
);
809 /* While scheduling, we need to choose instructions satisfying certain
810 * criteria. As we schedule backwards, we choose the *last* instruction in the
811 * worklist to simulate in-order scheduling. Chosen instructions must satisfy a
812 * given predicate. */
814 struct midgard_predicate
{
815 /* TAG or ~0 for dont-care */
818 /* True if we want to pop off the chosen instruction */
821 /* For ALU, choose only this unit */
824 /* State for bundle constants. constants is the actual constants
825 * for the bundle. constant_count is the number of bytes (up to
826 * 16) currently in use for constants. When picking in destructive
827 * mode, the constants array will be updated, and the instruction
828 * will be adjusted to index into the constants array */
831 unsigned constant_count
;
834 /* Exclude this destination (if not ~0) */
838 /* For an instruction that can fit, adjust it to fit and update the constants
839 * array, in destructive mode. Returns whether the fitting was successful. */
842 mir_adjust_constants(midgard_instruction
*ins
,
843 struct midgard_predicate
*pred
,
846 /* Blend constants dominate */
847 if (ins
->has_blend_constant
) {
848 if (pred
->constant_count
)
850 else if (destructive
) {
851 pred
->blend_constant
= true;
852 pred
->constant_count
= 16;
857 /* No constant, nothing to adjust */
858 if (!ins
->has_constants
)
861 /* TODO: Deduplicate; permit multiple constants within a bundle */
863 if (destructive
&& !pred
->constant_count
) {
864 if (ins
->alu
.reg_mode
== midgard_reg_mode_16
) {
865 /* TODO: Fix packing XXX */
866 uint16_t *bundles
= (uint16_t *) pred
->constants
;
867 uint32_t *constants
= (uint32_t *) ins
->constants
;
869 /* Copy them wholesale */
870 for (unsigned i
= 0; i
< 4; ++i
)
871 bundles
[i
] = constants
[i
];
873 memcpy(pred
->constants
, ins
->constants
, 16);
876 pred
->constant_count
= 16;
880 return !pred
->constant_count
;
883 static midgard_instruction
*
884 mir_choose_instruction(
885 midgard_instruction
**instructions
,
886 BITSET_WORD
*worklist
, unsigned count
,
887 struct midgard_predicate
*predicate
)
889 /* Parse the predicate */
890 unsigned tag
= predicate
->tag
;
891 bool alu
= tag
== TAG_ALU_4
;
892 unsigned unit
= predicate
->unit
;
893 bool branch
= alu
&& (unit
== ALU_ENAB_BR_COMPACT
);
895 /* Iterate to find the best instruction satisfying the predicate */
899 signed best_index
= -1;
901 BITSET_FOREACH_SET(i
, tmp
, worklist
, count
) {
902 if (tag
!= ~0 && instructions
[i
]->type
!= tag
)
905 if (predicate
->exclude
!= ~0 && instructions
[i
]->dest
== predicate
->exclude
)
908 if (alu
&& !branch
&& !(alu_opcode_props
[instructions
[i
]->alu
.op
].props
& unit
))
911 if (branch
&& !instructions
[i
]->compact_branch
)
914 /* Simulate in-order scheduling */
915 if ((signed) i
< best_index
)
922 /* Did we find anything? */
927 /* If we found something, remove it from the worklist */
928 assert(best_index
< count
);
930 if (predicate
->destructive
) {
931 BITSET_CLEAR(worklist
, best_index
);
934 return instructions
[best_index
];
937 /* Still, we don't choose instructions in a vacuum. We need a way to choose the
938 * best bundle type (ALU, load/store, texture). Nondestructive. */
942 midgard_instruction
**instructions
,
943 BITSET_WORD
*worklist
, unsigned count
)
945 /* At the moment, our algorithm is very simple - use the bundle of the
946 * best instruction, regardless of what else could be scheduled
947 * alongside it. This is not optimal but it works okay for in-order */
949 struct midgard_predicate predicate
= {
951 .destructive
= false,
955 midgard_instruction
*chosen
= mir_choose_instruction(instructions
, worklist
, count
, &predicate
);
963 /* We want to choose an ALU instruction filling a given unit */
965 mir_choose_alu(midgard_instruction
**slot
,
966 midgard_instruction
**instructions
,
967 BITSET_WORD
*worklist
, unsigned len
,
968 struct midgard_predicate
*predicate
,
971 /* Did we already schedule to this slot? */
975 /* Try to schedule something, if not */
976 predicate
->unit
= unit
;
977 *slot
= mir_choose_instruction(instructions
, worklist
, len
, predicate
);
979 /* Store unit upon scheduling */
980 if (*slot
&& !((*slot
)->compact_branch
))
981 (*slot
)->unit
= unit
;
984 /* When we are scheduling a branch/csel, we need the consumed condition in the
985 * same block as a pipeline register. There are two options to enable this:
987 * - Move the conditional into the bundle. Preferred, but only works if the
988 * conditional is used only once and is from this block.
989 * - Copy the conditional.
991 * We search for the conditional. If it's in this block, single-use, and
992 * without embedded constants, we schedule it immediately. Otherwise, we
993 * schedule a move for it.
995 * mir_comparison_mobile is a helper to find the moveable condition.
999 mir_comparison_mobile(
1000 compiler_context
*ctx
,
1001 midgard_instruction
**instructions
,
1005 if (!mir_single_use(ctx
, cond
))
1010 for (unsigned i
= 0; i
< count
; ++i
) {
1011 if (instructions
[i
]->dest
!= cond
)
1014 /* Must fit in an ALU bundle */
1015 if (instructions
[i
]->type
!= TAG_ALU_4
)
1018 /* We'll need to rewrite to .w but that doesn't work for vector
1019 * ops that don't replicate (ball/bany), so bail there */
1021 if (GET_CHANNEL_COUNT(alu_opcode_props
[instructions
[i
]->alu
.op
].props
))
1024 /* TODO: moving conditionals with constants */
1026 if (instructions
[i
]->has_constants
)
1029 /* Ensure it is written only once */
1040 /* Using the information about the moveable conditional itself, we either pop
1041 * that condition off the worklist for use now, or create a move to
1042 * artificially schedule instead as a fallback */
1044 static midgard_instruction
*
1045 mir_schedule_comparison(
1046 compiler_context
*ctx
,
1047 midgard_instruction
**instructions
,
1048 BITSET_WORD
*worklist
, unsigned count
,
1049 unsigned cond
, bool vector
, unsigned swizzle
,
1050 midgard_instruction
*user
)
1052 /* TODO: swizzle when scheduling */
1054 (!vector
&& (swizzle
== 0)) ?
1055 mir_comparison_mobile(ctx
, instructions
, count
, cond
) : ~0;
1057 /* If we can, schedule the condition immediately */
1058 if ((comp_i
!= ~0) && BITSET_TEST(worklist
, comp_i
)) {
1059 assert(comp_i
< count
);
1060 BITSET_CLEAR(worklist
, comp_i
);
1061 return instructions
[comp_i
];
1064 /* Otherwise, we insert a move */
1065 midgard_vector_alu_src csel
= {
1069 midgard_instruction mov
= v_mov(cond
, csel
, cond
);
1070 mov
.mask
= vector
? 0xF : 0x1;
1072 return mir_insert_instruction_before(ctx
, user
, mov
);
1075 /* Most generally, we need instructions writing to r31 in the appropriate
1078 static midgard_instruction
*
1079 mir_schedule_condition(compiler_context
*ctx
,
1080 struct midgard_predicate
*predicate
,
1081 BITSET_WORD
*worklist
, unsigned count
,
1082 midgard_instruction
**instructions
,
1083 midgard_instruction
*last
)
1085 /* For a branch, the condition is the only argument; for csel, third */
1086 bool branch
= last
->compact_branch
;
1087 unsigned condition_index
= branch
? 0 : 2;
1089 /* csel_v is vector; otherwise, conditions are scalar */
1090 bool vector
= !branch
&& OP_IS_CSEL_V(last
->alu
.op
);
1092 /* Grab the conditional instruction */
1094 midgard_instruction
*cond
= mir_schedule_comparison(
1095 ctx
, instructions
, worklist
, count
, last
->src
[condition_index
],
1096 vector
, last
->cond_swizzle
, last
);
1098 /* We have exclusive reign over this (possibly move) conditional
1099 * instruction. We can rewrite into a pipeline conditional register */
1101 predicate
->exclude
= cond
->dest
;
1102 cond
->dest
= SSA_FIXED_REGISTER(31);
1105 cond
->mask
= (1 << COMPONENT_W
);
1107 mir_foreach_src(cond
, s
) {
1108 if (cond
->src
[s
] == ~0)
1111 mir_set_swizzle(cond
, s
, (mir_get_swizzle(cond
, s
) << (2*3)) & 0xFF);
1115 /* Schedule the unit: csel is always in the latter pipeline, so a csel
1116 * condition must be in the former pipeline stage (vmul/sadd),
1117 * depending on scalar/vector of the instruction itself. A branch must
1118 * be written from the latter pipeline stage and a branch condition is
1119 * always scalar, so it is always in smul (exception: ball/bany, which
1123 cond
->unit
= UNIT_SMUL
;
1125 cond
->unit
= vector
? UNIT_VMUL
: UNIT_SADD
;
1130 /* Schedules a single bundle of the given type */
1132 static midgard_bundle
1133 mir_schedule_texture(
1134 midgard_instruction
**instructions
,
1135 BITSET_WORD
*worklist
, unsigned len
)
1137 struct midgard_predicate predicate
= {
1138 .tag
= TAG_TEXTURE_4
,
1139 .destructive
= true,
1143 midgard_instruction
*ins
=
1144 mir_choose_instruction(instructions
, worklist
, len
, &predicate
);
1146 mir_update_worklist(worklist
, len
, instructions
, ins
);
1148 struct midgard_bundle out
= {
1149 .tag
= TAG_TEXTURE_4
,
1150 .instruction_count
= 1,
1151 .instructions
= { ins
}
1157 static midgard_bundle
1159 midgard_instruction
**instructions
,
1160 BITSET_WORD
*worklist
, unsigned len
)
1162 struct midgard_predicate predicate
= {
1163 .tag
= TAG_LOAD_STORE_4
,
1164 .destructive
= true,
1168 /* Try to pick two load/store ops. Second not gauranteed to exist */
1170 midgard_instruction
*ins
=
1171 mir_choose_instruction(instructions
, worklist
, len
, &predicate
);
1173 midgard_instruction
*pair
=
1174 mir_choose_instruction(instructions
, worklist
, len
, &predicate
);
1176 struct midgard_bundle out
= {
1177 .tag
= TAG_LOAD_STORE_4
,
1178 .instruction_count
= pair
? 2 : 1,
1179 .instructions
= { ins
, pair
}
1182 /* We have to update the worklist atomically, since the two
1183 * instructions run concurrently (TODO: verify it's not pipelined) */
1185 mir_update_worklist(worklist
, len
, instructions
, ins
);
1186 mir_update_worklist(worklist
, len
, instructions
, pair
);
1191 static midgard_bundle
1193 compiler_context
*ctx
,
1194 midgard_instruction
**instructions
,
1195 BITSET_WORD
*worklist
, unsigned len
)
1197 struct midgard_bundle bundle
= {};
1199 unsigned bytes_emitted
= sizeof(bundle
.control
);
1201 struct midgard_predicate predicate
= {
1203 .destructive
= true,
1207 midgard_instruction
*ins
=
1208 mir_choose_instruction(instructions
, worklist
, len
, &predicate
);
1210 midgard_instruction
*vmul
= NULL
;
1211 midgard_instruction
*vadd
= NULL
;
1212 midgard_instruction
*vlut
= NULL
;
1213 midgard_instruction
*smul
= NULL
;
1214 midgard_instruction
*sadd
= NULL
;
1215 midgard_instruction
*branch
= NULL
;
1217 mir_update_worklist(worklist
, len
, instructions
, ins
);
1219 if (ins
->compact_branch
) {
1221 } else if (!ins
->unit
) {
1222 unsigned units
= alu_opcode_props
[ins
->alu
.op
].props
;
1224 if (units
& UNIT_VMUL
) {
1225 ins
->unit
= UNIT_VMUL
;
1227 } else if (units
& UNIT_VADD
) {
1228 ins
->unit
= UNIT_VADD
;
1230 } else if (units
& UNIT_VLUT
) {
1231 ins
->unit
= UNIT_VLUT
;
1237 bundle
.has_embedded_constants
= ins
->has_constants
;
1238 bundle
.has_blend_constant
= ins
->has_blend_constant
;
1240 if (ins
->alu
.reg_mode
== midgard_reg_mode_16
) {
1241 /* TODO: Fix packing XXX */
1242 uint16_t *bundles
= (uint16_t *) bundle
.constants
;
1243 uint32_t *constants
= (uint32_t *) ins
->constants
;
1245 /* Copy them wholesale */
1246 for (unsigned i
= 0; i
< 4; ++i
)
1247 bundles
[i
] = constants
[i
];
1249 memcpy(bundle
.constants
, ins
->constants
, sizeof(bundle
.constants
));
1252 if (ins
->writeout
) {
1253 unsigned src
= (branch
->src
[0] == ~0) ? SSA_FIXED_REGISTER(0) : branch
->src
[0];
1254 unsigned temp
= (branch
->src
[0] == ~0) ? SSA_FIXED_REGISTER(0) : make_compiler_temp(ctx
);
1255 midgard_instruction mov
= v_mov(src
, blank_alu_src
, temp
);
1256 vmul
= mem_dup(&mov
, sizeof(midgard_instruction
));
1257 vmul
->unit
= UNIT_VMUL
;
1259 /* TODO: Don't leak */
1261 /* Rewrite to use our temp */
1262 midgard_instruction
*stages
[] = { sadd
, vadd
, smul
};
1264 for (unsigned i
= 0; i
< ARRAY_SIZE(stages
); ++i
) {
1266 mir_rewrite_index_dst_single(stages
[i
], src
, temp
);
1269 mir_rewrite_index_src_single(branch
, src
, temp
);
1272 if ((vadd
&& OP_IS_CSEL(vadd
->alu
.op
)) || (smul
&& OP_IS_CSEL(smul
->alu
.op
)) || (ins
->compact_branch
&& !ins
->prepacked_branch
&& ins
->branch
.conditional
)) {
1273 midgard_instruction
*cond
= mir_choose_instruction(instructions
, worklist
, len
, &predicate
);
1274 mir_update_worklist(worklist
, len
, instructions
, cond
);
1277 unsigned units
= alu_opcode_props
[cond
->alu
.op
].props
;
1279 if (units
& UNIT_VMUL
) {
1280 cond
->unit
= UNIT_VMUL
;
1281 } else if (units
& UNIT_VADD
) {
1282 cond
->unit
= UNIT_VADD
;
1287 if (cond
->unit
& UNIT_VMUL
)
1289 else if (cond
->unit
& UNIT_SADD
)
1291 else if (cond
->unit
& UNIT_VADD
)
1293 else if (cond
->unit
& UNIT_SMUL
)
1296 unreachable("Bad condition");
1299 unsigned padding
= 0;
1301 /* Now that we have finished scheduling, build up the bundle */
1302 midgard_instruction
*stages
[] = { vmul
, sadd
, vadd
, smul
, vlut
, branch
};
1304 for (unsigned i
= 0; i
< ARRAY_SIZE(stages
); ++i
) {
1306 bundle
.control
|= stages
[i
]->unit
;
1307 bytes_emitted
+= bytes_for_instruction(stages
[i
]);
1308 bundle
.instructions
[bundle
.instruction_count
++] = stages
[i
];
1312 /* Pad ALU op to nearest word */
1314 if (bytes_emitted
& 15) {
1315 padding
= 16 - (bytes_emitted
& 15);
1316 bytes_emitted
+= padding
;
1319 /* Constants must always be quadwords */
1320 if (bundle
.has_embedded_constants
)
1321 bytes_emitted
+= 16;
1323 /* Size ALU instruction for tag */
1324 bundle
.tag
= (TAG_ALU_4
) + (bytes_emitted
/ 16) - 1;
1325 bundle
.padding
= padding
;
1326 bundle
.control
|= bundle
.tag
;
1331 /* Schedule a single block by iterating its instruction to create bundles.
1332 * While we go, tally about the bundle sizes to compute the block size. */
1336 schedule_block(compiler_context
*ctx
, midgard_block
*block
)
1338 /* Copy list to dynamic array */
1340 midgard_instruction
**instructions
= flatten_mir(block
, &len
);
1342 /* Calculate dependencies and initial worklist */
1343 unsigned node_count
= ctx
->temp_count
+ 1;
1344 mir_create_dependency_graph(instructions
, len
, node_count
);
1346 /* Allocate the worklist */
1347 size_t sz
= BITSET_WORDS(len
) * sizeof(BITSET_WORD
);
1348 BITSET_WORD
*worklist
= calloc(sz
, 1);
1349 mir_initialize_worklist(worklist
, instructions
, len
);
1351 util_dynarray_init(&block
->bundles
, NULL
);
1353 block
->quadword_count
= 0;
1356 mir_foreach_instr_in_block(block
, ins
) {
1362 midgard_bundle bundle
= schedule_bundle(ctx
, block
, ins
, &skip
);
1363 util_dynarray_append(&block
->bundles
, midgard_bundle
, bundle
);
1365 if (bundle
.has_blend_constant
) {
1366 unsigned offset
= ctx
->quadword_count
+ block
->quadword_count
+ quadword_size(bundle
.tag
) - 1;
1367 ctx
->blend_constant_offset
= offset
* 0x10;
1370 block
->quadword_count
+= quadword_size(bundle
.tag
);
1373 block
->is_scheduled
= true;
1374 ctx
->quadword_count
+= block
->quadword_count
;
1377 /* When we're 'squeezing down' the values in the IR, we maintain a hash
1381 find_or_allocate_temp(compiler_context
*ctx
, unsigned hash
)
1383 if (hash
>= SSA_FIXED_MINIMUM
)
1386 unsigned temp
= (uintptr_t) _mesa_hash_table_u64_search(
1387 ctx
->hash_to_temp
, hash
+ 1);
1392 /* If no temp is find, allocate one */
1393 temp
= ctx
->temp_count
++;
1394 ctx
->max_hash
= MAX2(ctx
->max_hash
, hash
);
1396 _mesa_hash_table_u64_insert(ctx
->hash_to_temp
,
1397 hash
+ 1, (void *) ((uintptr_t) temp
+ 1));
1402 /* Reassigns numbering to get rid of gaps in the indices */
1405 mir_squeeze_index(compiler_context
*ctx
)
1408 ctx
->temp_count
= 0;
1409 /* TODO don't leak old hash_to_temp */
1410 ctx
->hash_to_temp
= _mesa_hash_table_u64_create(NULL
);
1412 mir_foreach_instr_global(ctx
, ins
) {
1413 ins
->dest
= find_or_allocate_temp(ctx
, ins
->dest
);
1415 for (unsigned i
= 0; i
< ARRAY_SIZE(ins
->src
); ++i
)
1416 ins
->src
[i
] = find_or_allocate_temp(ctx
, ins
->src
[i
]);
1420 static midgard_instruction
1421 v_load_store_scratch(
1427 /* We index by 32-bit vec4s */
1428 unsigned byte
= (index
* 4 * 4);
1430 midgard_instruction ins
= {
1431 .type
= TAG_LOAD_STORE_4
,
1434 .src
= { ~0, ~0, ~0 },
1436 .op
= is_store
? midgard_op_st_int4
: midgard_op_ld_int4
,
1437 .swizzle
= SWIZZLE_XYZW
,
1439 /* For register spilling - to thread local storage */
1443 /* Splattered across, TODO combine logically */
1444 .varying_parameters
= (byte
& 0x1FF) << 1,
1445 .address
= (byte
>> 9)
1448 /* If we spill an unspill, RA goes into an infinite loop */
1453 /* r0 = r26, r1 = r27 */
1454 assert(srcdest
== SSA_FIXED_REGISTER(26) || srcdest
== SSA_FIXED_REGISTER(27));
1455 ins
.src
[0] = srcdest
;
1463 /* If register allocation fails, find the best spill node and spill it to fix
1464 * whatever the issue was. This spill node could be a work register (spilling
1465 * to thread local storage), but it could also simply be a special register
1466 * that needs to spill to become a work register. */
1468 static void mir_spill_register(
1469 compiler_context
*ctx
,
1471 unsigned *spill_count
)
1473 unsigned spill_index
= ctx
->temp_count
;
1475 /* Our first step is to calculate spill cost to figure out the best
1476 * spill node. All nodes are equal in spill cost, but we can't spill
1477 * nodes written to from an unspill */
1479 for (unsigned i
= 0; i
< ctx
->temp_count
; ++i
) {
1480 ra_set_node_spill_cost(g
, i
, 1.0);
1483 /* We can't spill any bundles that contain unspills. This could be
1484 * optimized to allow use of r27 to spill twice per bundle, but if
1485 * you're at the point of optimizing spilling, it's too late. */
1487 mir_foreach_block(ctx
, block
) {
1488 mir_foreach_bundle_in_block(block
, bun
) {
1489 bool no_spill
= false;
1491 for (unsigned i
= 0; i
< bun
->instruction_count
; ++i
)
1492 no_spill
|= bun
->instructions
[i
]->no_spill
;
1497 for (unsigned i
= 0; i
< bun
->instruction_count
; ++i
) {
1498 unsigned dest
= bun
->instructions
[i
]->dest
;
1499 if (dest
< ctx
->temp_count
)
1500 ra_set_node_spill_cost(g
, dest
, -1.0);
1505 int spill_node
= ra_get_best_spill_node(g
);
1507 if (spill_node
< 0) {
1508 mir_print_shader(ctx
);
1512 /* We have a spill node, so check the class. Work registers
1513 * legitimately spill to TLS, but special registers just spill to work
1516 unsigned class = ra_get_node_class(g
, spill_node
);
1517 bool is_special
= (class >> 2) != REG_CLASS_WORK
;
1518 bool is_special_w
= (class >> 2) == REG_CLASS_TEXW
;
1520 /* Allocate TLS slot (maybe) */
1521 unsigned spill_slot
= !is_special
? (*spill_count
)++ : 0;
1523 /* For TLS, replace all stores to the spilled node. For
1524 * special reads, just keep as-is; the class will be demoted
1525 * implicitly. For special writes, spill to a work register */
1527 if (!is_special
|| is_special_w
) {
1529 spill_slot
= spill_index
++;
1531 mir_foreach_block(ctx
, block
) {
1532 mir_foreach_instr_in_block_safe(block
, ins
) {
1533 if (ins
->dest
!= spill_node
) continue;
1535 midgard_instruction st
;
1538 st
= v_mov(spill_node
, blank_alu_src
, spill_slot
);
1541 ins
->dest
= SSA_FIXED_REGISTER(26);
1542 ins
->no_spill
= true;
1543 st
= v_load_store_scratch(ins
->dest
, spill_slot
, true, ins
->mask
);
1546 /* Hint: don't rewrite this node */
1549 mir_insert_instruction_after_scheduled(ctx
, block
, ins
, st
);
1557 /* For special reads, figure out how many components we need */
1558 unsigned read_mask
= 0;
1560 mir_foreach_instr_global_safe(ctx
, ins
) {
1561 read_mask
|= mir_mask_of_read_components(ins
, spill_node
);
1564 /* Insert a load from TLS before the first consecutive
1565 * use of the node, rewriting to use spilled indices to
1566 * break up the live range. Or, for special, insert a
1567 * move. Ironically the latter *increases* register
1568 * pressure, but the two uses of the spilling mechanism
1569 * are somewhat orthogonal. (special spilling is to use
1570 * work registers to back special registers; TLS
1571 * spilling is to use memory to back work registers) */
1573 mir_foreach_block(ctx
, block
) {
1574 bool consecutive_skip
= false;
1575 unsigned consecutive_index
= 0;
1577 mir_foreach_instr_in_block(block
, ins
) {
1578 /* We can't rewrite the moves used to spill in the
1579 * first place. These moves are hinted. */
1580 if (ins
->hint
) continue;
1582 if (!mir_has_arg(ins
, spill_node
)) {
1583 consecutive_skip
= false;
1587 if (consecutive_skip
) {
1589 mir_rewrite_index_src_single(ins
, spill_node
, consecutive_index
);
1593 if (!is_special_w
) {
1594 consecutive_index
= ++spill_index
;
1596 midgard_instruction
*before
= ins
;
1598 /* For a csel, go back one more not to break up the bundle */
1599 if (ins
->type
== TAG_ALU_4
&& OP_IS_CSEL(ins
->alu
.op
))
1600 before
= mir_prev_op(before
);
1602 midgard_instruction st
;
1606 st
= v_mov(spill_node
, blank_alu_src
, consecutive_index
);
1610 st
= v_load_store_scratch(consecutive_index
, spill_slot
, false, 0xF);
1613 /* Mask the load based on the component count
1614 * actually needed to prvent RA loops */
1616 st
.mask
= read_mask
;
1618 mir_insert_instruction_before_scheduled(ctx
, block
, before
, st
);
1619 // consecutive_skip = true;
1621 /* Special writes already have their move spilled in */
1622 consecutive_index
= spill_slot
;
1626 /* Rewrite to use */
1627 mir_rewrite_index_src_single(ins
, spill_node
, consecutive_index
);
1636 mir_foreach_instr_global(ctx
, ins
) {
1642 schedule_program(compiler_context
*ctx
)
1644 struct ra_graph
*g
= NULL
;
1645 bool spilled
= false;
1646 int iter_count
= 1000; /* max iterations */
1648 /* Number of 128-bit slots in memory we've spilled into */
1649 unsigned spill_count
= 0;
1651 midgard_promote_uniforms(ctx
, 16);
1653 /* Must be lowered right before RA */
1654 mir_squeeze_index(ctx
);
1655 mir_lower_special_reads(ctx
);
1656 mir_squeeze_index(ctx
);
1658 /* Lowering can introduce some dead moves */
1660 mir_foreach_block(ctx
, block
) {
1661 midgard_opt_dead_move_eliminate(ctx
, block
);
1662 schedule_block(ctx
, block
);
1665 mir_create_pipeline_registers(ctx
);
1669 mir_spill_register(ctx
, g
, &spill_count
);
1671 mir_squeeze_index(ctx
);
1674 g
= allocate_registers(ctx
, &spilled
);
1675 } while(spilled
&& ((iter_count
--) > 0));
1677 if (iter_count
<= 0) {
1678 fprintf(stderr
, "panfrost: Gave up allocating registers, rendering will be incomplete\n");
1682 /* Report spilling information. spill_count is in 128-bit slots (vec4 x
1683 * fp32), but tls_size is in bytes, so multiply by 16 */
1685 ctx
->tls_size
= spill_count
* 16;
1687 install_registers(ctx
, g
);