Home | History | Annotate | Download | only in nir

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_ends_in_jump(nir_block *block)
51 return !exec_list_is_empty(&block->instr_list) &&
52 nir_block_last_instr(block)->type == nir_instr_type_jump;
56 block_add_pred(nir_block *block, nir_block *pred)
58 _mesa_set_add(block->predecessors, pred);
62 block_remove_pred(nir_block *block, nir_block *pred)
64 struct set_entry *entry = _mesa_set_search(block->predecessors, pred);
68 _mesa_set_remove(block->predecessors, entry);
98 unlink_block_successors(nir_block *block)
100 if (block->successors[1] != NULL)
101 unlink_blocks(block, block->successors[1]);
102 if (block->successors[0] != NULL)
103 unlink_blocks(block, block->successors[0]);
107 link_non_block_to_block(nir_cf_node *node, nir_block *block)
111 * We're trying to link an if to a block after it; this just means linking
112 * the last block of the then and else branches.
122 link_blocks(last_then_block, block, NULL);
127 link_blocks(last_else_block, block, NULL);
135 link_block_to_non_block(nir_block *block, nir_cf_node *node)
139 * We're trying to link a block to an if after it; this just means linking
140 * the block to the first block of the then and else branches.
148 unlink_block_successors(block);
149 link_blocks(block, first_then_block, first_else_block);
161 unlink_block_successors(block);
162 link_blocks(block, loop_header_block, NULL);
168 * Replace a block's successor with a different one.
171 replace_successor(nir_block *block, nir_block *old_succ, nir_block *new_succ)
173 if (block->successors[0] == old_succ) {
174 block->successors[0] = new_succ;
176 assert(block->successors[1] == old_succ);
177 block->successors[1] = new_succ;
180 block_remove_pred(old_succ, block);
181 block_add_pred(new_succ, block);
185 * Takes a basic block and inserts a new empty basic block before it, making its
186 * predecessors point to the new block. This essentially splits the block into
187 * an empty header and a body so that another non-block CF node can be inserted
193 split_block_beginning(nir_block *block)
195 nir_block *new_block = nir_block_create(ralloc_parent(block));
196 new_block->cf_node.parent = block->cf_node.parent;
197 exec_node_insert_node_before(&block->cf_node.node, &new_block->cf_node.node);
200 set_foreach(block->predecessors, entry) {
202 replace_successor(pred, block, new_block);
205 /* Any phi nodes must stay part of the new block, or else their
209 nir_foreach_instr_safe(instr, block) {
214 instr->block = new_block;
222 rewrite_phi_preds(nir_block *block, nir_block *old_pred, nir_block *new_pred)
224 nir_foreach_instr_safe(instr, block) {
239 insert_phi_undef(nir_block *block, nir_block *pred)
241 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
242 nir_foreach_instr(instr, block) {
289 /* Given a basic block with no successors that has been inserted into the
295 block_add_normal_succs(nir_block *block)
297 if (exec_node_is_tail_sentinel(block->cf_node.node.next)) {
298 nir_cf_node *parent = block->cf_node.parent;
303 link_blocks(block, next_block, NULL);
309 link_blocks(block, head_block, NULL);
310 insert_phi_undef(head_block, block);
313 link_blocks(block, impl->end_block, NULL);
316 nir_cf_node *next = nir_cf_node_next(&block->cf_node);
323 link_blocks(block, first_then_block, first_else_block);
329 link_blocks(block, first_block, NULL);
330 insert_phi_undef(first_block, block);
336 split_block_end(nir_block *block)
338 nir_block *new_block = nir_block_create(ralloc_parent(block));
339 new_block->cf_node.parent = block->cf_node.parent;
340 exec_node_insert_after(&block->cf_node.node, &new_block->cf_node.node);
342 if (block_ends_in_jump(block)) {
343 /* Figure out what successor block would've had if it didn't have a jump
348 move_successors(block, new_block);
358 nir_block *new_block = split_block_beginning(instr->block);
360 nir_foreach_instr_safe(cur_instr, instr->block) {
365 cur_instr->block = new_block;
372 /* Splits a basic block at the point specified by the cursor. The "before" and
374 * if non-NULL. Note that the "beginning" of the block is actually interpreted
375 * as before the first non-phi instruction, and it's illegal to split a block
386 after = cursor.block;
387 before = split_block_beginning(cursor.block);
391 before = cursor.block;
392 after = split_block_end(cursor.block);
396 after = cursor.instr->block;
405 before = cursor.instr->block;
406 after = split_block_end(cursor.instr->block);
408 after = cursor.instr->block;
424 * Inserts a non-basic block between two basic blocks and links them together.
448 * update the CFG after a jump instruction has been added to the end of a block
452 nir_handle_add_jump(nir_block *block)
454 nir_instr *instr = nir_block_last_instr(block);
457 unlink_block_successors(block);
459 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
464 nir_loop *loop = nearest_loop(&block->cf_node);
468 link_blocks(block, first_block, NULL);
472 link_blocks(block, after_block, NULL);
476 link_blocks(block, impl->end_block, NULL);
481 remove_phi_src(nir_block *block, nir_block *pred)
483 nir_foreach_instr(instr, block) {
497 /* Removes the successor of a block with a jump. Note that the jump to be
502 unlink_jump(nir_block *block, nir_jump_type type, bool add_normal_successors)
504 if (block->successors[0])
505 remove_phi_src(block->successors[0], block);
506 if (block->successors[1])
507 remove_phi_src(block->successors[1], block);
509 unlink_block_successors(block);
511 block_add_normal_succs(block);
515 nir_handle_remove_jump(nir_block *block, nir_jump_type type)
517 unlink_jump(block, type, true);
519 nir_function_impl *impl = nir_cf_node_get_function(&block->cf_node);
568 instr->block = before;
584 nir_block *block = nir_cf_node_as_block(node);
585 exec_node_insert_after(&before->cf_node.node, &block->cf_node.node);
586 block->cf_node.parent = before->cf_node.parent;
587 /* stitch_blocks() assumes that any block that ends with a jump has
589 * up jumps here as the block is being inserted.
591 if (block_ends_in_jump(block))
592 nir_handle_add_jump(block);
594 stitch_blocks(block, after);
595 stitch_blocks(before, block);
621 nir_block *block = nir_cf_node_as_block(node);
623 nir_foreach_instr_safe(instr, block) {
626 unlink_jump(block, jump_type, false);
674 /* In the case where begin points to an instruction in some basic block and
675 * end points to the end of the same basic block, we rely on the fact that
677 * block. If the later instructions were moved instead, then the end cursor
687 /* Dominance and other block-related information is toast. */