2 * Copyright © 2018 Valve Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 void perfwarn(bool cond
, const char *msg
, Instruction
*instr
)
36 fprintf(stderr
, "ACO performance warning: %s\n", msg
);
38 fprintf(stderr
, "instruction: ");
39 aco_print_instr(instr
, stderr
);
40 fprintf(stderr
, "\n");
43 if (debug_flags
& DEBUG_PERFWARN
)
49 void validate(Program
* program
, FILE * output
)
51 if (!(debug_flags
& DEBUG_VALIDATE
))
55 auto check
= [&output
, &is_valid
](bool check
, const char * msg
, aco::Instruction
* instr
) -> void {
57 fprintf(output
, "%s: ", msg
);
58 aco_print_instr(instr
, output
);
59 fprintf(output
, "\n");
63 auto check_block
= [&output
, &is_valid
](bool check
, const char * msg
, aco::Block
* block
) -> void {
65 fprintf(output
, "%s: BB%u\n", msg
, block
->index
);
70 for (Block
& block
: program
->blocks
) {
71 for (aco_ptr
<Instruction
>& instr
: block
.instructions
) {
73 /* check base format */
74 Format base_format
= instr
->format
;
75 base_format
= (Format
)((uint32_t)base_format
& ~(uint32_t)Format::SDWA
);
76 base_format
= (Format
)((uint32_t)base_format
& ~(uint32_t)Format::DPP
);
77 if ((uint32_t)base_format
& (uint32_t)Format::VOP1
)
78 base_format
= Format::VOP1
;
79 else if ((uint32_t)base_format
& (uint32_t)Format::VOP2
)
80 base_format
= Format::VOP2
;
81 else if ((uint32_t)base_format
& (uint32_t)Format::VOPC
)
82 base_format
= Format::VOPC
;
83 else if ((uint32_t)base_format
& (uint32_t)Format::VINTRP
)
84 base_format
= Format::VINTRP
;
85 check(base_format
== instr_info
.format
[(int)instr
->opcode
], "Wrong base format for instruction", instr
.get());
87 /* check VOP3 modifiers */
88 if (((uint32_t)instr
->format
& (uint32_t)Format::VOP3
) && instr
->format
!= Format::VOP3
) {
89 check(base_format
== Format::VOP2
||
90 base_format
== Format::VOP1
||
91 base_format
== Format::VOPC
||
92 base_format
== Format::VINTRP
,
93 "Format cannot have VOP3A/VOP3B applied", instr
.get());
97 if (instr
->isSDWA()) {
98 check(base_format
== Format::VOP2
||
99 base_format
== Format::VOP1
||
100 base_format
== Format::VOPC
,
101 "Format cannot have SDWA applied", instr
.get());
103 check(program
->chip_class
>= GFX8
, "SDWA is GFX8+ only", instr
.get());
105 SDWA_instruction
*sdwa
= static_cast<SDWA_instruction
*>(instr
.get());
106 check(sdwa
->omod
== 0 || program
->chip_class
>= GFX9
, "SDWA omod only supported on GFX9+", instr
.get());
107 if (base_format
== Format::VOPC
) {
108 check(sdwa
->clamp
== false || program
->chip_class
== GFX8
, "SDWA VOPC clamp only supported on GFX8", instr
.get());
109 check((instr
->definitions
[0].isFixed() && instr
->definitions
[0].physReg() == vcc
) ||
110 program
->chip_class
>= GFX9
,
111 "SDWA+VOPC definition must be fixed to vcc on GFX8", instr
.get());
114 if (instr
->operands
.size() >= 3) {
115 check(instr
->operands
[2].isFixed() && instr
->operands
[2].physReg() == vcc
,
116 "3rd operand must be fixed to vcc with SDWA", instr
.get());
118 if (instr
->definitions
.size() >= 2) {
119 check(instr
->definitions
[1].isFixed() && instr
->definitions
[1].physReg() == vcc
,
120 "2nd definition must be fixed to vcc with SDWA", instr
.get());
123 check(instr
->opcode
!= aco_opcode::v_madmk_f32
&&
124 instr
->opcode
!= aco_opcode::v_madak_f32
&&
125 instr
->opcode
!= aco_opcode::v_madmk_f16
&&
126 instr
->opcode
!= aco_opcode::v_madak_f16
&&
127 instr
->opcode
!= aco_opcode::v_readfirstlane_b32
&&
128 instr
->opcode
!= aco_opcode::v_clrexcp
&&
129 instr
->opcode
!= aco_opcode::v_swap_b32
,
130 "SDWA can't be used with this opcode", instr
.get());
131 if (program
->chip_class
!= GFX8
) {
132 check(instr
->opcode
!= aco_opcode::v_mac_f32
&&
133 instr
->opcode
!= aco_opcode::v_mac_f16
&&
134 instr
->opcode
!= aco_opcode::v_fmac_f32
&&
135 instr
->opcode
!= aco_opcode::v_fmac_f16
,
136 "SDWA can't be used with this opcode", instr
.get());
141 if (instr
->isVOP3()) {
142 VOP3A_instruction
*vop3
= static_cast<VOP3A_instruction
*>(instr
.get());
143 check(vop3
->opsel
== 0 || program
->chip_class
>= GFX9
, "Opsel is only supported on GFX9+", instr
.get());
144 check((vop3
->opsel
& ~(0x10 | ((1 << instr
->operands
.size()) - 1))) == 0, "Unused bits in opsel must be zeroed out", instr
.get());
147 /* check for undefs */
148 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++) {
149 if (instr
->operands
[i
].isUndefined()) {
150 bool flat
= instr
->format
== Format::FLAT
|| instr
->format
== Format::SCRATCH
|| instr
->format
== Format::GLOBAL
;
151 bool can_be_undef
= is_phi(instr
) || instr
->format
== Format::EXP
||
152 instr
->format
== Format::PSEUDO_REDUCTION
||
153 (flat
&& i
== 1) || (instr
->format
== Format::MIMG
&& i
== 1) ||
154 ((instr
->format
== Format::MUBUF
|| instr
->format
== Format::MTBUF
) && i
== 1);
155 check(can_be_undef
, "Undefs can only be used in certain operands", instr
.get());
159 if (instr
->isSALU() || instr
->isVALU()) {
162 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++)
164 Operand op
= instr
->operands
[i
];
168 check(instr
->format
== Format::SOP1
||
169 instr
->format
== Format::SOP2
||
170 instr
->format
== Format::SOPC
||
171 instr
->format
== Format::VOP1
||
172 instr
->format
== Format::VOP2
||
173 instr
->format
== Format::VOPC
||
174 (instr
->isVOP3() && program
->chip_class
>= GFX10
),
175 "Literal applied on wrong instruction format", instr
.get());
177 check(literal
.isUndefined() || (literal
.size() == op
.size() && literal
.constantValue() == op
.constantValue()), "Only 1 Literal allowed", instr
.get());
179 check(!instr
->isVALU() || instr
->isVOP3() || i
== 0 || i
== 2, "Wrong source position for Literal argument", instr
.get());
182 /* check num sgprs for VALU */
183 if (instr
->isVALU()) {
184 bool is_shift64
= instr
->opcode
== aco_opcode::v_lshlrev_b64
||
185 instr
->opcode
== aco_opcode::v_lshrrev_b64
||
186 instr
->opcode
== aco_opcode::v_ashrrev_i64
;
187 unsigned const_bus_limit
= 1;
188 if (program
->chip_class
>= GFX10
&& !is_shift64
)
191 uint32_t scalar_mask
= instr
->isVOP3() ? 0x7 : 0x5;
193 scalar_mask
= program
->chip_class
>= GFX9
? 0x7 : 0x4;
195 check(instr
->definitions
[0].getTemp().type() == RegType::vgpr
||
196 (int) instr
->format
& (int) Format::VOPC
||
197 instr
->opcode
== aco_opcode::v_readfirstlane_b32
||
198 instr
->opcode
== aco_opcode::v_readlane_b32
||
199 instr
->opcode
== aco_opcode::v_readlane_b32_e64
,
200 "Wrong Definition type for VALU instruction", instr
.get());
201 unsigned num_sgprs
= 0;
202 unsigned sgpr
[] = {0, 0};
203 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++)
205 Operand op
= instr
->operands
[i
];
206 if (instr
->opcode
== aco_opcode::v_readfirstlane_b32
||
207 instr
->opcode
== aco_opcode::v_readlane_b32
||
208 instr
->opcode
== aco_opcode::v_readlane_b32_e64
||
209 instr
->opcode
== aco_opcode::v_writelane_b32
||
210 instr
->opcode
== aco_opcode::v_writelane_b32_e64
) {
211 check(!op
.isLiteral(), "No literal allowed on VALU instruction", instr
.get());
212 check(i
== 1 || (op
.isTemp() && op
.regClass() == v1
), "Wrong Operand type for VALU instruction", instr
.get());
215 if (op
.isTemp() && instr
->operands
[i
].regClass().type() == RegType::sgpr
) {
216 check(scalar_mask
& (1 << i
), "Wrong source position for SGPR argument", instr
.get());
218 if (op
.tempId() != sgpr
[0] && op
.tempId() != sgpr
[1]) {
220 sgpr
[num_sgprs
++] = op
.tempId();
224 if (op
.isConstant() && !op
.isLiteral())
225 check(scalar_mask
& (1 << i
), "Wrong source position for constant argument", instr
.get());
227 check(num_sgprs
+ (literal
.isUndefined() ? 0 : 1) <= const_bus_limit
, "Too many SGPRs/literals", instr
.get());
230 if (instr
->format
== Format::SOP1
|| instr
->format
== Format::SOP2
) {
231 check(instr
->definitions
[0].getTemp().type() == RegType::sgpr
, "Wrong Definition type for SALU instruction", instr
.get());
232 for (const Operand
& op
: instr
->operands
) {
233 check(op
.isConstant() || op
.regClass().type() <= RegType::sgpr
,
234 "Wrong Operand type for SALU instruction", instr
.get());
239 switch (instr
->format
) {
240 case Format::PSEUDO
: {
241 if (instr
->opcode
== aco_opcode::p_create_vector
) {
243 for (const Operand
& op
: instr
->operands
) {
246 check(size
== instr
->definitions
[0].size(), "Definition size does not match operand sizes", instr
.get());
247 if (instr
->definitions
[0].getTemp().type() == RegType::sgpr
) {
248 for (const Operand
& op
: instr
->operands
) {
249 check(op
.isConstant() || op
.regClass().type() == RegType::sgpr
,
250 "Wrong Operand type for scalar vector", instr
.get());
253 } else if (instr
->opcode
== aco_opcode::p_extract_vector
) {
254 check((instr
->operands
[0].isTemp()) && instr
->operands
[1].isConstant(), "Wrong Operand types", instr
.get());
255 check(instr
->operands
[1].constantValue() < instr
->operands
[0].size(), "Index out of range", instr
.get());
256 check(instr
->definitions
[0].getTemp().type() == RegType::vgpr
|| instr
->operands
[0].regClass().type() == RegType::sgpr
,
257 "Cannot extract SGPR value from VGPR vector", instr
.get());
258 } else if (instr
->opcode
== aco_opcode::p_parallelcopy
) {
259 check(instr
->definitions
.size() == instr
->operands
.size(), "Number of Operands does not match number of Definitions", instr
.get());
260 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++) {
261 if (instr
->operands
[i
].isTemp())
262 check((instr
->definitions
[i
].getTemp().type() == instr
->operands
[i
].regClass().type()) ||
263 (instr
->definitions
[i
].getTemp().type() == RegType::vgpr
&& instr
->operands
[i
].regClass().type() == RegType::sgpr
),
264 "Operand and Definition types do not match", instr
.get());
266 } else if (instr
->opcode
== aco_opcode::p_phi
) {
267 check(instr
->operands
.size() == block
.logical_preds
.size(), "Number of Operands does not match number of predecessors", instr
.get());
268 check(instr
->definitions
[0].getTemp().type() == RegType::vgpr
|| instr
->definitions
[0].getTemp().regClass() == program
->lane_mask
, "Logical Phi Definition must be vgpr or divergent boolean", instr
.get());
269 } else if (instr
->opcode
== aco_opcode::p_linear_phi
) {
270 for (const Operand
& op
: instr
->operands
)
271 check(!op
.isTemp() || op
.getTemp().is_linear(), "Wrong Operand type", instr
.get());
272 check(instr
->operands
.size() == block
.linear_preds
.size(), "Number of Operands does not match number of predecessors", instr
.get());
277 if (instr
->operands
.size() >= 1)
278 check(instr
->operands
[0].isTemp() && instr
->operands
[0].regClass().type() == RegType::sgpr
, "SMEM operands must be sgpr", instr
.get());
279 if (instr
->operands
.size() >= 2)
280 check(instr
->operands
[1].isConstant() || (instr
->operands
[1].isTemp() && instr
->operands
[1].regClass().type() == RegType::sgpr
),
281 "SMEM offset must be constant or sgpr", instr
.get());
282 if (!instr
->definitions
.empty())
283 check(instr
->definitions
[0].getTemp().type() == RegType::sgpr
, "SMEM result must be sgpr", instr
.get());
287 case Format::MUBUF
: {
288 check(instr
->operands
.size() > 1, "VMEM instructions must have at least one operand", instr
.get());
289 check(instr
->operands
[1].hasRegClass() && instr
->operands
[1].regClass().type() == RegType::vgpr
,
290 "VADDR must be in vgpr for VMEM instructions", instr
.get());
291 check(instr
->operands
[0].isTemp() && instr
->operands
[0].regClass().type() == RegType::sgpr
, "VMEM resource constant must be sgpr", instr
.get());
292 check(instr
->operands
.size() < 4 || (instr
->operands
[3].isTemp() && instr
->operands
[3].regClass().type() == RegType::vgpr
), "VMEM write data must be vgpr", instr
.get());
296 check(instr
->operands
.size() == 3, "MIMG instructions must have exactly 3 operands", instr
.get());
297 check(instr
->operands
[0].hasRegClass() && (instr
->operands
[0].regClass() == s4
|| instr
->operands
[0].regClass() == s8
),
298 "MIMG operands[0] (resource constant) must be in 4 or 8 SGPRs", instr
.get());
299 if (instr
->operands
[1].hasRegClass() && instr
->operands
[1].regClass().type() == RegType::sgpr
)
300 check(instr
->operands
[1].regClass() == s4
, "MIMG operands[1] (sampler constant) must be 4 SGPRs", instr
.get());
301 else if (instr
->operands
[1].hasRegClass() && instr
->operands
[1].regClass().type() == RegType::vgpr
)
302 check((instr
->definitions
.empty() || instr
->definitions
[0].regClass() == instr
->operands
[1].regClass() ||
303 instr
->opcode
== aco_opcode::image_atomic_cmpswap
|| instr
->opcode
== aco_opcode::image_atomic_fcmpswap
),
304 "MIMG operands[1] (VDATA) must be the same as definitions[0] for atomics", instr
.get());
305 check(instr
->operands
[2].hasRegClass() && instr
->operands
[2].regClass().type() == RegType::vgpr
,
306 "MIMG operands[2] (VADDR) must be VGPR", instr
.get());
307 check(instr
->definitions
.empty() || (instr
->definitions
[0].isTemp() && instr
->definitions
[0].regClass().type() == RegType::vgpr
),
308 "MIMG definitions[0] (VDATA) must be VGPR", instr
.get());
312 for (const Operand
& op
: instr
->operands
) {
313 check((op
.isTemp() && op
.regClass().type() == RegType::vgpr
) || op
.physReg() == m0
,
314 "Only VGPRs are valid DS instruction operands", instr
.get());
316 if (!instr
->definitions
.empty())
317 check(instr
->definitions
[0].getTemp().type() == RegType::vgpr
, "DS instruction must return VGPR", instr
.get());
321 for (unsigned i
= 0; i
< 4; i
++)
322 check(instr
->operands
[i
].hasRegClass() && instr
->operands
[i
].regClass().type() == RegType::vgpr
,
323 "Only VGPRs are valid Export arguments", instr
.get());
327 check(instr
->operands
[1].isUndefined(), "Flat instructions don't support SADDR", instr
.get());
330 case Format::SCRATCH
: {
331 check(instr
->operands
[0].isTemp() && instr
->operands
[0].regClass().type() == RegType::vgpr
, "FLAT/GLOBAL/SCRATCH address must be vgpr", instr
.get());
332 check(instr
->operands
[1].hasRegClass() && instr
->operands
[1].regClass().type() == RegType::sgpr
,
333 "FLAT/GLOBAL/SCRATCH sgpr address must be undefined or sgpr", instr
.get());
334 if (!instr
->definitions
.empty())
335 check(instr
->definitions
[0].getTemp().type() == RegType::vgpr
, "FLAT/GLOBAL/SCRATCH result must be vgpr", instr
.get());
337 check(instr
->operands
[2].regClass().type() == RegType::vgpr
, "FLAT/GLOBAL/SCRATCH data must be vgpr", instr
.get());
347 for (unsigned i
= 0; i
< program
->blocks
.size(); i
++) {
348 Block
& block
= program
->blocks
[i
];
349 check_block(block
.index
== i
, "block.index must match actual index", &block
);
351 /* predecessors/successors should be sorted */
352 for (unsigned j
= 0; j
+ 1 < block
.linear_preds
.size(); j
++)
353 check_block(block
.linear_preds
[j
] < block
.linear_preds
[j
+ 1], "linear predecessors must be sorted", &block
);
354 for (unsigned j
= 0; j
+ 1 < block
.logical_preds
.size(); j
++)
355 check_block(block
.logical_preds
[j
] < block
.logical_preds
[j
+ 1], "logical predecessors must be sorted", &block
);
356 for (unsigned j
= 0; j
+ 1 < block
.linear_succs
.size(); j
++)
357 check_block(block
.linear_succs
[j
] < block
.linear_succs
[j
+ 1], "linear successors must be sorted", &block
);
358 for (unsigned j
= 0; j
+ 1 < block
.logical_succs
.size(); j
++)
359 check_block(block
.logical_succs
[j
] < block
.logical_succs
[j
+ 1], "logical successors must be sorted", &block
);
361 /* critical edges are not allowed */
362 if (block
.linear_preds
.size() > 1) {
363 for (unsigned pred
: block
.linear_preds
)
364 check_block(program
->blocks
[pred
].linear_succs
.size() == 1, "linear critical edges are not allowed", &program
->blocks
[pred
]);
365 for (unsigned pred
: block
.logical_preds
)
366 check_block(program
->blocks
[pred
].logical_succs
.size() == 1, "logical critical edges are not allowed", &program
->blocks
[pred
]);
377 Location() : block(NULL
), instr(NULL
) {}
380 Instruction
*instr
; //NULL if it's the block's live-in
389 bool ra_fail(FILE *output
, Location loc
, Location loc2
, const char *fmt
, ...) {
393 vsprintf(msg
, fmt
, args
);
396 fprintf(stderr
, "RA error found at instruction in BB%d:\n", loc
.block
->index
);
398 aco_print_instr(loc
.instr
, stderr
);
399 fprintf(stderr
, "\n%s", msg
);
401 fprintf(stderr
, "%s", msg
);
404 fprintf(stderr
, " in BB%d:\n", loc2
.block
->index
);
405 aco_print_instr(loc2
.instr
, stderr
);
407 fprintf(stderr
, "\n\n");
412 } /* end namespace */
414 bool validate_ra(Program
*program
, const struct radv_nir_compiler_options
*options
, FILE *output
) {
415 if (!(debug_flags
& DEBUG_VALIDATE_RA
))
419 aco::live live_vars
= aco::live_var_analysis(program
, options
);
420 std::vector
<std::vector
<Temp
>> phi_sgpr_ops(program
->blocks
.size());
422 std::map
<unsigned, Assignment
> assignments
;
423 for (Block
& block
: program
->blocks
) {
426 for (aco_ptr
<Instruction
>& instr
: block
.instructions
) {
427 if (instr
->opcode
== aco_opcode::p_phi
) {
428 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++) {
429 if (instr
->operands
[i
].isTemp() &&
430 instr
->operands
[i
].getTemp().type() == RegType::sgpr
&&
431 instr
->operands
[i
].isFirstKill())
432 phi_sgpr_ops
[block
.logical_preds
[i
]].emplace_back(instr
->operands
[i
].getTemp());
436 loc
.instr
= instr
.get();
437 for (unsigned i
= 0; i
< instr
->operands
.size(); i
++) {
438 Operand
& op
= instr
->operands
[i
];
442 err
|= ra_fail(output
, loc
, Location(), "Operand %d is not assigned a register", i
);
443 if (assignments
.count(op
.tempId()) && assignments
[op
.tempId()].reg
!= op
.physReg())
444 err
|= ra_fail(output
, loc
, assignments
.at(op
.tempId()).firstloc
, "Operand %d has an inconsistent register assignment with instruction", i
);
445 if ((op
.getTemp().type() == RegType::vgpr
&& op
.physReg() + op
.size() > 256 + program
->config
->num_vgprs
) ||
446 (op
.getTemp().type() == RegType::sgpr
&& op
.physReg() + op
.size() > program
->config
->num_sgprs
&& op
.physReg() < program
->sgpr_limit
))
447 err
|= ra_fail(output
, loc
, assignments
.at(op
.tempId()).firstloc
, "Operand %d has an out-of-bounds register assignment", i
);
448 if (op
.physReg() == vcc
&& !program
->needs_vcc
)
449 err
|= ra_fail(output
, loc
, Location(), "Operand %d fixed to vcc but needs_vcc=false", i
);
450 if (!assignments
[op
.tempId()].firstloc
.block
)
451 assignments
[op
.tempId()].firstloc
= loc
;
452 if (!assignments
[op
.tempId()].defloc
.block
)
453 assignments
[op
.tempId()].reg
= op
.physReg();
456 for (unsigned i
= 0; i
< instr
->definitions
.size(); i
++) {
457 Definition
& def
= instr
->definitions
[i
];
461 err
|= ra_fail(output
, loc
, Location(), "Definition %d is not assigned a register", i
);
462 if (assignments
[def
.tempId()].defloc
.block
)
463 err
|= ra_fail(output
, loc
, assignments
.at(def
.tempId()).defloc
, "Temporary %%%d also defined by instruction", def
.tempId());
464 if ((def
.getTemp().type() == RegType::vgpr
&& def
.physReg() + def
.size() > 256 + program
->config
->num_vgprs
) ||
465 (def
.getTemp().type() == RegType::sgpr
&& def
.physReg() + def
.size() > program
->config
->num_sgprs
&& def
.physReg() < program
->sgpr_limit
))
466 err
|= ra_fail(output
, loc
, assignments
.at(def
.tempId()).firstloc
, "Definition %d has an out-of-bounds register assignment", i
);
467 if (def
.physReg() == vcc
&& !program
->needs_vcc
)
468 err
|= ra_fail(output
, loc
, Location(), "Definition %d fixed to vcc but needs_vcc=false", i
);
469 if (!assignments
[def
.tempId()].firstloc
.block
)
470 assignments
[def
.tempId()].firstloc
= loc
;
471 assignments
[def
.tempId()].defloc
= loc
;
472 assignments
[def
.tempId()].reg
= def
.physReg();
477 for (Block
& block
: program
->blocks
) {
481 std::array
<unsigned, 512> regs
;
485 live
.insert(live_vars
.live_out
[block
.index
].begin(), live_vars
.live_out
[block
.index
].end());
486 /* remove killed p_phi sgpr operands */
487 for (Temp tmp
: phi_sgpr_ops
[block
.index
])
491 for (Temp tmp
: live
) {
492 PhysReg reg
= assignments
.at(tmp
.id()).reg
;
493 for (unsigned i
= 0; i
< tmp
.size(); i
++) {
495 err
|= ra_fail(output
, loc
, Location(), "Assignment of element %d of %%%d already taken by %%%d in live-out", i
, tmp
.id(), regs
[reg
+ i
]);
497 regs
[reg
+ i
] = tmp
.id();
502 for (auto it
= block
.instructions
.rbegin(); it
!= block
.instructions
.rend(); ++it
) {
503 aco_ptr
<Instruction
>& instr
= *it
;
505 /* check killed p_phi sgpr operands */
506 if (instr
->opcode
== aco_opcode::p_logical_end
) {
507 for (Temp tmp
: phi_sgpr_ops
[block
.index
]) {
508 PhysReg reg
= assignments
.at(tmp
.id()).reg
;
509 for (unsigned i
= 0; i
< tmp
.size(); i
++) {
511 err
|= ra_fail(output
, loc
, Location(), "Assignment of element %d of %%%d already taken by %%%d in live-out", i
, tmp
.id(), regs
[reg
+ i
]);
517 for (const Definition
& def
: instr
->definitions
) {
520 live
.erase(def
.getTemp());
523 /* don't count phi operands as live-in, since they are actually
524 * killed when they are copied at the predecessor */
525 if (instr
->opcode
!= aco_opcode::p_phi
&& instr
->opcode
!= aco_opcode::p_linear_phi
) {
526 for (const Operand
& op
: instr
->operands
) {
529 live
.insert(op
.getTemp());
534 for (Temp tmp
: live
) {
535 PhysReg reg
= assignments
.at(tmp
.id()).reg
;
536 for (unsigned i
= 0; i
< tmp
.size(); i
++)
537 regs
[reg
+ i
] = tmp
.id();
540 for (aco_ptr
<Instruction
>& instr
: block
.instructions
) {
541 loc
.instr
= instr
.get();
543 /* remove killed p_phi operands from regs */
544 if (instr
->opcode
== aco_opcode::p_logical_end
) {
545 for (Temp tmp
: phi_sgpr_ops
[block
.index
]) {
546 PhysReg reg
= assignments
.at(tmp
.id()).reg
;
551 if (instr
->opcode
!= aco_opcode::p_phi
&& instr
->opcode
!= aco_opcode::p_linear_phi
) {
552 for (const Operand
& op
: instr
->operands
) {
555 if (op
.isFirstKillBeforeDef()) {
556 for (unsigned j
= 0; j
< op
.getTemp().size(); j
++)
557 regs
[op
.physReg() + j
] = 0;
562 for (unsigned i
= 0; i
< instr
->definitions
.size(); i
++) {
563 Definition
& def
= instr
->definitions
[i
];
566 Temp tmp
= def
.getTemp();
567 PhysReg reg
= assignments
.at(tmp
.id()).reg
;
568 for (unsigned j
= 0; j
< tmp
.size(); j
++) {
570 err
|= ra_fail(output
, loc
, assignments
.at(regs
[reg
+ i
]).defloc
, "Assignment of element %d of %%%d already taken by %%%d from instruction", i
, tmp
.id(), regs
[reg
+ j
]);
571 regs
[reg
+ j
] = tmp
.id();
575 for (const Definition
& def
: instr
->definitions
) {
579 for (unsigned j
= 0; j
< def
.getTemp().size(); j
++)
580 regs
[def
.physReg() + j
] = 0;
584 if (instr
->opcode
!= aco_opcode::p_phi
&& instr
->opcode
!= aco_opcode::p_linear_phi
) {
585 for (const Operand
& op
: instr
->operands
) {
588 if (op
.isLateKill() && op
.isFirstKill()) {
589 for (unsigned j
= 0; j
< op
.getTemp().size(); j
++)
590 regs
[op
.physReg() + j
] = 0;