e2a151dafacc5b9cb57d7fab3c8c7f66748f66d9
2 * Copyright © 2014 Intel 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
24 * Connor Abbott (cwabbott0@gmail.com)
28 #include "nir_control_flow_private.h"
31 * \name Control flow modification
33 * These functions modify the control flow tree while keeping the control flow
34 * graph up-to-date. The invariants respected are:
35 * 1. Each then statement, else statement, or loop body must have at least one
37 * 2. Each if-statement and loop must have one basic block before it and one
39 * 3. Two basic blocks cannot be directly next to each other.
40 * 4. If a basic block has a jump instruction, there must be only one and it
41 * must be at the end of the block.
42 * 5. The CFG must always be connected - this means that we must insert a fake
43 * CFG edge for loops with no break statement.
45 * The purpose of the second one is so that we have places to insert code during
46 * GCM, as well as eliminating the possibility of critical edges.
51 block_ends_in_jump(nir_block
*block
)
53 return !exec_list_is_empty(&block
->instr_list
) &&
54 nir_block_last_instr(block
)->type
== nir_instr_type_jump
;
58 block_add_pred(nir_block
*block
, nir_block
*pred
)
60 _mesa_set_add(block
->predecessors
, pred
);
64 block_remove_pred(nir_block
*block
, nir_block
*pred
)
66 struct set_entry
*entry
= _mesa_set_search(block
->predecessors
, pred
);
70 _mesa_set_remove(block
->predecessors
, entry
);
74 link_blocks(nir_block
*pred
, nir_block
*succ1
, nir_block
*succ2
)
76 pred
->successors
[0] = succ1
;
78 block_add_pred(succ1
, pred
);
80 pred
->successors
[1] = succ2
;
82 block_add_pred(succ2
, pred
);
86 unlink_blocks(nir_block
*pred
, nir_block
*succ
)
88 if (pred
->successors
[0] == succ
) {
89 pred
->successors
[0] = pred
->successors
[1];
90 pred
->successors
[1] = NULL
;
92 assert(pred
->successors
[1] == succ
);
93 pred
->successors
[1] = NULL
;
96 block_remove_pred(succ
, pred
);
100 unlink_block_successors(nir_block
*block
)
102 if (block
->successors
[0] != NULL
)
103 unlink_blocks(block
, block
->successors
[0]);
104 if (block
->successors
[1] != NULL
)
105 unlink_blocks(block
, block
->successors
[1]);
109 link_non_block_to_block(nir_cf_node
*node
, nir_block
*block
)
111 if (node
->type
== nir_cf_node_if
) {
113 * We're trying to link an if to a block after it; this just means linking
114 * the last block of the then and else branches.
117 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
119 nir_cf_node
*last_then
= nir_if_last_then_node(if_stmt
);
120 assert(last_then
->type
== nir_cf_node_block
);
121 nir_block
*last_then_block
= nir_cf_node_as_block(last_then
);
123 nir_cf_node
*last_else
= nir_if_last_else_node(if_stmt
);
124 assert(last_else
->type
== nir_cf_node_block
);
125 nir_block
*last_else_block
= nir_cf_node_as_block(last_else
);
127 if (!block_ends_in_jump(last_then_block
)) {
128 unlink_block_successors(last_then_block
);
129 link_blocks(last_then_block
, block
, NULL
);
132 if (!block_ends_in_jump(last_else_block
)) {
133 unlink_block_successors(last_else_block
);
134 link_blocks(last_else_block
, block
, NULL
);
137 assert(node
->type
== nir_cf_node_loop
);
140 * We can only get to this codepath if we're inserting a new loop, or
141 * at least a loop with no break statements; we can't insert break
142 * statements into a loop when we haven't inserted it into the CFG
143 * because we wouldn't know which block comes after the loop
144 * and therefore, which block should be the successor of the block with
145 * the break). Therefore, we need to insert a fake edge (see invariant
149 nir_loop
*loop
= nir_cf_node_as_loop(node
);
151 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
152 assert(last
->type
== nir_cf_node_block
);
153 nir_block
*last_block
= nir_cf_node_as_block(last
);
155 last_block
->successors
[1] = block
;
156 block_add_pred(block
, last_block
);
161 link_block_to_non_block(nir_block
*block
, nir_cf_node
*node
)
163 if (node
->type
== nir_cf_node_if
) {
165 * We're trying to link a block to an if after it; this just means linking
166 * the block to the first block of the then and else branches.
169 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
171 nir_cf_node
*first_then
= nir_if_first_then_node(if_stmt
);
172 assert(first_then
->type
== nir_cf_node_block
);
173 nir_block
*first_then_block
= nir_cf_node_as_block(first_then
);
175 nir_cf_node
*first_else
= nir_if_first_else_node(if_stmt
);
176 assert(first_else
->type
== nir_cf_node_block
);
177 nir_block
*first_else_block
= nir_cf_node_as_block(first_else
);
179 unlink_block_successors(block
);
180 link_blocks(block
, first_then_block
, first_else_block
);
183 * For similar reasons as the corresponding case in
184 * link_non_block_to_block(), don't worry about if the loop header has
185 * any predecessors that need to be unlinked.
188 assert(node
->type
== nir_cf_node_loop
);
190 nir_loop
*loop
= nir_cf_node_as_loop(node
);
192 nir_cf_node
*loop_header
= nir_loop_first_cf_node(loop
);
193 assert(loop_header
->type
== nir_cf_node_block
);
194 nir_block
*loop_header_block
= nir_cf_node_as_block(loop_header
);
196 unlink_block_successors(block
);
197 link_blocks(block
, loop_header_block
, NULL
);
203 * Replace a block's successor with a different one.
206 replace_successor(nir_block
*block
, nir_block
*old_succ
, nir_block
*new_succ
)
208 if (block
->successors
[0] == old_succ
) {
209 block
->successors
[0] = new_succ
;
211 assert(block
->successors
[1] == old_succ
);
212 block
->successors
[1] = new_succ
;
215 block_remove_pred(old_succ
, block
);
216 block_add_pred(new_succ
, block
);
220 * Takes a basic block and inserts a new empty basic block before it, making its
221 * predecessors point to the new block. This essentially splits the block into
222 * an empty header and a body so that another non-block CF node can be inserted
223 * between the two. Note that this does *not* link the two basic blocks, so
224 * some kind of cleanup *must* be performed after this call.
228 split_block_beginning(nir_block
*block
)
230 nir_block
*new_block
= nir_block_create(ralloc_parent(block
));
231 new_block
->cf_node
.parent
= block
->cf_node
.parent
;
232 exec_node_insert_node_before(&block
->cf_node
.node
, &new_block
->cf_node
.node
);
234 struct set_entry
*entry
;
235 set_foreach(block
->predecessors
, entry
) {
236 nir_block
*pred
= (nir_block
*) entry
->key
;
237 replace_successor(pred
, block
, new_block
);
240 /* Any phi nodes must stay part of the new block, or else their
241 * sourcse will be messed up. This will reverse the order of the phi's, but
242 * order shouldn't matter.
244 nir_foreach_instr_safe(block
, instr
) {
245 if (instr
->type
!= nir_instr_type_phi
)
248 exec_node_remove(&instr
->node
);
249 instr
->block
= new_block
;
250 exec_list_push_head(&new_block
->instr_list
, &instr
->node
);
257 rewrite_phi_preds(nir_block
*block
, nir_block
*old_pred
, nir_block
*new_pred
)
259 nir_foreach_instr_safe(block
, instr
) {
260 if (instr
->type
!= nir_instr_type_phi
)
263 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
264 nir_foreach_phi_src(phi
, src
) {
265 if (src
->pred
== old_pred
) {
266 src
->pred
= new_pred
;
274 insert_phi_undef(nir_block
*block
, nir_block
*pred
)
276 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
277 nir_foreach_instr(block
, instr
) {
278 if (instr
->type
!= nir_instr_type_phi
)
281 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
282 nir_ssa_undef_instr
*undef
=
283 nir_ssa_undef_instr_create(ralloc_parent(phi
),
284 phi
->dest
.ssa
.num_components
);
285 nir_instr_insert_before_cf_list(&impl
->body
, &undef
->instr
);
286 nir_phi_src
*src
= ralloc(phi
, nir_phi_src
);
288 src
->src
.parent_instr
= &phi
->instr
;
289 src
->src
.is_ssa
= true;
290 src
->src
.ssa
= &undef
->def
;
292 list_addtail(&src
->src
.use_link
, &undef
->def
.uses
);
294 exec_list_push_tail(&phi
->srcs
, &src
->node
);
299 * Moves the successors of source to the successors of dest, leaving both
300 * successors of source NULL.
304 move_successors(nir_block
*source
, nir_block
*dest
)
306 nir_block
*succ1
= source
->successors
[0];
307 nir_block
*succ2
= source
->successors
[1];
310 unlink_blocks(source
, succ1
);
311 rewrite_phi_preds(succ1
, source
, dest
);
315 unlink_blocks(source
, succ2
);
316 rewrite_phi_preds(succ2
, source
, dest
);
319 unlink_block_successors(dest
);
320 link_blocks(dest
, succ1
, succ2
);
323 /* Given a basic block with no successors that has been inserted into the
324 * control flow tree, gives it the successors it would normally have assuming
325 * it doesn't end in a jump instruction. Also inserts phi sources with undefs
329 block_add_normal_succs(nir_block
*block
)
331 if (exec_node_is_tail_sentinel(block
->cf_node
.node
.next
)) {
332 nir_cf_node
*parent
= block
->cf_node
.parent
;
333 if (parent
->type
== nir_cf_node_if
) {
334 nir_cf_node
*next
= nir_cf_node_next(parent
);
335 assert(next
->type
== nir_cf_node_block
);
336 nir_block
*next_block
= nir_cf_node_as_block(next
);
338 link_blocks(block
, next_block
, NULL
);
340 assert(parent
->type
== nir_cf_node_loop
);
341 nir_loop
*loop
= nir_cf_node_as_loop(parent
);
343 nir_cf_node
*head
= nir_loop_first_cf_node(loop
);
344 assert(head
->type
== nir_cf_node_block
);
345 nir_block
*head_block
= nir_cf_node_as_block(head
);
347 link_blocks(block
, head_block
, NULL
);
348 insert_phi_undef(head_block
, block
);
351 nir_cf_node
*next
= nir_cf_node_next(&block
->cf_node
);
352 if (next
->type
== nir_cf_node_if
) {
353 nir_if
*next_if
= nir_cf_node_as_if(next
);
355 nir_cf_node
*first_then
= nir_if_first_then_node(next_if
);
356 assert(first_then
->type
== nir_cf_node_block
);
357 nir_block
*first_then_block
= nir_cf_node_as_block(first_then
);
359 nir_cf_node
*first_else
= nir_if_first_else_node(next_if
);
360 assert(first_else
->type
== nir_cf_node_block
);
361 nir_block
*first_else_block
= nir_cf_node_as_block(first_else
);
363 link_blocks(block
, first_then_block
, first_else_block
);
365 assert(next
->type
== nir_cf_node_loop
);
366 nir_loop
*next_loop
= nir_cf_node_as_loop(next
);
368 nir_cf_node
*first
= nir_loop_first_cf_node(next_loop
);
369 assert(first
->type
== nir_cf_node_block
);
370 nir_block
*first_block
= nir_cf_node_as_block(first
);
372 link_blocks(block
, first_block
, NULL
);
373 insert_phi_undef(first_block
, block
);
379 split_block_end(nir_block
*block
)
381 nir_block
*new_block
= nir_block_create(ralloc_parent(block
));
382 new_block
->cf_node
.parent
= block
->cf_node
.parent
;
383 exec_node_insert_after(&block
->cf_node
.node
, &new_block
->cf_node
.node
);
385 if (block_ends_in_jump(block
)) {
386 /* Figure out what successor block would've had if it didn't have a jump
387 * instruction, and make new_block have that successor.
389 block_add_normal_succs(new_block
);
391 move_successors(block
, new_block
);
398 split_block_before_instr(nir_instr
*instr
)
400 assert(instr
->type
!= nir_instr_type_phi
);
401 nir_block
*new_block
= split_block_beginning(instr
->block
);
403 nir_foreach_instr_safe(instr
->block
, cur_instr
) {
404 if (cur_instr
== instr
)
407 exec_node_remove(&cur_instr
->node
);
408 cur_instr
->block
= new_block
;
409 exec_list_push_tail(&new_block
->instr_list
, &cur_instr
->node
);
415 /* Splits a basic block at the point specified by the cursor. The "before" and
416 * "after" arguments are filled out with the blocks resulting from the split
417 * if non-NULL. Note that the "beginning" of the block is actually interpreted
418 * as before the first non-phi instruction, and it's illegal to split a block
419 * before a phi instruction.
423 split_block_cursor(nir_cursor cursor
,
424 nir_block
**_before
, nir_block
**_after
)
426 nir_block
*before
, *after
;
427 switch (cursor
.option
) {
428 case nir_cursor_before_block
:
429 after
= cursor
.block
;
430 before
= split_block_beginning(cursor
.block
);
433 case nir_cursor_after_block
:
434 before
= cursor
.block
;
435 after
= split_block_end(cursor
.block
);
438 case nir_cursor_before_instr
:
439 after
= cursor
.instr
->block
;
440 before
= split_block_before_instr(cursor
.instr
);
443 case nir_cursor_after_instr
:
444 /* We lower this to split_block_before_instr() so that we can keep the
445 * after-a-jump-instr case contained to split_block_end().
447 if (nir_instr_is_last(cursor
.instr
)) {
448 before
= cursor
.instr
->block
;
449 after
= split_block_end(cursor
.instr
->block
);
451 after
= cursor
.instr
->block
;
452 before
= split_block_before_instr(nir_instr_next(cursor
.instr
));
464 * Inserts a non-basic block between two basic blocks and links them together.
468 insert_non_block(nir_block
*before
, nir_cf_node
*node
, nir_block
*after
)
470 node
->parent
= before
->cf_node
.parent
;
471 exec_node_insert_after(&before
->cf_node
.node
, &node
->node
);
472 link_block_to_non_block(before
, node
);
473 link_non_block_to_block(node
, after
);
476 /* walk up the control flow tree to find the innermost enclosed loop */
478 nearest_loop(nir_cf_node
*node
)
480 while (node
->type
!= nir_cf_node_loop
) {
484 return nir_cf_node_as_loop(node
);
488 * update the CFG after a jump instruction has been added to the end of a block
492 nir_handle_add_jump(nir_block
*block
)
494 nir_instr
*instr
= nir_block_last_instr(block
);
495 nir_jump_instr
*jump_instr
= nir_instr_as_jump(instr
);
497 unlink_block_successors(block
);
499 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
500 nir_metadata_preserve(impl
, nir_metadata_none
);
502 if (jump_instr
->type
== nir_jump_break
||
503 jump_instr
->type
== nir_jump_continue
) {
504 nir_loop
*loop
= nearest_loop(&block
->cf_node
);
506 if (jump_instr
->type
== nir_jump_continue
) {
507 nir_cf_node
*first_node
= nir_loop_first_cf_node(loop
);
508 assert(first_node
->type
== nir_cf_node_block
);
509 nir_block
*first_block
= nir_cf_node_as_block(first_node
);
510 link_blocks(block
, first_block
, NULL
);
512 nir_cf_node
*after
= nir_cf_node_next(&loop
->cf_node
);
513 assert(after
->type
== nir_cf_node_block
);
514 nir_block
*after_block
= nir_cf_node_as_block(after
);
515 link_blocks(block
, after_block
, NULL
);
517 /* If we inserted a fake link, remove it */
518 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
519 assert(last
->type
== nir_cf_node_block
);
520 nir_block
*last_block
= nir_cf_node_as_block(last
);
521 if (last_block
->successors
[1] != NULL
)
522 unlink_blocks(last_block
, after_block
);
525 assert(jump_instr
->type
== nir_jump_return
);
526 link_blocks(block
, impl
->end_block
, NULL
);
531 remove_phi_src(nir_block
*block
, nir_block
*pred
)
533 nir_foreach_instr(block
, instr
) {
534 if (instr
->type
!= nir_instr_type_phi
)
537 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
538 nir_foreach_phi_src_safe(phi
, src
) {
539 if (src
->pred
== pred
) {
540 list_del(&src
->src
.use_link
);
541 exec_node_remove(&src
->node
);
547 /* Removes the successor of a block with a jump, and inserts a fake edge for
548 * infinite loops. Note that the jump to be eliminated may be free-floating.
552 void unlink_jump(nir_block
*block
, nir_jump_type type
)
554 if (block
->successors
[0])
555 remove_phi_src(block
->successors
[0], block
);
556 if (block
->successors
[1])
557 remove_phi_src(block
->successors
[1], block
);
559 if (type
== nir_jump_break
) {
560 nir_block
*next
= block
->successors
[0];
562 if (next
->predecessors
->entries
== 1) {
564 nir_cf_node_as_loop(nir_cf_node_prev(&next
->cf_node
));
566 /* insert fake link */
567 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
568 assert(last
->type
== nir_cf_node_block
);
569 nir_block
*last_block
= nir_cf_node_as_block(last
);
571 last_block
->successors
[1] = next
;
572 block_add_pred(next
, last_block
);
576 unlink_block_successors(block
);
580 nir_handle_remove_jump(nir_block
*block
, nir_jump_type type
)
582 unlink_jump(block
, type
);
584 block_add_normal_succs(block
);
586 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
587 nir_metadata_preserve(impl
, nir_metadata_none
);
591 update_if_uses(nir_cf_node
*node
)
593 if (node
->type
!= nir_cf_node_if
)
596 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
598 if_stmt
->condition
.parent_if
= if_stmt
;
599 if (if_stmt
->condition
.is_ssa
) {
600 list_addtail(&if_stmt
->condition
.use_link
,
601 &if_stmt
->condition
.ssa
->if_uses
);
603 list_addtail(&if_stmt
->condition
.use_link
,
604 &if_stmt
->condition
.reg
.reg
->if_uses
);
609 * Stitch two basic blocks together into one. The aggregate must have the same
610 * predecessors as the first and the same successors as the second.
614 stitch_blocks(nir_block
*before
, nir_block
*after
)
617 * We move after into before, so we have to deal with up to 2 successors vs.
618 * possibly a large number of predecessors.
620 * TODO: special case when before is empty and after isn't?
623 if (block_ends_in_jump(before
)) {
624 assert(exec_list_is_empty(&after
->instr_list
));
625 if (after
->successors
[0])
626 remove_phi_src(after
->successors
[0], after
);
627 if (after
->successors
[1])
628 remove_phi_src(after
->successors
[1], after
);
629 unlink_block_successors(after
);
630 exec_node_remove(&after
->cf_node
.node
);
632 move_successors(after
, before
);
634 foreach_list_typed(nir_instr
, instr
, node
, &after
->instr_list
) {
635 instr
->block
= before
;
638 exec_list_append(&before
->instr_list
, &after
->instr_list
);
639 exec_node_remove(&after
->cf_node
.node
);
644 nir_cf_node_insert(nir_cursor cursor
, nir_cf_node
*node
)
646 nir_block
*before
, *after
;
648 split_block_cursor(cursor
, &before
, &after
);
650 if (node
->type
== nir_cf_node_block
) {
651 nir_block
*block
= nir_cf_node_as_block(node
);
652 exec_node_insert_after(&before
->cf_node
.node
, &block
->cf_node
.node
);
653 block
->cf_node
.parent
= before
->cf_node
.parent
;
654 /* stitch_blocks() assumes that any block that ends with a jump has
655 * already been setup with the correct successors, so we need to set
656 * up jumps here as the block is being inserted.
658 if (block_ends_in_jump(block
))
659 nir_handle_add_jump(block
);
661 stitch_blocks(block
, after
);
662 stitch_blocks(before
, block
);
664 update_if_uses(node
);
665 insert_non_block(before
, node
, after
);
670 replace_ssa_def_uses(nir_ssa_def
*def
, void *void_impl
)
672 nir_function_impl
*impl
= void_impl
;
673 void *mem_ctx
= ralloc_parent(impl
);
675 nir_ssa_undef_instr
*undef
=
676 nir_ssa_undef_instr_create(mem_ctx
, def
->num_components
);
677 nir_instr_insert_before_cf_list(&impl
->body
, &undef
->instr
);
678 nir_ssa_def_rewrite_uses(def
, nir_src_for_ssa(&undef
->def
));
683 cleanup_cf_node(nir_cf_node
*node
, nir_function_impl
*impl
)
685 switch (node
->type
) {
686 case nir_cf_node_block
: {
687 nir_block
*block
= nir_cf_node_as_block(node
);
688 /* We need to walk the instructions and clean up defs/uses */
689 nir_foreach_instr_safe(block
, instr
) {
690 if (instr
->type
== nir_instr_type_jump
) {
691 nir_jump_type jump_type
= nir_instr_as_jump(instr
)->type
;
692 unlink_jump(block
, jump_type
);
694 nir_foreach_ssa_def(instr
, replace_ssa_def_uses
, impl
);
695 nir_instr_remove(instr
);
701 case nir_cf_node_if
: {
702 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
703 foreach_list_typed(nir_cf_node
, child
, node
, &if_stmt
->then_list
)
704 cleanup_cf_node(child
, impl
);
705 foreach_list_typed(nir_cf_node
, child
, node
, &if_stmt
->else_list
)
706 cleanup_cf_node(child
, impl
);
708 list_del(&if_stmt
->condition
.use_link
);
712 case nir_cf_node_loop
: {
713 nir_loop
*loop
= nir_cf_node_as_loop(node
);
714 foreach_list_typed(nir_cf_node
, child
, node
, &loop
->body
)
715 cleanup_cf_node(child
, impl
);
718 case nir_cf_node_function
: {
719 nir_function_impl
*impl
= nir_cf_node_as_function(node
);
720 foreach_list_typed(nir_cf_node
, child
, node
, &impl
->body
)
721 cleanup_cf_node(child
, impl
);
725 unreachable("Invalid CF node type");
730 nir_cf_extract(nir_cf_list
*extracted
, nir_cursor begin
, nir_cursor end
)
732 nir_block
*block_begin
, *block_end
, *block_before
, *block_after
;
734 /* In the case where begin points to an instruction in some basic block and
735 * end points to the end of the same basic block, we rely on the fact that
736 * splitting on an instruction moves earlier instructions into a new basic
737 * block. If the later instructions were moved instead, then the end cursor
738 * would be pointing to the same place that begin used to point to, which
739 * is obviously not what we want.
741 split_block_cursor(begin
, &block_before
, &block_begin
);
742 split_block_cursor(end
, &block_end
, &block_after
);
744 extracted
->impl
= nir_cf_node_get_function(&block_begin
->cf_node
);
745 exec_list_make_empty(&extracted
->list
);
747 nir_cf_node
*cf_node
= &block_begin
->cf_node
;
748 nir_cf_node
*cf_node_end
= &block_end
->cf_node
;
750 nir_cf_node
*next
= nir_cf_node_next(cf_node
);
752 exec_node_remove(&cf_node
->node
);
753 cf_node
->parent
= NULL
;
754 exec_list_push_tail(&extracted
->list
, &cf_node
->node
);
756 if (cf_node
== cf_node_end
)
762 stitch_blocks(block_before
, block_after
);
766 nir_cf_reinsert(nir_cf_list
*cf_list
, nir_cursor cursor
)
768 nir_block
*before
, *after
;
770 split_block_cursor(cursor
, &before
, &after
);
772 foreach_list_typed_safe(nir_cf_node
, node
, node
, &cf_list
->list
) {
773 exec_node_remove(&node
->node
);
774 node
->parent
= before
->cf_node
.parent
;
775 exec_node_insert_node_before(&after
->cf_node
.node
, &node
->node
);
778 stitch_blocks(before
,
779 nir_cf_node_as_block(nir_cf_node_next(&before
->cf_node
)));
780 stitch_blocks(nir_cf_node_as_block(nir_cf_node_prev(&after
->cf_node
)),
785 nir_cf_delete(nir_cf_list
*cf_list
)
787 foreach_list_typed(nir_cf_node
, node
, node
, &cf_list
->list
) {
788 cleanup_cf_node(node
, cf_list
->impl
);