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 link_blocks(nir_block
*pred
, nir_block
*succ1
, nir_block
*succ2
)
66 pred
->successors
[0] = succ1
;
68 block_add_pred(succ1
, pred
);
70 pred
->successors
[1] = succ2
;
72 block_add_pred(succ2
, pred
);
76 unlink_blocks(nir_block
*pred
, nir_block
*succ
)
78 if (pred
->successors
[0] == succ
) {
79 pred
->successors
[0] = pred
->successors
[1];
80 pred
->successors
[1] = NULL
;
82 assert(pred
->successors
[1] == succ
);
83 pred
->successors
[1] = NULL
;
86 struct set_entry
*entry
= _mesa_set_search(succ
->predecessors
, pred
);
90 _mesa_set_remove(succ
->predecessors
, entry
);
94 unlink_block_successors(nir_block
*block
)
96 if (block
->successors
[0] != NULL
)
97 unlink_blocks(block
, block
->successors
[0]);
98 if (block
->successors
[1] != NULL
)
99 unlink_blocks(block
, block
->successors
[1]);
103 link_non_block_to_block(nir_cf_node
*node
, nir_block
*block
)
105 if (node
->type
== nir_cf_node_if
) {
107 * We're trying to link an if to a block after it; this just means linking
108 * the last block of the then and else branches.
111 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
113 nir_cf_node
*last_then
= nir_if_last_then_node(if_stmt
);
114 assert(last_then
->type
== nir_cf_node_block
);
115 nir_block
*last_then_block
= nir_cf_node_as_block(last_then
);
117 nir_cf_node
*last_else
= nir_if_last_else_node(if_stmt
);
118 assert(last_else
->type
== nir_cf_node_block
);
119 nir_block
*last_else_block
= nir_cf_node_as_block(last_else
);
121 if (!block_ends_in_jump(last_then_block
)) {
122 unlink_block_successors(last_then_block
);
123 link_blocks(last_then_block
, block
, NULL
);
126 if (!block_ends_in_jump(last_else_block
)) {
127 unlink_block_successors(last_else_block
);
128 link_blocks(last_else_block
, block
, NULL
);
131 assert(node
->type
== nir_cf_node_loop
);
134 * We can only get to this codepath if we're inserting a new loop, or
135 * at least a loop with no break statements; we can't insert break
136 * statements into a loop when we haven't inserted it into the CFG
137 * because we wouldn't know which block comes after the loop
138 * and therefore, which block should be the successor of the block with
139 * the break). Therefore, we need to insert a fake edge (see invariant
143 nir_loop
*loop
= nir_cf_node_as_loop(node
);
145 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
146 assert(last
->type
== nir_cf_node_block
);
147 nir_block
*last_block
= nir_cf_node_as_block(last
);
149 last_block
->successors
[1] = block
;
150 block_add_pred(block
, last_block
);
155 link_block_to_non_block(nir_block
*block
, nir_cf_node
*node
)
157 if (node
->type
== nir_cf_node_if
) {
159 * We're trying to link a block to an if after it; this just means linking
160 * the block to the first block of the then and else branches.
163 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
165 nir_cf_node
*first_then
= nir_if_first_then_node(if_stmt
);
166 assert(first_then
->type
== nir_cf_node_block
);
167 nir_block
*first_then_block
= nir_cf_node_as_block(first_then
);
169 nir_cf_node
*first_else
= nir_if_first_else_node(if_stmt
);
170 assert(first_else
->type
== nir_cf_node_block
);
171 nir_block
*first_else_block
= nir_cf_node_as_block(first_else
);
173 unlink_block_successors(block
);
174 link_blocks(block
, first_then_block
, first_else_block
);
177 * For similar reasons as the corresponding case in
178 * link_non_block_to_block(), don't worry about if the loop header has
179 * any predecessors that need to be unlinked.
182 assert(node
->type
== nir_cf_node_loop
);
184 nir_loop
*loop
= nir_cf_node_as_loop(node
);
186 nir_cf_node
*loop_header
= nir_loop_first_cf_node(loop
);
187 assert(loop_header
->type
== nir_cf_node_block
);
188 nir_block
*loop_header_block
= nir_cf_node_as_block(loop_header
);
190 unlink_block_successors(block
);
191 link_blocks(block
, loop_header_block
, NULL
);
197 * Takes a basic block and inserts a new empty basic block before it, making its
198 * predecessors point to the new block. This essentially splits the block into
199 * an empty header and a body so that another non-block CF node can be inserted
200 * between the two. Note that this does *not* link the two basic blocks, so
201 * some kind of cleanup *must* be performed after this call.
205 split_block_beginning(nir_block
*block
)
207 nir_block
*new_block
= nir_block_create(ralloc_parent(block
));
208 new_block
->cf_node
.parent
= block
->cf_node
.parent
;
209 exec_node_insert_node_before(&block
->cf_node
.node
, &new_block
->cf_node
.node
);
211 struct set_entry
*entry
;
212 set_foreach(block
->predecessors
, entry
) {
213 nir_block
*pred
= (nir_block
*) entry
->key
;
215 unlink_blocks(pred
, block
);
216 link_blocks(pred
, new_block
, NULL
);
219 /* Any phi nodes must stay part of the new block, or else their
220 * sourcse will be messed up. This will reverse the order of the phi's, but
221 * order shouldn't matter.
223 nir_foreach_instr_safe(block
, instr
) {
224 if (instr
->type
!= nir_instr_type_phi
)
227 exec_node_remove(&instr
->node
);
228 instr
->block
= new_block
;
229 exec_list_push_head(&new_block
->instr_list
, &instr
->node
);
236 rewrite_phi_preds(nir_block
*block
, nir_block
*old_pred
, nir_block
*new_pred
)
238 nir_foreach_instr_safe(block
, instr
) {
239 if (instr
->type
!= nir_instr_type_phi
)
242 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
243 nir_foreach_phi_src(phi
, src
) {
244 if (src
->pred
== old_pred
) {
245 src
->pred
= new_pred
;
253 insert_phi_undef(nir_block
*block
, nir_block
*pred
)
255 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
256 nir_foreach_instr(block
, instr
) {
257 if (instr
->type
!= nir_instr_type_phi
)
260 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
261 nir_ssa_undef_instr
*undef
=
262 nir_ssa_undef_instr_create(ralloc_parent(phi
),
263 phi
->dest
.ssa
.num_components
);
264 nir_instr_insert_before_cf_list(&impl
->body
, &undef
->instr
);
265 nir_phi_src
*src
= ralloc(phi
, nir_phi_src
);
267 src
->src
.parent_instr
= &phi
->instr
;
268 src
->src
.is_ssa
= true;
269 src
->src
.ssa
= &undef
->def
;
271 list_addtail(&src
->src
.use_link
, &undef
->def
.uses
);
273 exec_list_push_tail(&phi
->srcs
, &src
->node
);
278 * Moves the successors of source to the successors of dest, leaving both
279 * successors of source NULL.
283 move_successors(nir_block
*source
, nir_block
*dest
)
285 nir_block
*succ1
= source
->successors
[0];
286 nir_block
*succ2
= source
->successors
[1];
289 unlink_blocks(source
, succ1
);
290 rewrite_phi_preds(succ1
, source
, dest
);
294 unlink_blocks(source
, succ2
);
295 rewrite_phi_preds(succ2
, source
, dest
);
298 unlink_block_successors(dest
);
299 link_blocks(dest
, succ1
, succ2
);
302 /* Given a basic block with no successors that has been inserted into the
303 * control flow tree, gives it the successors it would normally have assuming
304 * it doesn't end in a jump instruction. Also inserts phi sources with undefs
308 block_add_normal_succs(nir_block
*block
)
310 if (exec_node_is_tail_sentinel(block
->cf_node
.node
.next
)) {
311 nir_cf_node
*parent
= block
->cf_node
.parent
;
312 if (parent
->type
== nir_cf_node_if
) {
313 nir_cf_node
*next
= nir_cf_node_next(parent
);
314 assert(next
->type
== nir_cf_node_block
);
315 nir_block
*next_block
= nir_cf_node_as_block(next
);
317 link_blocks(block
, next_block
, NULL
);
319 assert(parent
->type
== nir_cf_node_loop
);
320 nir_loop
*loop
= nir_cf_node_as_loop(parent
);
322 nir_cf_node
*head
= nir_loop_first_cf_node(loop
);
323 assert(head
->type
== nir_cf_node_block
);
324 nir_block
*head_block
= nir_cf_node_as_block(head
);
326 link_blocks(block
, head_block
, NULL
);
327 insert_phi_undef(head_block
, block
);
330 nir_cf_node
*next
= nir_cf_node_next(&block
->cf_node
);
331 if (next
->type
== nir_cf_node_if
) {
332 nir_if
*next_if
= nir_cf_node_as_if(next
);
334 nir_cf_node
*first_then
= nir_if_first_then_node(next_if
);
335 assert(first_then
->type
== nir_cf_node_block
);
336 nir_block
*first_then_block
= nir_cf_node_as_block(first_then
);
338 nir_cf_node
*first_else
= nir_if_first_else_node(next_if
);
339 assert(first_else
->type
== nir_cf_node_block
);
340 nir_block
*first_else_block
= nir_cf_node_as_block(first_else
);
342 link_blocks(block
, first_then_block
, first_else_block
);
344 assert(next
->type
== nir_cf_node_loop
);
345 nir_loop
*next_loop
= nir_cf_node_as_loop(next
);
347 nir_cf_node
*first
= nir_loop_first_cf_node(next_loop
);
348 assert(first
->type
== nir_cf_node_block
);
349 nir_block
*first_block
= nir_cf_node_as_block(first
);
351 link_blocks(block
, first_block
, NULL
);
352 insert_phi_undef(first_block
, block
);
358 split_block_end(nir_block
*block
)
360 nir_block
*new_block
= nir_block_create(ralloc_parent(block
));
361 new_block
->cf_node
.parent
= block
->cf_node
.parent
;
362 exec_node_insert_after(&block
->cf_node
.node
, &new_block
->cf_node
.node
);
364 if (block_ends_in_jump(block
)) {
365 /* Figure out what successor block would've had if it didn't have a jump
366 * instruction, and make new_block have that successor.
368 block_add_normal_succs(new_block
);
370 move_successors(block
, new_block
);
377 split_block_before_instr(nir_instr
*instr
)
379 assert(instr
->type
!= nir_instr_type_phi
);
380 nir_block
*new_block
= split_block_beginning(instr
->block
);
382 nir_foreach_instr_safe(instr
->block
, cur_instr
) {
383 if (cur_instr
== instr
)
386 exec_node_remove(&cur_instr
->node
);
387 cur_instr
->block
= new_block
;
388 exec_list_push_tail(&new_block
->instr_list
, &cur_instr
->node
);
394 /* Splits a basic block at the point specified by the cursor. The "before" and
395 * "after" arguments are filled out with the blocks resulting from the split
396 * if non-NULL. Note that the "beginning" of the block is actually interpreted
397 * as before the first non-phi instruction, and it's illegal to split a block
398 * before a phi instruction.
402 split_block_cursor(nir_cursor cursor
,
403 nir_block
**_before
, nir_block
**_after
)
405 nir_block
*before
, *after
;
406 switch (cursor
.option
) {
407 case nir_cursor_before_block
:
408 after
= cursor
.block
;
409 before
= split_block_beginning(cursor
.block
);
412 case nir_cursor_after_block
:
413 before
= cursor
.block
;
414 after
= split_block_end(cursor
.block
);
417 case nir_cursor_before_instr
:
418 after
= cursor
.instr
->block
;
419 before
= split_block_before_instr(cursor
.instr
);
422 case nir_cursor_after_instr
:
423 /* We lower this to split_block_before_instr() so that we can keep the
424 * after-a-jump-instr case contained to split_block_end().
426 if (nir_instr_is_last(cursor
.instr
)) {
427 before
= cursor
.instr
->block
;
428 after
= split_block_end(cursor
.instr
->block
);
430 after
= cursor
.instr
->block
;
431 before
= split_block_before_instr(nir_instr_next(cursor
.instr
));
443 * Inserts a non-basic block between two basic blocks and links them together.
447 insert_non_block(nir_block
*before
, nir_cf_node
*node
, nir_block
*after
)
449 node
->parent
= before
->cf_node
.parent
;
450 exec_node_insert_after(&before
->cf_node
.node
, &node
->node
);
451 link_block_to_non_block(before
, node
);
452 link_non_block_to_block(node
, after
);
455 /* walk up the control flow tree to find the innermost enclosed loop */
457 nearest_loop(nir_cf_node
*node
)
459 while (node
->type
!= nir_cf_node_loop
) {
463 return nir_cf_node_as_loop(node
);
467 * update the CFG after a jump instruction has been added to the end of a block
471 nir_handle_add_jump(nir_block
*block
)
473 nir_instr
*instr
= nir_block_last_instr(block
);
474 nir_jump_instr
*jump_instr
= nir_instr_as_jump(instr
);
476 unlink_block_successors(block
);
478 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
479 nir_metadata_preserve(impl
, nir_metadata_none
);
481 if (jump_instr
->type
== nir_jump_break
||
482 jump_instr
->type
== nir_jump_continue
) {
483 nir_loop
*loop
= nearest_loop(&block
->cf_node
);
485 if (jump_instr
->type
== nir_jump_continue
) {
486 nir_cf_node
*first_node
= nir_loop_first_cf_node(loop
);
487 assert(first_node
->type
== nir_cf_node_block
);
488 nir_block
*first_block
= nir_cf_node_as_block(first_node
);
489 link_blocks(block
, first_block
, NULL
);
491 nir_cf_node
*after
= nir_cf_node_next(&loop
->cf_node
);
492 assert(after
->type
== nir_cf_node_block
);
493 nir_block
*after_block
= nir_cf_node_as_block(after
);
494 link_blocks(block
, after_block
, NULL
);
496 /* If we inserted a fake link, remove it */
497 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
498 assert(last
->type
== nir_cf_node_block
);
499 nir_block
*last_block
= nir_cf_node_as_block(last
);
500 if (last_block
->successors
[1] != NULL
)
501 unlink_blocks(last_block
, after_block
);
504 assert(jump_instr
->type
== nir_jump_return
);
505 link_blocks(block
, impl
->end_block
, NULL
);
510 remove_phi_src(nir_block
*block
, nir_block
*pred
)
512 nir_foreach_instr(block
, instr
) {
513 if (instr
->type
!= nir_instr_type_phi
)
516 nir_phi_instr
*phi
= nir_instr_as_phi(instr
);
517 nir_foreach_phi_src_safe(phi
, src
) {
518 if (src
->pred
== pred
) {
519 list_del(&src
->src
.use_link
);
520 exec_node_remove(&src
->node
);
526 /* Removes the successor of a block with a jump, and inserts a fake edge for
527 * infinite loops. Note that the jump to be eliminated may be free-floating.
531 void unlink_jump(nir_block
*block
, nir_jump_type type
)
533 if (block
->successors
[0])
534 remove_phi_src(block
->successors
[0], block
);
535 if (block
->successors
[1])
536 remove_phi_src(block
->successors
[1], block
);
538 if (type
== nir_jump_break
) {
539 nir_block
*next
= block
->successors
[0];
541 if (next
->predecessors
->entries
== 1) {
543 nir_cf_node_as_loop(nir_cf_node_prev(&next
->cf_node
));
545 /* insert fake link */
546 nir_cf_node
*last
= nir_loop_last_cf_node(loop
);
547 assert(last
->type
== nir_cf_node_block
);
548 nir_block
*last_block
= nir_cf_node_as_block(last
);
550 last_block
->successors
[1] = next
;
551 block_add_pred(next
, last_block
);
555 unlink_block_successors(block
);
559 nir_handle_remove_jump(nir_block
*block
, nir_jump_type type
)
561 unlink_jump(block
, type
);
563 block_add_normal_succs(block
);
565 nir_function_impl
*impl
= nir_cf_node_get_function(&block
->cf_node
);
566 nir_metadata_preserve(impl
, nir_metadata_none
);
570 update_if_uses(nir_cf_node
*node
)
572 if (node
->type
!= nir_cf_node_if
)
575 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
577 if_stmt
->condition
.parent_if
= if_stmt
;
578 if (if_stmt
->condition
.is_ssa
) {
579 list_addtail(&if_stmt
->condition
.use_link
,
580 &if_stmt
->condition
.ssa
->if_uses
);
582 list_addtail(&if_stmt
->condition
.use_link
,
583 &if_stmt
->condition
.reg
.reg
->if_uses
);
588 * Stitch two basic blocks together into one. The aggregate must have the same
589 * predecessors as the first and the same successors as the second.
593 stitch_blocks(nir_block
*before
, nir_block
*after
)
596 * We move after into before, so we have to deal with up to 2 successors vs.
597 * possibly a large number of predecessors.
599 * TODO: special case when before is empty and after isn't?
602 if (block_ends_in_jump(before
)) {
603 assert(exec_list_is_empty(&after
->instr_list
));
604 if (after
->successors
[0])
605 remove_phi_src(after
->successors
[0], after
);
606 if (after
->successors
[1])
607 remove_phi_src(after
->successors
[1], after
);
608 unlink_block_successors(after
);
609 exec_node_remove(&after
->cf_node
.node
);
611 move_successors(after
, before
);
613 foreach_list_typed(nir_instr
, instr
, node
, &after
->instr_list
) {
614 instr
->block
= before
;
617 exec_list_append(&before
->instr_list
, &after
->instr_list
);
618 exec_node_remove(&after
->cf_node
.node
);
623 nir_cf_node_insert(nir_cursor cursor
, nir_cf_node
*node
)
625 nir_block
*before
, *after
;
627 split_block_cursor(cursor
, &before
, &after
);
629 if (node
->type
== nir_cf_node_block
) {
630 nir_block
*block
= nir_cf_node_as_block(node
);
631 exec_node_insert_after(&before
->cf_node
.node
, &block
->cf_node
.node
);
632 block
->cf_node
.parent
= before
->cf_node
.parent
;
633 /* stitch_blocks() assumes that any block that ends with a jump has
634 * already been setup with the correct successors, so we need to set
635 * up jumps here as the block is being inserted.
637 if (block_ends_in_jump(block
))
638 nir_handle_add_jump(block
);
640 stitch_blocks(block
, after
);
641 stitch_blocks(before
, block
);
643 update_if_uses(node
);
644 insert_non_block(before
, node
, after
);
649 replace_ssa_def_uses(nir_ssa_def
*def
, void *void_impl
)
651 nir_function_impl
*impl
= void_impl
;
652 void *mem_ctx
= ralloc_parent(impl
);
654 nir_ssa_undef_instr
*undef
=
655 nir_ssa_undef_instr_create(mem_ctx
, def
->num_components
);
656 nir_instr_insert_before_cf_list(&impl
->body
, &undef
->instr
);
657 nir_ssa_def_rewrite_uses(def
, nir_src_for_ssa(&undef
->def
), mem_ctx
);
662 cleanup_cf_node(nir_cf_node
*node
, nir_function_impl
*impl
)
664 switch (node
->type
) {
665 case nir_cf_node_block
: {
666 nir_block
*block
= nir_cf_node_as_block(node
);
667 /* We need to walk the instructions and clean up defs/uses */
668 nir_foreach_instr_safe(block
, instr
) {
669 if (instr
->type
== nir_instr_type_jump
) {
670 nir_jump_type jump_type
= nir_instr_as_jump(instr
)->type
;
671 unlink_jump(block
, jump_type
);
673 nir_foreach_ssa_def(instr
, replace_ssa_def_uses
, impl
);
674 nir_instr_remove(instr
);
680 case nir_cf_node_if
: {
681 nir_if
*if_stmt
= nir_cf_node_as_if(node
);
682 foreach_list_typed(nir_cf_node
, child
, node
, &if_stmt
->then_list
)
683 cleanup_cf_node(child
, impl
);
684 foreach_list_typed(nir_cf_node
, child
, node
, &if_stmt
->else_list
)
685 cleanup_cf_node(child
, impl
);
687 list_del(&if_stmt
->condition
.use_link
);
691 case nir_cf_node_loop
: {
692 nir_loop
*loop
= nir_cf_node_as_loop(node
);
693 foreach_list_typed(nir_cf_node
, child
, node
, &loop
->body
)
694 cleanup_cf_node(child
, impl
);
697 case nir_cf_node_function
: {
698 nir_function_impl
*impl
= nir_cf_node_as_function(node
);
699 foreach_list_typed(nir_cf_node
, child
, node
, &impl
->body
)
700 cleanup_cf_node(child
, impl
);
704 unreachable("Invalid CF node type");
709 nir_cf_extract(nir_cf_list
*extracted
, nir_cursor begin
, nir_cursor end
)
711 nir_block
*block_begin
, *block_end
, *block_before
, *block_after
;
713 /* In the case where begin points to an instruction in some basic block and
714 * end points to the end of the same basic block, we rely on the fact that
715 * splitting on an instruction moves earlier instructions into a new basic
716 * block. If the later instructions were moved instead, then the end cursor
717 * would be pointing to the same place that begin used to point to, which
718 * is obviously not what we want.
720 split_block_cursor(begin
, &block_before
, &block_begin
);
721 split_block_cursor(end
, &block_end
, &block_after
);
723 extracted
->impl
= nir_cf_node_get_function(&block_begin
->cf_node
);
724 exec_list_make_empty(&extracted
->list
);
726 nir_cf_node
*cf_node
= &block_begin
->cf_node
;
727 nir_cf_node
*cf_node_end
= &block_end
->cf_node
;
729 nir_cf_node
*next
= nir_cf_node_next(cf_node
);
731 exec_node_remove(&cf_node
->node
);
732 cf_node
->parent
= NULL
;
733 exec_list_push_tail(&extracted
->list
, &cf_node
->node
);
735 if (cf_node
== cf_node_end
)
741 stitch_blocks(block_before
, block_after
);
745 nir_cf_reinsert(nir_cf_list
*cf_list
, nir_cursor cursor
)
747 nir_block
*before
, *after
;
749 split_block_cursor(cursor
, &before
, &after
);
751 foreach_list_typed_safe(nir_cf_node
, node
, node
, &cf_list
->list
) {
752 exec_node_remove(&node
->node
);
753 node
->parent
= before
->cf_node
.parent
;
754 exec_node_insert_node_before(&after
->cf_node
.node
, &node
->node
);
757 stitch_blocks(before
,
758 nir_cf_node_as_block(nir_cf_node_next(&before
->cf_node
)));
759 stitch_blocks(nir_cf_node_as_block(nir_cf_node_prev(&after
->cf_node
)),
764 nir_cf_delete(nir_cf_list
*cf_list
)
766 foreach_list_typed(nir_cf_node
, node
, node
, &cf_list
->list
) {
767 cleanup_cf_node(node
, cf_list
->impl
);