-/* This routine creates a register set. Should be called infrequently since
- * it's slow and can be cached. For legibility, variables are named in terms of
- * work registers, although it is also used to create the register set for
- * special register allocation */
-
-static void
-add_shadow_conflicts (struct ra_regs *regs, unsigned base, unsigned shadow)
-{
- for (unsigned a = 0; a < WORK_STRIDE; ++a) {
- unsigned reg_a = (WORK_STRIDE * base) + a;
-
- for (unsigned b = 0; b < WORK_STRIDE; ++b) {
- unsigned reg_b = (WORK_STRIDE * shadow) + b;
-
- ra_add_reg_conflict(regs, reg_a, reg_b);
- ra_add_reg_conflict(regs, reg_b, reg_a);
- }
- }
-}
-
-static struct ra_regs *
-create_register_set(unsigned work_count, unsigned *classes)
-{
- int virtual_count = 32 * WORK_STRIDE;
-
- /* First, initialize the RA */
- struct ra_regs *regs = ra_alloc_reg_set(NULL, virtual_count, true);
-
- for (unsigned c = 0; c < NR_REG_CLASSES; ++c) {
- int work_vec4 = ra_alloc_reg_class(regs);
- int work_vec3 = ra_alloc_reg_class(regs);
- int work_vec2 = ra_alloc_reg_class(regs);
- int work_vec1 = ra_alloc_reg_class(regs);
-
- classes[4*c + 0] = work_vec1;
- classes[4*c + 1] = work_vec2;
- classes[4*c + 2] = work_vec3;
- classes[4*c + 3] = work_vec4;
-
- /* Special register classes have other register counts */
- unsigned count =
- (c == REG_CLASS_WORK) ? work_count :
- (c == REG_CLASS_LDST27) ? 1 : 2;
-
- /* We arbitraily pick r17 (RA unused) as the shadow for r27 */
- unsigned first_reg =
- (c == REG_CLASS_LDST) ? 26 :
- (c == REG_CLASS_LDST27) ? SHADOW_R27 :
- (c == REG_CLASS_TEXR) ? 28 :
- (c == REG_CLASS_TEXW) ? SHADOW_R28 :
- 0;
-
- /* Add the full set of work registers */
- for (unsigned i = first_reg; i < (first_reg + count); ++i) {
- int base = WORK_STRIDE * i;
-
- /* Build a full set of subdivisions */
- ra_class_add_reg(regs, work_vec4, base);
- ra_class_add_reg(regs, work_vec3, base + 1);
- ra_class_add_reg(regs, work_vec3, base + 2);
- ra_class_add_reg(regs, work_vec2, base + 3);
- ra_class_add_reg(regs, work_vec2, base + 4);
- ra_class_add_reg(regs, work_vec2, base + 5);
- ra_class_add_reg(regs, work_vec1, base + 6);
- ra_class_add_reg(regs, work_vec1, base + 7);
- ra_class_add_reg(regs, work_vec1, base + 8);
- ra_class_add_reg(regs, work_vec1, base + 9);
-
- for (unsigned a = 0; a < 10; ++a) {
- unsigned mask1 = reg_type_to_mask[a];
-
- for (unsigned b = 0; b < 10; ++b) {
- unsigned mask2 = reg_type_to_mask[b];
-
- if (mask1 & mask2)
- ra_add_reg_conflict(regs,
- base + a, base + b);
- }
- }
- }
- }
-
-
- /* We have duplicate classes */
- add_shadow_conflicts(regs, 27, SHADOW_R27);
- add_shadow_conflicts(regs, 28, SHADOW_R28);
- add_shadow_conflicts(regs, 29, SHADOW_R29);
-
- /* We're done setting up */
- ra_set_finalize(regs, NULL);
-
- return regs;
-}
-
-/* This routine gets a precomputed register set off the screen if it's able, or
- * otherwise it computes one on the fly */
-
-static struct ra_regs *
-get_register_set(struct midgard_screen *screen, unsigned work_count, unsigned **classes)
-{
- /* Bounds check */
- assert(work_count >= 8);
- assert(work_count <= 16);
-
- /* Compute index */
- unsigned index = work_count - 8;
-
- /* Find the reg set */
- struct ra_regs *cached = screen->regs[index];
-
- if (cached) {
- assert(screen->reg_classes[index]);
- *classes = screen->reg_classes[index];
- return cached;
- }
-
- /* Otherwise, create one */
- struct ra_regs *created = create_register_set(work_count, screen->reg_classes[index]);
-
- /* Cache it and use it */
- screen->regs[index] = created;
-
- *classes = screen->reg_classes[index];
- return created;
-}
-
-/* Assign a (special) class, ensuring that it is compatible with whatever class
- * was already set */
-