Lines Matching refs:block

37  * 2. Each if-statement and loop must have one basic block before it and one
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.
49 block_add_pred(nir_block *block, nir_block *pred)
51 _mesa_set_add(block->predecessors, pred);
55 block_remove_pred(nir_block *block, nir_block *pred)
57 struct set_entry *entry = _mesa_set_search(block->predecessors, pred);
61 _mesa_set_remove(block->predecessors, entry);
91 unlink_block_successors(nir_block *block)
93 if (block->successors[1] != NULL)
94 unlink_blocks(block, block->successors[1]);
95 if (block->successors[0] != NULL)
96 unlink_blocks(block, block->successors[0]);
100 link_non_block_to_block(nir_cf_node *node, nir_block *block)
104 * We're trying to link an if to a block after it; this just means linking
105 * the last block of the then and else branches.
115 link_blocks(last_then_block, block, NULL);
120 link_blocks(last_else_block, block, NULL);
128 link_block_to_non_block(nir_block *block, nir_cf_node *node)
132 * We're trying to link a block to an if after it; this just means linking
133 * the block to the first block of the then and else branches.
141 unlink_block_successors(block);
142 link_blocks(block, first_then_block, first_else_block);
154 unlink_block_successors(block);
155 link_blocks(block, loop_header_block, NULL);
161 * Replace a block's successor with a different one.
164 replace_successor(nir_block *block, nir_block *old_succ, nir_block *new_succ)
166 if (block->successors[0] == old_succ) {
167 block->successors[0] = new_succ;
169 assert(block->successors[1] == old_succ);
170 block->successors[1] = new_succ;
173 block_remove_pred(old_succ, block);
174 block_add_pred(new_succ, block);
178 * Takes a basic block and inserts a new empty basic block before it, making its
179 * predecessors point to the new block. This essentially splits the block into
180 * an empty header and a body so that another non-block CF node can be inserted
186 split_block_beginning(nir_block *block)
188 nir_block *new_block = nir_block_create(ralloc_parent(block));
189 new_block->cf_node.parent = block->cf_node.parent;
190 exec_node_insert_node_before(&block->cf_node.node, &new_block->cf_node.node);
192 set_foreach(block->predecessors, entry) {
194 replace_successor(pred, block, new_block);
197 /* Any phi nodes must stay part of the new block, or else their
200 nir_foreach_instr_safe(instr, block) {
205 instr->block = new_block;
213 rewrite_phi_preds(nir_block *block, nir_block *old_pred, nir_block *new_pred)
215 nir_foreach_instr_safe(instr, block) {
230 nir_insert_phi_undef(nir_block *block, nir_block *pred)
232 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
233 nir_foreach_instr(instr, block) {
273 /* Given a basic block with no successors that has been inserted into the
279 block_add_normal_succs(nir_block *block)
281 if (exec_node_is_tail_sentinel(block->cf_node.node.next)) {
282 nir_cf_node *parent = block->cf_node.parent;
287 link_blocks(block, next_block, NULL);
293 link_blocks(block, head_block, NULL);
294 nir_insert_phi_undef(head_block, block);
297 link_blocks(block, impl->end_block, NULL);
300 nir_cf_node *next = nir_cf_node_next(&block->cf_node);
307 link_blocks(block, first_then_block, first_else_block);
313 link_blocks(block, first_block, NULL);
314 nir_insert_phi_undef(first_block, block);
320 split_block_end(nir_block *block)
322 nir_block *new_block = nir_block_create(ralloc_parent(block));
323 new_block->cf_node.parent = block->cf_node.parent;
324 exec_node_insert_after(&block->cf_node.node, &new_block->cf_node.node);
326 if (nir_block_ends_in_jump(block)) {
327 /* Figure out what successor block would've had if it didn't have a jump
332 move_successors(block, new_block);
342 nir_block *new_block = split_block_beginning(instr->block);
344 nir_foreach_instr_safe(cur_instr, instr->block) {
349 cur_instr->block = new_block;
356 /* Splits a basic block at the point specified by the cursor. The "before" and
358 * if non-NULL. Note that the "beginning" of the block is actually interpreted
359 * as before the first non-phi instruction, and it's illegal to split a block
370 after = cursor.block;
371 before = split_block_beginning(cursor.block);
375 before = cursor.block;
376 after = split_block_end(cursor.block);
380 after = cursor.instr->block;
389 before = cursor.instr->block;
390 after = split_block_end(cursor.instr->block);
392 after = cursor.instr->block;
408 * Inserts a non-basic block between two basic blocks and links them together.
433 remove_phi_src(nir_block *block, nir_block *pred)
435 nir_foreach_instr(instr, block) {
451 * update the CFG after a jump instruction has been added to the end of a block
455 nir_handle_add_jump(nir_block *block)
457 nir_instr *instr = nir_block_last_instr(block);
460 if (block->successors[0])
461 remove_phi_src(block->successors[0], block);
462 if (block->successors[1])
463 remove_phi_src(block->successors[1], block);
464 unlink_block_successors(block);
466 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
472 link_blocks(block, impl->end_block, NULL);
476 nir_loop *loop = nearest_loop(&block->cf_node);
479 link_blocks(block, after_block, NULL);
484 nir_loop *loop = nearest_loop(&block->cf_node);
486 link_blocks(block, first_block, NULL);
491 link_blocks(block, jump_instr->target, NULL);
495 link_blocks(block, jump_instr->else_target, jump_instr->target);
503 /* Removes the successor of a block with a jump. Note that the jump to be
508 unlink_jump(nir_block *block, nir_jump_type type, bool add_normal_successors)
510 if (block->successors[0])
511 remove_phi_src(block->successors[0], block);
512 if (block->successors[1])
513 remove_phi_src(block->successors[1], block);
515 unlink_block_successors(block);
517 block_add_normal_succs(block);
521 nir_handle_remove_jump(nir_block *block, nir_jump_type type)
523 unlink_jump(block, type, true);
525 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
551 * Returns a cursor pointing at the end of the before block (i.e.m between the
581 instr->block = before;
600 nir_block *block = nir_cf_node_as_block(node);
601 exec_node_insert_after(&before->cf_node.node, &block->cf_node.node);
602 block->cf_node.parent = before->cf_node.parent;
603 /* stitch_blocks() assumes that any block that ends with a jump has
605 * up jumps here as the block is being inserted.
607 if (nir_block_ends_in_jump(block))
608 nir_handle_add_jump(block);
610 stitch_blocks(block, after);
611 stitch_blocks(before, block);
637 nir_block *block = nir_cf_node_as_block(node);
639 nir_foreach_instr_safe(instr, block) {
642 unlink_jump(block, jump->type, false);
698 /* Splitting a block twice with two cursors created before either split is
700 * point to the same block. One is if the second cursor is an block-based
702 * block. If it's a before_block cursor and it's in the same block as
708 if (end.option == nir_cursor_after_block && end.block == block_before)
709 end.block = block_begin;
714 * second split places the original block after the new block in which case
715 * the block_begin pointer that we saved off above is pointing to the block
716 * at the end rather than the block in the middle like it's supposed to be.
726 /* Dominance and other block-related information is toast. */
752 nir_block *block = nir_cf_node_as_block(node);
753 nir_instr *last_instr = nir_block_last_instr(block);
764 unlink_block_successors(block);
765 link_blocks(block, end_block, NULL);