2 * Copyright © 2019 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
26 #include "aco_builder.h"
32 enum WQMState
: uint8_t {
35 WQM
= 1 << 1, /* with control flow applied */
36 Preserve_WQM
= 1 << 2,
37 Exact_Branch
= 1 << 3,
40 enum mask_type
: uint8_t {
41 mask_type_global
= 1 << 0,
42 mask_type_exact
= 1 << 1,
43 mask_type_wqm
= 1 << 2,
44 mask_type_loop
= 1 << 3, /* active lanes of a loop */
45 mask_type_initial
= 1 << 4, /* initially active lanes */
50 /* state for WQM propagation */
51 std::set
<unsigned> worklist
;
52 std::vector
<uint16_t> defined_in
;
53 std::vector
<bool> needs_wqm
;
54 std::vector
<bool> branch_wqm
; /* true if the branch condition in this block should be in wqm */
57 wqm_ctx(Program
* program
) : program(program
),
58 defined_in(program
->peekAllocationId(), 0xFFFF),
59 needs_wqm(program
->peekAllocationId()),
60 branch_wqm(program
->blocks
.size()),
64 for (unsigned i
= 0; i
< program
->blocks
.size(); i
++)
71 uint16_t num_exec_masks
;
73 bool has_divergent_break
;
74 bool has_divergent_continue
;
75 bool has_discard
; /* has a discard or demote */
76 loop_info(Block
* b
, uint16_t num
, uint8_t needs
, bool breaks
, bool cont
, bool discard
) :
77 loop_header(b
), num_exec_masks(num
), needs(needs
), has_divergent_break(breaks
),
78 has_divergent_continue(cont
), has_discard(discard
) {}
82 std::vector
<std::pair
<Temp
, uint8_t>> exec
;
83 std::vector
<WQMState
> instr_needs
;
85 uint8_t ever_again_needs
;
91 std::vector
<block_info
> info
;
92 std::vector
<loop_info
> loop
;
93 bool handle_wqm
= false;
94 exec_ctx(Program
*program
) : program(program
), info(program
->blocks
.size()) {}
97 bool pred_by_exec_mask(aco_ptr
<Instruction
>& instr
) {
99 return instr
->reads_exec();
100 if (instr
->format
== Format::SMEM
|| instr
->isSALU())
102 if (instr
->format
== Format::PSEUDO_BARRIER
)
105 if (instr
->format
== Format::PSEUDO
) {
106 switch (instr
->opcode
) {
107 case aco_opcode::p_create_vector
:
108 return instr
->definitions
[0].getTemp().type() == RegType::vgpr
;
109 case aco_opcode::p_extract_vector
:
110 case aco_opcode::p_split_vector
:
111 return instr
->operands
[0].getTemp().type() == RegType::vgpr
;
112 case aco_opcode::p_spill
:
113 case aco_opcode::p_reload
:
120 if (instr
->opcode
== aco_opcode::v_readlane_b32
||
121 instr
->opcode
== aco_opcode::v_writelane_b32
)
127 bool needs_exact(aco_ptr
<Instruction
>& instr
) {
128 if (instr
->format
== Format::MUBUF
) {
129 MUBUF_instruction
*mubuf
= static_cast<MUBUF_instruction
*>(instr
.get());
130 return mubuf
->disable_wqm
;
131 } else if (instr
->format
== Format::MTBUF
) {
132 MTBUF_instruction
*mtbuf
= static_cast<MTBUF_instruction
*>(instr
.get());
133 return mtbuf
->disable_wqm
;
134 } else if (instr
->format
== Format::MIMG
) {
135 MIMG_instruction
*mimg
= static_cast<MIMG_instruction
*>(instr
.get());
136 return mimg
->disable_wqm
;
138 return instr
->format
== Format::EXP
|| instr
->opcode
== aco_opcode::p_fs_buffer_store_smem
;
142 void set_needs_wqm(wqm_ctx
&ctx
, Temp tmp
)
144 if (!ctx
.needs_wqm
[tmp
.id()]) {
145 ctx
.needs_wqm
[tmp
.id()] = true;
146 if (ctx
.defined_in
[tmp
.id()] != 0xFFFF)
147 ctx
.worklist
.insert(ctx
.defined_in
[tmp
.id()]);
151 void mark_block_wqm(wqm_ctx
&ctx
, unsigned block_idx
)
153 if (ctx
.branch_wqm
[block_idx
])
156 ctx
.branch_wqm
[block_idx
] = true;
157 Block
& block
= ctx
.program
->blocks
[block_idx
];
158 aco_ptr
<Instruction
>& branch
= block
.instructions
.back();
160 if (branch
->opcode
!= aco_opcode::p_branch
) {
161 assert(!branch
->operands
.empty() && branch
->operands
[0].isTemp());
162 set_needs_wqm(ctx
, branch
->operands
[0].getTemp());
165 /* TODO: this sets more branch conditions to WQM than it needs to
166 * it should be enough to stop at the "exec mask top level" */
167 if (block
.kind
& block_kind_top_level
)
170 for (unsigned pred_idx
: block
.logical_preds
)
171 mark_block_wqm(ctx
, pred_idx
);
174 void get_block_needs(wqm_ctx
&ctx
, exec_ctx
&exec_ctx
, Block
* block
)
176 block_info
& info
= exec_ctx
.info
[block
->index
];
178 std::vector
<WQMState
> instr_needs(block
->instructions
.size());
180 if (block
->kind
& block_kind_top_level
) {
181 if (ctx
.loop
&& ctx
.wqm
) {
182 /* mark all break conditions as WQM */
183 unsigned block_idx
= block
->index
+ 1;
184 while (!(ctx
.program
->blocks
[block_idx
].kind
& block_kind_top_level
)) {
185 if (ctx
.program
->blocks
[block_idx
].kind
& block_kind_break
)
186 mark_block_wqm(ctx
, block_idx
);
189 } else if (ctx
.loop
&& !ctx
.wqm
) {
190 /* Ensure a branch never results in an exec mask with only helper
191 * invocations (which can cause a loop to repeat infinitively if it's
192 * break branches are done in exact). */
193 unsigned block_idx
= block
->index
;
195 if ((ctx
.program
->blocks
[block_idx
].kind
& block_kind_branch
))
196 exec_ctx
.info
[block_idx
].block_needs
|= Exact_Branch
;
198 } while (!(ctx
.program
->blocks
[block_idx
].kind
& block_kind_top_level
));
205 for (int i
= block
->instructions
.size() - 1; i
>= 0; --i
) {
206 aco_ptr
<Instruction
>& instr
= block
->instructions
[i
];
208 WQMState needs
= needs_exact(instr
) ? Exact
: Unspecified
;
209 bool propagate_wqm
= instr
->opcode
== aco_opcode::p_wqm
;
210 bool preserve_wqm
= instr
->opcode
== aco_opcode::p_discard_if
;
211 bool pred_by_exec
= pred_by_exec_mask(instr
);
212 for (const Definition
& definition
: instr
->definitions
) {
213 if (!definition
.isTemp())
215 const unsigned def
= definition
.tempId();
216 ctx
.defined_in
[def
] = block
->index
;
217 if (needs
== Unspecified
&& ctx
.needs_wqm
[def
]) {
218 needs
= pred_by_exec
? WQM
: Unspecified
;
219 propagate_wqm
= true;
224 for (const Operand
& op
: instr
->operands
) {
226 set_needs_wqm(ctx
, op
.getTemp());
229 } else if (preserve_wqm
&& info
.block_needs
& WQM
) {
230 needs
= Preserve_WQM
;
233 /* ensure the condition controlling the control flow for this phi is in WQM */
234 if (needs
== WQM
&& instr
->opcode
== aco_opcode::p_phi
) {
235 for (unsigned pred_idx
: block
->logical_preds
)
236 mark_block_wqm(ctx
, pred_idx
);
239 instr_needs
[i
] = needs
;
240 info
.block_needs
|= needs
;
243 info
.instr_needs
= instr_needs
;
245 /* for "if (<cond>) <wqm code>" or "while (<cond>) <wqm code>",
246 * <cond> should be computed in WQM */
247 if (info
.block_needs
& WQM
&& !(block
->kind
& block_kind_top_level
)) {
248 for (unsigned pred_idx
: block
->logical_preds
)
249 mark_block_wqm(ctx
, pred_idx
);
252 if (block
->kind
& block_kind_loop_header
)
256 void calculate_wqm_needs(exec_ctx
& exec_ctx
)
258 wqm_ctx
ctx(exec_ctx
.program
);
260 while (!ctx
.worklist
.empty()) {
261 unsigned block_index
= *std::prev(ctx
.worklist
.end());
262 ctx
.worklist
.erase(std::prev(ctx
.worklist
.end()));
264 get_block_needs(ctx
, exec_ctx
, &exec_ctx
.program
->blocks
[block_index
]);
267 uint8_t ever_again_needs
= 0;
268 for (int i
= exec_ctx
.program
->blocks
.size() - 1; i
>= 0; i
--) {
269 exec_ctx
.info
[i
].ever_again_needs
= ever_again_needs
;
270 Block
& block
= exec_ctx
.program
->blocks
[i
];
272 if (block
.kind
& block_kind_needs_lowering
)
273 exec_ctx
.info
[i
].block_needs
|= Exact
;
275 /* if discard is used somewhere in nested CF, we need to preserve the WQM mask */
276 if ((block
.kind
& block_kind_discard
||
277 block
.kind
& block_kind_uses_discard_if
) &&
278 ever_again_needs
& WQM
)
279 exec_ctx
.info
[i
].block_needs
|= Preserve_WQM
;
281 ever_again_needs
|= exec_ctx
.info
[i
].block_needs
& ~Exact_Branch
;
282 if (block
.kind
& block_kind_discard
||
283 block
.kind
& block_kind_uses_discard_if
||
284 block
.kind
& block_kind_uses_demote
)
285 ever_again_needs
|= Exact
;
287 /* don't propagate WQM preservation further than the next top_level block */
288 if (block
.kind
& block_kind_top_level
)
289 ever_again_needs
&= ~Preserve_WQM
;
291 exec_ctx
.info
[i
].block_needs
&= ~Preserve_WQM
;
293 exec_ctx
.handle_wqm
= true;
296 void transition_to_WQM(exec_ctx
& ctx
, Builder bld
, unsigned idx
)
298 if (ctx
.info
[idx
].exec
.back().second
& mask_type_wqm
)
300 if (ctx
.info
[idx
].exec
.back().second
& mask_type_global
) {
301 Temp exec_mask
= ctx
.info
[idx
].exec
.back().first
;
302 exec_mask
= bld
.sop1(aco_opcode::s_wqm_b64
, bld
.def(s2
, exec
), bld
.def(s1
, scc
), exec_mask
);
303 ctx
.info
[idx
].exec
.emplace_back(exec_mask
, mask_type_global
| mask_type_wqm
);
306 /* otherwise, the WQM mask should be one below the current mask */
307 ctx
.info
[idx
].exec
.pop_back();
308 assert(ctx
.info
[idx
].exec
.back().second
& mask_type_wqm
);
309 ctx
.info
[idx
].exec
.back().first
= bld
.pseudo(aco_opcode::p_parallelcopy
, bld
.def(s2
, exec
),
310 ctx
.info
[idx
].exec
.back().first
);
313 void transition_to_Exact(exec_ctx
& ctx
, Builder bld
, unsigned idx
)
315 if (ctx
.info
[idx
].exec
.back().second
& mask_type_exact
)
317 /* We can't remove the loop exec mask, because that can cause exec.size() to
318 * be less than num_exec_masks. The loop exec mask also needs to be kept
319 * around for various uses. */
320 if ((ctx
.info
[idx
].exec
.back().second
& mask_type_global
) &&
321 !(ctx
.info
[idx
].exec
.back().second
& mask_type_loop
)) {
322 ctx
.info
[idx
].exec
.pop_back();
323 assert(ctx
.info
[idx
].exec
.back().second
& mask_type_exact
);
324 ctx
.info
[idx
].exec
.back().first
= bld
.pseudo(aco_opcode::p_parallelcopy
, bld
.def(s2
, exec
),
325 ctx
.info
[idx
].exec
.back().first
);
328 /* otherwise, we create an exact mask and push to the stack */
329 Temp wqm
= ctx
.info
[idx
].exec
.back().first
;
330 Temp exact
= bld
.tmp(s2
);
331 wqm
= bld
.sop1(aco_opcode::s_and_saveexec_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
332 bld
.exec(Definition(exact
)), ctx
.info
[idx
].exec
[0].first
, bld
.exec(wqm
));
333 ctx
.info
[idx
].exec
.back().first
= wqm
;
334 ctx
.info
[idx
].exec
.emplace_back(exact
, mask_type_exact
);
337 unsigned add_coupling_code(exec_ctx
& ctx
, Block
* block
,
338 std::vector
<aco_ptr
<Instruction
>>& instructions
)
340 unsigned idx
= block
->index
;
341 Builder
bld(ctx
.program
, &instructions
);
342 std::vector
<unsigned>& preds
= block
->linear_preds
;
346 aco_ptr
<Instruction
>& startpgm
= block
->instructions
[0];
347 assert(startpgm
->opcode
== aco_opcode::p_startpgm
);
348 Temp exec_mask
= startpgm
->definitions
.back().getTemp();
349 bld
.insert(std::move(startpgm
));
351 if (ctx
.handle_wqm
) {
352 ctx
.info
[0].exec
.emplace_back(exec_mask
, mask_type_global
| mask_type_exact
| mask_type_initial
);
353 /* if this block only needs WQM, initialize already */
354 if (ctx
.info
[0].block_needs
== WQM
)
355 transition_to_WQM(ctx
, bld
, 0);
357 uint8_t mask
= mask_type_global
;
358 if (ctx
.program
->needs_wqm
) {
359 exec_mask
= bld
.sop1(aco_opcode::s_wqm_b64
, bld
.def(s2
, exec
), bld
.def(s1
, scc
), bld
.exec(exec_mask
));
360 mask
|= mask_type_wqm
;
362 mask
|= mask_type_exact
;
364 ctx
.info
[0].exec
.emplace_back(exec_mask
, mask
);
370 /* loop entry block */
371 if (block
->kind
& block_kind_loop_header
) {
372 assert(preds
[0] == idx
- 1);
373 ctx
.info
[idx
].exec
= ctx
.info
[idx
- 1].exec
;
374 loop_info
& info
= ctx
.loop
.back();
375 while (ctx
.info
[idx
].exec
.size() > info
.num_exec_masks
)
376 ctx
.info
[idx
].exec
.pop_back();
378 /* create ssa names for outer exec masks */
379 if (info
.has_discard
) {
380 aco_ptr
<Pseudo_instruction
> phi
;
381 for (int i
= 0; i
< info
.num_exec_masks
- 1; i
++) {
382 phi
.reset(create_instruction
<Pseudo_instruction
>(aco_opcode::p_linear_phi
, Format::PSEUDO
, preds
.size(), 1));
383 phi
->definitions
[0] = bld
.def(s2
);
384 phi
->operands
[0] = Operand(ctx
.info
[preds
[0]].exec
[i
].first
);
385 ctx
.info
[idx
].exec
[i
].first
= bld
.insert(std::move(phi
));
389 /* create ssa name for restore mask */
390 if (info
.has_divergent_break
) {
391 /* this phi might be trivial but ensures a parallelcopy on the loop header */
392 aco_ptr
<Pseudo_instruction
> phi
{create_instruction
<Pseudo_instruction
>(aco_opcode::p_linear_phi
, Format::PSEUDO
, preds
.size(), 1)};
393 phi
->definitions
[0] = bld
.def(s2
);
394 phi
->operands
[0] = Operand(ctx
.info
[preds
[0]].exec
[info
.num_exec_masks
- 1].first
);
395 ctx
.info
[idx
].exec
.back().first
= bld
.insert(std::move(phi
));
398 /* create ssa name for loop active mask */
399 aco_ptr
<Pseudo_instruction
> phi
{create_instruction
<Pseudo_instruction
>(aco_opcode::p_linear_phi
, Format::PSEUDO
, preds
.size(), 1)};
400 if (info
.has_divergent_continue
)
401 phi
->definitions
[0] = bld
.def(s2
);
403 phi
->definitions
[0] = bld
.def(s2
, exec
);
404 phi
->operands
[0] = Operand(ctx
.info
[preds
[0]].exec
.back().first
);
405 Temp loop_active
= bld
.insert(std::move(phi
));
407 if (info
.has_divergent_break
) {
408 uint8_t mask_type
= (ctx
.info
[idx
].exec
.back().second
& (mask_type_wqm
| mask_type_exact
)) | mask_type_loop
;
409 ctx
.info
[idx
].exec
.emplace_back(loop_active
, mask_type
);
411 ctx
.info
[idx
].exec
.back().first
= loop_active
;
412 ctx
.info
[idx
].exec
.back().second
|= mask_type_loop
;
415 /* create a parallelcopy to move the active mask to exec */
417 if (info
.has_divergent_continue
) {
418 while (block
->instructions
[i
]->opcode
!= aco_opcode::p_logical_start
) {
419 bld
.insert(std::move(block
->instructions
[i
]));
422 uint8_t mask_type
= ctx
.info
[idx
].exec
.back().second
& (mask_type_wqm
| mask_type_exact
);
423 ctx
.info
[idx
].exec
.emplace_back(bld
.pseudo(aco_opcode::p_parallelcopy
, bld
.def(s2
, exec
),
424 ctx
.info
[idx
].exec
.back().first
), mask_type
);
430 /* loop exit block */
431 if (block
->kind
& block_kind_loop_exit
) {
432 Block
* header
= ctx
.loop
.back().loop_header
;
433 loop_info
& info
= ctx
.loop
.back();
435 for (ASSERTED
unsigned pred
: preds
)
436 assert(ctx
.info
[pred
].exec
.size() >= info
.num_exec_masks
);
438 /* fill the loop header phis */
439 std::vector
<unsigned>& header_preds
= header
->linear_preds
;
441 if (info
.has_discard
) {
442 while (k
< info
.num_exec_masks
- 1) {
443 aco_ptr
<Instruction
>& phi
= header
->instructions
[k
];
444 assert(phi
->opcode
== aco_opcode::p_linear_phi
);
445 for (unsigned i
= 1; i
< phi
->operands
.size(); i
++)
446 phi
->operands
[i
] = Operand(ctx
.info
[header_preds
[i
]].exec
[k
].first
);
450 aco_ptr
<Instruction
>& phi
= header
->instructions
[k
++];
451 assert(phi
->opcode
== aco_opcode::p_linear_phi
);
452 for (unsigned i
= 1; i
< phi
->operands
.size(); i
++)
453 phi
->operands
[i
] = Operand(ctx
.info
[header_preds
[i
]].exec
[info
.num_exec_masks
- 1].first
);
455 if (info
.has_divergent_break
) {
456 aco_ptr
<Instruction
>& phi
= header
->instructions
[k
];
457 assert(phi
->opcode
== aco_opcode::p_linear_phi
);
458 for (unsigned i
= 1; i
< phi
->operands
.size(); i
++)
459 phi
->operands
[i
] = Operand(ctx
.info
[header_preds
[i
]].exec
[info
.num_exec_masks
].first
);
462 assert(!(block
->kind
& block_kind_top_level
) || info
.num_exec_masks
<= 2);
464 /* create the loop exit phis if not trivial */
465 for (unsigned k
= 0; k
< info
.num_exec_masks
; k
++) {
466 Temp same
= ctx
.info
[preds
[0]].exec
[k
].first
;
467 uint8_t type
= ctx
.info
[header_preds
[0]].exec
[k
].second
;
470 for (unsigned i
= 1; i
< preds
.size() && trivial
; i
++) {
471 if (ctx
.info
[preds
[i
]].exec
[k
].first
!= same
)
476 ctx
.info
[idx
].exec
.emplace_back(same
, type
);
478 /* create phi for loop footer */
479 aco_ptr
<Pseudo_instruction
> phi
{create_instruction
<Pseudo_instruction
>(aco_opcode::p_linear_phi
, Format::PSEUDO
, preds
.size(), 1)};
480 phi
->definitions
[0] = bld
.def(s2
);
481 for (unsigned i
= 0; i
< phi
->operands
.size(); i
++)
482 phi
->operands
[i
] = Operand(ctx
.info
[preds
[i
]].exec
[k
].first
);
483 ctx
.info
[idx
].exec
.emplace_back(bld
.insert(std::move(phi
)), type
);
486 assert(ctx
.info
[idx
].exec
.size() == info
.num_exec_masks
);
488 /* create a parallelcopy to move the live mask to exec */
490 while (block
->instructions
[i
]->opcode
!= aco_opcode::p_logical_start
) {
491 bld
.insert(std::move(block
->instructions
[i
]));
495 if (ctx
.handle_wqm
) {
496 if (block
->kind
& block_kind_top_level
&& ctx
.info
[idx
].exec
.size() == 2) {
497 if ((ctx
.info
[idx
].block_needs
| ctx
.info
[idx
].ever_again_needs
) == 0 ||
498 (ctx
.info
[idx
].block_needs
| ctx
.info
[idx
].ever_again_needs
) == Exact
) {
499 ctx
.info
[idx
].exec
.back().second
|= mask_type_global
;
500 transition_to_Exact(ctx
, bld
, idx
);
501 ctx
.handle_wqm
= false;
504 if (ctx
.info
[idx
].block_needs
== WQM
)
505 transition_to_WQM(ctx
, bld
, idx
);
506 else if (ctx
.info
[idx
].block_needs
== Exact
)
507 transition_to_Exact(ctx
, bld
, idx
);
510 ctx
.info
[idx
].exec
.back().first
= bld
.pseudo(aco_opcode::p_parallelcopy
, bld
.def(s2
, exec
),
511 ctx
.info
[idx
].exec
.back().first
);
517 if (preds
.size() == 1) {
518 ctx
.info
[idx
].exec
= ctx
.info
[preds
[0]].exec
;
520 assert(preds
.size() == 2);
521 /* if one of the predecessors ends in exact mask, we pop it from stack */
522 unsigned num_exec_masks
= std::min(ctx
.info
[preds
[0]].exec
.size(),
523 ctx
.info
[preds
[1]].exec
.size());
524 if (block
->kind
& block_kind_top_level
&& !(block
->kind
& block_kind_merge
))
525 num_exec_masks
= std::min(num_exec_masks
, 2u);
527 /* create phis for diverged exec masks */
528 for (unsigned i
= 0; i
< num_exec_masks
; i
++) {
529 bool in_exec
= i
== num_exec_masks
- 1 && !(block
->kind
& block_kind_merge
);
530 if (!in_exec
&& ctx
.info
[preds
[0]].exec
[i
].first
== ctx
.info
[preds
[1]].exec
[i
].first
) {
531 assert(ctx
.info
[preds
[0]].exec
[i
].second
== ctx
.info
[preds
[1]].exec
[i
].second
);
532 ctx
.info
[idx
].exec
.emplace_back(ctx
.info
[preds
[0]].exec
[i
]);
536 Temp phi
= bld
.pseudo(aco_opcode::p_linear_phi
, in_exec
? bld
.def(s2
, exec
) : bld
.def(s2
),
537 ctx
.info
[preds
[0]].exec
[i
].first
,
538 ctx
.info
[preds
[1]].exec
[i
].first
);
539 uint8_t mask_type
= ctx
.info
[preds
[0]].exec
[i
].second
& ctx
.info
[preds
[1]].exec
[i
].second
;
540 ctx
.info
[idx
].exec
.emplace_back(phi
, mask_type
);
545 while (block
->instructions
[i
]->opcode
== aco_opcode::p_phi
||
546 block
->instructions
[i
]->opcode
== aco_opcode::p_linear_phi
) {
547 bld
.insert(std::move(block
->instructions
[i
]));
551 if (block
->kind
& block_kind_merge
)
552 ctx
.info
[idx
].exec
.pop_back();
554 if (block
->kind
& block_kind_top_level
&& ctx
.info
[idx
].exec
.size() == 3) {
555 assert(ctx
.info
[idx
].exec
.back().second
== mask_type_exact
);
556 assert(block
->kind
& block_kind_merge
);
557 ctx
.info
[idx
].exec
.pop_back();
560 /* try to satisfy the block's needs */
561 if (ctx
.handle_wqm
) {
562 if (block
->kind
& block_kind_top_level
&& ctx
.info
[idx
].exec
.size() == 2) {
563 if ((ctx
.info
[idx
].block_needs
| ctx
.info
[idx
].ever_again_needs
) == 0 ||
564 (ctx
.info
[idx
].block_needs
| ctx
.info
[idx
].ever_again_needs
) == Exact
) {
565 ctx
.info
[idx
].exec
.back().second
|= mask_type_global
;
566 transition_to_Exact(ctx
, bld
, idx
);
567 ctx
.handle_wqm
= false;
570 if (ctx
.info
[idx
].block_needs
== WQM
)
571 transition_to_WQM(ctx
, bld
, idx
);
572 else if (ctx
.info
[idx
].block_needs
== Exact
)
573 transition_to_Exact(ctx
, bld
, idx
);
576 if (block
->kind
& block_kind_merge
) {
577 Temp restore
= ctx
.info
[idx
].exec
.back().first
;
578 ctx
.info
[idx
].exec
.back().first
= bld
.pseudo(aco_opcode::p_parallelcopy
, bld
.def(s2
, exec
), restore
);
584 void lower_fs_buffer_store_smem(Builder
& bld
, bool need_check
, aco_ptr
<Instruction
>& instr
, Temp cur_exec
)
586 Operand offset
= instr
->operands
[1];
588 /* if exec is zero, then use UINT32_MAX as an offset and make this store a no-op */
589 Temp nonempty
= bld
.sopc(aco_opcode::s_cmp_lg_u64
, bld
.def(s1
, scc
), cur_exec
, Operand(0u));
591 if (offset
.isLiteral())
592 offset
= bld
.sop1(aco_opcode::s_mov_b32
, bld
.def(s1
), offset
);
594 offset
= bld
.sop2(aco_opcode::s_cselect_b32
, bld
.hint_m0(bld
.def(s1
)),
595 offset
, Operand(UINT32_MAX
), bld
.scc(nonempty
));
596 } else if (offset
.isConstant() && offset
.constantValue() > 0xFFFFF) {
597 offset
= bld
.sop1(aco_opcode::s_mov_b32
, bld
.hint_m0(bld
.def(s1
)), offset
);
599 if (!offset
.isConstant())
602 switch (instr
->operands
[2].size()) {
604 instr
->opcode
= aco_opcode::s_buffer_store_dword
;
607 instr
->opcode
= aco_opcode::s_buffer_store_dwordx2
;
610 instr
->opcode
= aco_opcode::s_buffer_store_dwordx4
;
613 unreachable("Invalid SMEM buffer store size");
615 instr
->operands
[1] = offset
;
616 /* as_uniform() needs to be done here so it's done in exact mode and helper
617 * lanes don't contribute. */
618 instr
->operands
[2] = Operand(bld
.as_uniform(instr
->operands
[2]));
621 void process_instructions(exec_ctx
& ctx
, Block
* block
,
622 std::vector
<aco_ptr
<Instruction
>>& instructions
,
626 if (ctx
.info
[block
->index
].exec
.back().second
& mask_type_wqm
)
629 assert(!ctx
.handle_wqm
|| ctx
.info
[block
->index
].exec
.back().second
& mask_type_exact
);
633 /* if the block doesn't need both, WQM and Exact, we can skip processing the instructions */
634 bool process
= (ctx
.handle_wqm
&&
635 (ctx
.info
[block
->index
].block_needs
& state
) !=
636 (ctx
.info
[block
->index
].block_needs
& (WQM
| Exact
))) ||
637 block
->kind
& block_kind_uses_discard_if
||
638 block
->kind
& block_kind_uses_demote
||
639 block
->kind
& block_kind_needs_lowering
;
641 std::vector
<aco_ptr
<Instruction
>>::iterator it
= std::next(block
->instructions
.begin(), idx
);
642 instructions
.insert(instructions
.end(),
643 std::move_iterator
<std::vector
<aco_ptr
<Instruction
>>::iterator
>(it
),
644 std::move_iterator
<std::vector
<aco_ptr
<Instruction
>>::iterator
>(block
->instructions
.end()));
648 Builder
bld(ctx
.program
, &instructions
);
650 for (; idx
< block
->instructions
.size(); idx
++) {
651 aco_ptr
<Instruction
> instr
= std::move(block
->instructions
[idx
]);
653 WQMState needs
= ctx
.handle_wqm
? ctx
.info
[block
->index
].instr_needs
[idx
] : Unspecified
;
655 if (instr
->opcode
== aco_opcode::p_discard_if
) {
656 if (ctx
.info
[block
->index
].block_needs
& Preserve_WQM
) {
657 assert(block
->kind
& block_kind_top_level
);
658 transition_to_WQM(ctx
, bld
, block
->index
);
659 ctx
.info
[block
->index
].exec
.back().second
&= ~mask_type_global
;
661 int num
= ctx
.info
[block
->index
].exec
.size();
663 Operand cond
= instr
->operands
[0];
664 for (int i
= num
- 1; i
>= 0; i
--) {
665 Instruction
*andn2
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
666 ctx
.info
[block
->index
].exec
[i
].first
, cond
);
668 andn2
->operands
[0].setFixed(exec
);
669 andn2
->definitions
[0].setFixed(exec
);
672 instr
->opcode
= aco_opcode::p_exit_early_if
;
673 instr
->operands
[0] = bld
.scc(andn2
->definitions
[1].getTemp());
675 ctx
.info
[block
->index
].exec
[i
].first
= andn2
->definitions
[0].getTemp();
677 assert(!ctx
.handle_wqm
|| (ctx
.info
[block
->index
].exec
[0].second
& mask_type_wqm
) == 0);
679 } else if (needs
== WQM
&& state
!= WQM
) {
680 transition_to_WQM(ctx
, bld
, block
->index
);
682 } else if (needs
== Exact
&& state
!= Exact
) {
683 transition_to_Exact(ctx
, bld
, block
->index
);
687 if (instr
->opcode
== aco_opcode::p_is_helper
|| instr
->opcode
== aco_opcode::p_load_helper
) {
688 Definition dst
= instr
->definitions
[0];
689 if (state
== Exact
) {
690 instr
.reset(create_instruction
<SOP1_instruction
>(aco_opcode::s_mov_b64
, Format::SOP1
, 1, 1));
691 instr
->operands
[0] = Operand(0u);
692 instr
->definitions
[0] = dst
;
694 std::pair
<Temp
, uint8_t>& exact_mask
= ctx
.info
[block
->index
].exec
[0];
695 if (instr
->opcode
== aco_opcode::p_load_helper
&&
696 !(ctx
.info
[block
->index
].exec
[0].second
& mask_type_initial
)) {
697 /* find last initial exact mask */
698 for (int i
= block
->index
; i
>= 0; i
--) {
699 if (ctx
.program
->blocks
[i
].kind
& block_kind_top_level
&&
700 ctx
.info
[i
].exec
[0].second
& mask_type_initial
) {
701 exact_mask
= ctx
.info
[i
].exec
[0];
707 assert(instr
->opcode
== aco_opcode::p_is_helper
|| exact_mask
.second
& mask_type_initial
);
708 assert(exact_mask
.second
& mask_type_exact
);
710 instr
.reset(create_instruction
<SOP2_instruction
>(aco_opcode::s_andn2_b64
, Format::SOP2
, 2, 2));
711 instr
->operands
[0] = Operand(ctx
.info
[block
->index
].exec
.back().first
); /* current exec */
712 instr
->operands
[1] = Operand(exact_mask
.first
);
713 instr
->definitions
[0] = dst
;
714 instr
->definitions
[1] = bld
.def(s1
, scc
);
716 } else if (instr
->opcode
== aco_opcode::p_demote_to_helper
) {
717 /* turn demote into discard_if with only exact masks */
718 assert((ctx
.info
[block
->index
].exec
[0].second
& (mask_type_exact
| mask_type_global
)) == (mask_type_exact
| mask_type_global
));
719 ctx
.info
[block
->index
].exec
[0].second
&= ~mask_type_initial
;
723 if (instr
->operands
.empty()) {
724 /* transition to exact and set exec to zero */
725 Temp old_exec
= ctx
.info
[block
->index
].exec
.back().first
;
726 Temp new_exec
= bld
.tmp(s2
);
727 cond
= bld
.sop1(aco_opcode::s_and_saveexec_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
728 bld
.exec(Definition(new_exec
)), Operand(0u), bld
.exec(old_exec
));
729 if (ctx
.info
[block
->index
].exec
.back().second
& mask_type_exact
) {
730 ctx
.info
[block
->index
].exec
.back().first
= new_exec
;
732 ctx
.info
[block
->index
].exec
.back().first
= cond
;
733 ctx
.info
[block
->index
].exec
.emplace_back(new_exec
, mask_type_exact
);
736 /* demote_if: transition to exact */
737 transition_to_Exact(ctx
, bld
, block
->index
);
738 assert(instr
->operands
[0].isTemp());
739 cond
= instr
->operands
[0].getTemp();
743 num
+= ctx
.info
[block
->index
].exec
.size() - 1;
744 for (int i
= num
- 1; i
>= 0; i
--) {
745 if (ctx
.info
[block
->index
].exec
[i
].second
& mask_type_exact
) {
746 Instruction
*andn2
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
747 ctx
.info
[block
->index
].exec
[i
].first
, cond
);
749 andn2
->operands
[0].setFixed(exec
);
750 andn2
->definitions
[0].setFixed(exec
);
753 instr
->opcode
= aco_opcode::p_exit_early_if
;
754 instr
->operands
[0] = bld
.scc(andn2
->definitions
[1].getTemp());
756 ctx
.info
[block
->index
].exec
[i
].first
= andn2
->definitions
[0].getTemp();
763 } else if (instr
->opcode
== aco_opcode::p_fs_buffer_store_smem
) {
764 bool need_check
= ctx
.info
[block
->index
].exec
.size() != 1 &&
765 !(ctx
.info
[block
->index
].exec
[ctx
.info
[block
->index
].exec
.size() - 2].second
& Exact
);
766 lower_fs_buffer_store_smem(bld
, need_check
, instr
, ctx
.info
[block
->index
].exec
.back().first
);
769 bld
.insert(std::move(instr
));
773 void add_branch_code(exec_ctx
& ctx
, Block
* block
)
775 unsigned idx
= block
->index
;
776 Builder
bld(ctx
.program
, block
);
778 if (idx
== ctx
.program
->blocks
.size() - 1)
781 /* try to disable wqm handling */
782 if (ctx
.handle_wqm
&& block
->kind
& block_kind_top_level
) {
783 if (ctx
.info
[idx
].exec
.size() == 3) {
784 assert(ctx
.info
[idx
].exec
[1].second
== mask_type_wqm
);
785 ctx
.info
[idx
].exec
.pop_back();
787 assert(ctx
.info
[idx
].exec
.size() <= 2);
789 if (ctx
.info
[idx
].ever_again_needs
== 0 ||
790 ctx
.info
[idx
].ever_again_needs
== Exact
) {
791 /* transition to Exact */
792 aco_ptr
<Instruction
> branch
= std::move(block
->instructions
.back());
793 block
->instructions
.pop_back();
794 ctx
.info
[idx
].exec
.back().second
|= mask_type_global
;
795 transition_to_Exact(ctx
, bld
, idx
);
796 bld
.insert(std::move(branch
));
797 ctx
.handle_wqm
= false;
799 } else if (ctx
.info
[idx
].block_needs
& Preserve_WQM
) {
800 /* transition to WQM and remove global flag */
801 aco_ptr
<Instruction
> branch
= std::move(block
->instructions
.back());
802 block
->instructions
.pop_back();
803 transition_to_WQM(ctx
, bld
, idx
);
804 ctx
.info
[idx
].exec
.back().second
&= ~mask_type_global
;
805 bld
.insert(std::move(branch
));
809 if (block
->kind
& block_kind_loop_preheader
) {
810 /* collect information about the succeeding loop */
811 bool has_divergent_break
= false;
812 bool has_divergent_continue
= false;
813 bool has_discard
= false;
815 unsigned loop_nest_depth
= ctx
.program
->blocks
[idx
+ 1].loop_nest_depth
;
817 for (unsigned i
= idx
+ 1; ctx
.program
->blocks
[i
].loop_nest_depth
>= loop_nest_depth
; i
++) {
818 Block
& loop_block
= ctx
.program
->blocks
[i
];
819 needs
|= ctx
.info
[i
].block_needs
;
821 if (loop_block
.kind
& block_kind_uses_discard_if
||
822 loop_block
.kind
& block_kind_discard
||
823 loop_block
.kind
& block_kind_uses_demote
)
825 if (loop_block
.loop_nest_depth
!= loop_nest_depth
)
828 if (loop_block
.kind
& block_kind_uniform
)
830 else if (loop_block
.kind
& block_kind_break
)
831 has_divergent_break
= true;
832 else if (loop_block
.kind
& block_kind_continue
)
833 has_divergent_continue
= true;
836 if (ctx
.handle_wqm
) {
838 aco_ptr
<Instruction
> branch
= std::move(block
->instructions
.back());
839 block
->instructions
.pop_back();
840 transition_to_WQM(ctx
, bld
, idx
);
841 bld
.insert(std::move(branch
));
843 aco_ptr
<Instruction
> branch
= std::move(block
->instructions
.back());
844 block
->instructions
.pop_back();
845 transition_to_Exact(ctx
, bld
, idx
);
846 bld
.insert(std::move(branch
));
850 unsigned num_exec_masks
= ctx
.info
[idx
].exec
.size();
851 if (block
->kind
& block_kind_top_level
)
852 num_exec_masks
= std::min(num_exec_masks
, 2u);
854 ctx
.loop
.emplace_back(&ctx
.program
->blocks
[block
->linear_succs
[0]],
858 has_divergent_continue
,
862 if (block
->kind
& block_kind_discard
) {
864 assert(block
->instructions
.back()->format
== Format::PSEUDO_BRANCH
);
865 aco_ptr
<Instruction
> branch
= std::move(block
->instructions
.back());
866 block
->instructions
.pop_back();
868 /* create a discard_if() instruction with the exec mask as condition */
870 if (ctx
.loop
.size()) {
871 /* if we're in a loop, only discard from the outer exec masks */
872 num
= ctx
.loop
.back().num_exec_masks
;
874 num
= ctx
.info
[idx
].exec
.size() - 1;
877 Temp old_exec
= ctx
.info
[idx
].exec
.back().first
;
878 Temp new_exec
= bld
.tmp(s2
);
879 Temp cond
= bld
.sop1(aco_opcode::s_and_saveexec_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
880 bld
.exec(Definition(new_exec
)), Operand(0u), bld
.exec(old_exec
));
881 ctx
.info
[idx
].exec
.back().first
= new_exec
;
883 for (int i
= num
- 1; i
>= 0; i
--) {
884 Instruction
*andn2
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
885 ctx
.info
[block
->index
].exec
[i
].first
, cond
);
887 bld
.pseudo(aco_opcode::p_exit_early_if
, bld
.scc(andn2
->definitions
[1].getTemp()));
888 ctx
.info
[block
->index
].exec
[i
].first
= andn2
->definitions
[0].getTemp();
890 assert(!ctx
.handle_wqm
|| (ctx
.info
[block
->index
].exec
[0].second
& mask_type_wqm
) == 0);
892 if ((block
->kind
& (block_kind_break
| block_kind_uniform
)) == block_kind_break
)
893 ctx
.info
[idx
].exec
.back().first
= cond
;
894 bld
.insert(std::move(branch
));
895 /* no return here as it can be followed by a divergent break */
898 if (block
->kind
& block_kind_continue_or_break
) {
899 assert(ctx
.program
->blocks
[ctx
.program
->blocks
[block
->linear_succs
[1]].linear_succs
[0]].kind
& block_kind_loop_header
);
900 assert(ctx
.program
->blocks
[ctx
.program
->blocks
[block
->linear_succs
[0]].linear_succs
[0]].kind
& block_kind_loop_exit
);
901 assert(block
->instructions
.back()->opcode
== aco_opcode::p_branch
);
902 block
->instructions
.pop_back();
904 if (ctx
.info
[idx
].exec
.back().second
& mask_type_loop
) {
905 bld
.branch(aco_opcode::p_cbranch_nz
, bld
.exec(ctx
.info
[idx
].exec
.back().first
), block
->linear_succs
[1], block
->linear_succs
[0]);
908 for (int exec_idx
= ctx
.info
[idx
].exec
.size() - 1; exec_idx
>= 0; exec_idx
--) {
909 if (ctx
.info
[idx
].exec
[exec_idx
].second
& mask_type_loop
) {
910 cond
= bld
.sopc(aco_opcode::s_cmp_lg_u64
, bld
.def(s1
, scc
), ctx
.info
[idx
].exec
[exec_idx
].first
, Operand(0u));
914 assert(cond
!= Temp());
916 bld
.branch(aco_opcode::p_cbranch_nz
, bld
.scc(cond
), block
->linear_succs
[1], block
->linear_succs
[0]);
921 if (block
->kind
& block_kind_uniform
) {
922 Pseudo_branch_instruction
* branch
= static_cast<Pseudo_branch_instruction
*>(block
->instructions
.back().get());
923 if (branch
->opcode
== aco_opcode::p_branch
) {
924 branch
->target
[0] = block
->linear_succs
[0];
926 branch
->target
[0] = block
->linear_succs
[1];
927 branch
->target
[1] = block
->linear_succs
[0];
932 if (block
->kind
& block_kind_branch
) {
934 if (ctx
.handle_wqm
&&
935 ctx
.info
[idx
].exec
.size() >= 2 &&
936 ctx
.info
[idx
].exec
.back().second
== mask_type_exact
&&
937 !(ctx
.info
[idx
].block_needs
& Exact_Branch
) &&
938 ctx
.info
[idx
].exec
[ctx
.info
[idx
].exec
.size() - 2].second
& mask_type_wqm
) {
939 /* return to wqm before branching */
940 ctx
.info
[idx
].exec
.pop_back();
943 // orig = s_and_saveexec_b64
944 assert(block
->linear_succs
.size() == 2);
945 assert(block
->instructions
.back()->opcode
== aco_opcode::p_cbranch_z
);
946 Temp cond
= block
->instructions
.back()->operands
[0].getTemp();
947 block
->instructions
.pop_back();
949 if (ctx
.info
[idx
].block_needs
& Exact_Branch
)
950 transition_to_Exact(ctx
, bld
, idx
);
952 Temp current_exec
= ctx
.info
[idx
].exec
.back().first
;
953 uint8_t mask_type
= ctx
.info
[idx
].exec
.back().second
& (mask_type_wqm
| mask_type_exact
);
955 Temp then_mask
= bld
.tmp(s2
);
956 Temp old_exec
= bld
.sop1(aco_opcode::s_and_saveexec_b64
, bld
.def(s2
), bld
.def(s1
, scc
),
957 bld
.exec(Definition(then_mask
)), cond
, bld
.exec(current_exec
));
959 ctx
.info
[idx
].exec
.back().first
= old_exec
;
961 /* add next current exec to the stack */
962 ctx
.info
[idx
].exec
.emplace_back(then_mask
, mask_type
);
964 bld
.branch(aco_opcode::p_cbranch_z
, bld
.exec(then_mask
), block
->linear_succs
[1], block
->linear_succs
[0]);
968 if (block
->kind
& block_kind_invert
) {
969 // exec = s_andn2_b64 (original_exec, exec)
970 assert(block
->instructions
.back()->opcode
== aco_opcode::p_cbranch_nz
);
971 block
->instructions
.pop_back();
972 Temp then_mask
= ctx
.info
[idx
].exec
.back().first
;
973 uint8_t mask_type
= ctx
.info
[idx
].exec
.back().second
;
974 ctx
.info
[idx
].exec
.pop_back();
975 Temp orig_exec
= ctx
.info
[idx
].exec
.back().first
;
976 Temp else_mask
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
, exec
),
977 bld
.def(s1
, scc
), orig_exec
, bld
.exec(then_mask
));
979 /* add next current exec to the stack */
980 ctx
.info
[idx
].exec
.emplace_back(else_mask
, mask_type
);
982 bld
.branch(aco_opcode::p_cbranch_z
, bld
.exec(else_mask
), block
->linear_succs
[1], block
->linear_succs
[0]);
986 if (block
->kind
& block_kind_break
) {
987 // loop_mask = s_andn2_b64 (loop_mask, exec)
988 assert(block
->instructions
.back()->opcode
== aco_opcode::p_branch
);
989 block
->instructions
.pop_back();
991 Temp current_exec
= ctx
.info
[idx
].exec
.back().first
;
993 for (int exec_idx
= ctx
.info
[idx
].exec
.size() - 2; exec_idx
>= 0; exec_idx
--) {
995 Temp exec_mask
= ctx
.info
[idx
].exec
[exec_idx
].first
;
996 exec_mask
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
), bld
.scc(Definition(cond
)),
997 exec_mask
, current_exec
);
998 ctx
.info
[idx
].exec
[exec_idx
].first
= exec_mask
;
999 if (ctx
.info
[idx
].exec
[exec_idx
].second
& mask_type_loop
)
1003 /* check if the successor is the merge block, otherwise set exec to 0 */
1004 // TODO: this could be done better by directly branching to the merge block
1005 unsigned succ_idx
= ctx
.program
->blocks
[block
->linear_succs
[1]].linear_succs
[0];
1006 Block
& succ
= ctx
.program
->blocks
[succ_idx
];
1007 if (!(succ
.kind
& block_kind_invert
|| succ
.kind
& block_kind_merge
)) {
1008 ctx
.info
[idx
].exec
.back().first
= bld
.sop1(aco_opcode::s_mov_b64
, bld
.def(s2
, exec
), Operand(0u));
1011 bld
.branch(aco_opcode::p_cbranch_nz
, bld
.scc(cond
), block
->linear_succs
[1], block
->linear_succs
[0]);
1015 if (block
->kind
& block_kind_continue
) {
1016 assert(block
->instructions
.back()->opcode
== aco_opcode::p_branch
);
1017 block
->instructions
.pop_back();
1019 Temp current_exec
= ctx
.info
[idx
].exec
.back().first
;
1021 for (int exec_idx
= ctx
.info
[idx
].exec
.size() - 2; exec_idx
>= 0; exec_idx
--) {
1022 if (ctx
.info
[idx
].exec
[exec_idx
].second
& mask_type_loop
)
1025 Temp exec_mask
= ctx
.info
[idx
].exec
[exec_idx
].first
;
1026 exec_mask
= bld
.sop2(aco_opcode::s_andn2_b64
, bld
.def(s2
), bld
.scc(Definition(cond
)),
1027 exec_mask
, bld
.exec(current_exec
));
1028 ctx
.info
[idx
].exec
[exec_idx
].first
= exec_mask
;
1030 assert(cond
!= Temp());
1032 /* check if the successor is the merge block, otherwise set exec to 0 */
1033 // TODO: this could be done better by directly branching to the merge block
1034 unsigned succ_idx
= ctx
.program
->blocks
[block
->linear_succs
[1]].linear_succs
[0];
1035 Block
& succ
= ctx
.program
->blocks
[succ_idx
];
1036 if (!(succ
.kind
& block_kind_invert
|| succ
.kind
& block_kind_merge
)) {
1037 ctx
.info
[idx
].exec
.back().first
= bld
.sop1(aco_opcode::s_mov_b64
, bld
.def(s2
, exec
), Operand(0u));
1040 bld
.branch(aco_opcode::p_cbranch_nz
, bld
.scc(cond
), block
->linear_succs
[1], block
->linear_succs
[0]);
1045 void process_block(exec_ctx
& ctx
, Block
* block
)
1047 std::vector
<aco_ptr
<Instruction
>> instructions
;
1048 instructions
.reserve(block
->instructions
.size());
1050 unsigned idx
= add_coupling_code(ctx
, block
, instructions
);
1052 assert(block
->index
!= ctx
.program
->blocks
.size() - 1 ||
1053 ctx
.info
[block
->index
].exec
.size() <= 2);
1055 process_instructions(ctx
, block
, instructions
, idx
);
1057 block
->instructions
= std::move(instructions
);
1059 add_branch_code(ctx
, block
);
1061 block
->live_out_exec
= ctx
.info
[block
->index
].exec
.back().first
;
1064 } /* end namespace */
1067 void insert_exec_mask(Program
*program
)
1069 exec_ctx
ctx(program
);
1071 if (program
->needs_wqm
&& program
->needs_exact
)
1072 calculate_wqm_needs(ctx
);
1074 for (Block
& block
: program
->blocks
)
1075 process_block(ctx
, &block
);