f9c2155b7df18442f2d6ea346ac85b54e92caf74
2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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
24 * Rob Clark <robclark@freedesktop.org>
30 //#include "util/u_math.h"
31 //#include "util/register_allocate.h"
32 //#include "util/ralloc.h"
33 #include "util/bitset.h"
36 //#include "ir3_compiler.h"
39 static const unsigned class_sizes
[] = {
41 4 + 4, /* txd + 1d/2d */
44 #define class_count ARRAY_SIZE(class_sizes)
46 static const unsigned half_class_sizes
[] = {
49 #define half_class_count ARRAY_SIZE(half_class_sizes)
51 /* seems to just be used for compute shaders? Seems like vec1 and vec3
52 * are sufficient (for now?)
54 static const unsigned high_class_sizes
[] = {
57 #define high_class_count ARRAY_SIZE(high_class_sizes)
59 #define total_class_count (class_count + half_class_count + high_class_count)
61 /* Below a0.x are normal regs. RA doesn't need to assign a0.x/p0.x. */
62 #define NUM_REGS (4 * 48) /* r0 to r47 */
63 #define NUM_HIGH_REGS (4 * 8) /* r48 to r55 */
64 #define FIRST_HIGH_REG (4 * 48)
65 /* Number of virtual regs in a given class: */
66 #define CLASS_REGS(i) (NUM_REGS - (class_sizes[i] - 1))
67 #define HALF_CLASS_REGS(i) (NUM_REGS - (half_class_sizes[i] - 1))
68 #define HIGH_CLASS_REGS(i) (NUM_HIGH_REGS - (high_class_sizes[i] - 1))
70 #define HALF_OFFSET (class_count)
71 #define HIGH_OFFSET (class_count + half_class_count)
73 /* register-set, created one time, used for all shaders: */
74 struct ir3_ra_reg_set
{
76 unsigned int classes
[class_count
];
77 unsigned int half_classes
[half_class_count
];
78 unsigned int high_classes
[high_class_count
];
79 /* maps flat virtual register space to base gpr: */
80 uint16_t *ra_reg_to_gpr
;
81 /* maps cls,gpr to flat virtual register space: */
82 uint16_t **gpr_to_ra_reg
;
85 /* additional block-data (per-block) */
86 struct ir3_ra_block_data
{
87 BITSET_WORD
*def
; /* variables defined before used in block */
88 BITSET_WORD
*use
; /* variables used before defined in block */
89 BITSET_WORD
*livein
; /* which defs reach entry point of block */
90 BITSET_WORD
*liveout
; /* which defs reach exit point of block */
93 /* additional instruction-data (per-instruction) */
94 struct ir3_ra_instr_data
{
95 /* cached instruction 'definer' info: */
96 struct ir3_instruction
*defn
;
100 /* register-assign context, per-shader */
102 struct ir3_shader_variant
*v
;
105 struct ir3_ra_reg_set
*set
;
108 /* Are we in the scalar assignment pass? In this pass, all larger-
109 * than-vec1 vales have already been assigned and pre-colored, so
110 * we only consider scalar values.
114 unsigned alloc_count
;
115 /* one per class, plus one slot for arrays: */
116 unsigned class_alloc_count
[total_class_count
+ 1];
117 unsigned class_base
[total_class_count
+ 1];
119 unsigned *def
, *use
; /* def/use table */
120 struct ir3_ra_instr_data
*instrd
;
122 /* Mapping vreg name back to instruction, used select reg callback: */
123 struct hash_table
*name_to_instr
;
125 /* Tracking for max half/full register assigned. We don't need to
126 * track high registers.
128 * The feedback about registers used in first pass is used to choose
129 * a target register usage to round-robin between in the 2nd pass.
131 unsigned max_assigned
;
132 unsigned max_half_assigned
;
134 /* Tracking for select_reg callback */
135 unsigned start_search_reg
;
140 ra_name(struct ir3_ra_ctx
*ctx
, struct ir3_ra_instr_data
*id
)
143 debug_assert(id
->cls
>= 0);
144 debug_assert(id
->cls
< total_class_count
); /* we shouldn't get arrays here.. */
145 name
= ctx
->class_base
[id
->cls
] + id
->defn
->name
;
146 debug_assert(name
< ctx
->alloc_count
);
150 /* Get the scalar name of the n'th component of an instruction dst: */
152 scalar_name(struct ir3_ra_ctx
*ctx
, struct ir3_instruction
*instr
, unsigned n
)
154 if (ctx
->scalar_pass
) {
155 if (instr
->opc
== OPC_META_SPLIT
) {
156 debug_assert(n
== 0); /* split results in a scalar */
157 struct ir3_instruction
*src
= instr
->regs
[1]->instr
;
158 return scalar_name(ctx
, src
, instr
->split
.off
);
159 } else if (instr
->opc
== OPC_META_COLLECT
) {
160 debug_assert(n
< (instr
->regs_count
+ 1));
161 struct ir3_instruction
*src
= instr
->regs
[n
+ 1]->instr
;
162 return scalar_name(ctx
, src
, 0);
165 debug_assert(n
== 0);
168 return ra_name(ctx
, &ctx
->instrd
[instr
->ip
]) + n
;
172 writes_gpr(struct ir3_instruction
*instr
)
174 if (dest_regs(instr
) == 0)
176 /* is dest a normal temp register: */
177 struct ir3_register
*reg
= instr
->regs
[0];
178 debug_assert(!(reg
->flags
& (IR3_REG_CONST
| IR3_REG_IMMED
)));
179 if ((reg
->num
== regid(REG_A0
, 0)) ||
180 (reg
->num
== regid(REG_P0
, 0)))
185 int ra_size_to_class(unsigned sz
, bool half
, bool high
);
187 #endif /* IR3_RA_H_ */