nir/print: Reformat the preds/succs block information
- Always print preds in same line as block name; - Use a single line for empty blocks; - Align preds/succs with the instructions. ``` if %29 { block b4: // preds: b3 32 %30 = load_const (0x00000000 = 0.000000) 32x4 %31 = @vulkan_resource_index (%30 (0x0)) (desc_set=0, binding=0, desc_type=SSBO) 32x4 %32 = @load_vulkan_descriptor (%31) (desc_type=SSBO) 32x4 %33 = deref_cast (Storage *)%32 (ssbo Storage) (ptr_stride=0, align_mul=4, align_offset=0) 32x4 %34 = deref_struct &%33->fail (ssbo uint) // &((Storage *)%32)->fail 32 %36 = @deref_atomic (%34, %35 (0x1)) (access=1, atomic_op=iadd) // succs: b6 } else { block b5: // preds: b3, succs: b6 } ``` Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Acked-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23564>
This commit is contained in:
@@ -1860,6 +1860,30 @@ block_has_instruction_with_dest(nir_block *block)
|
||||
static void print_cf_node(nir_cf_node *node, print_state *state,
|
||||
unsigned tabs);
|
||||
|
||||
static void
|
||||
print_block_preds(nir_block *block, print_state *state)
|
||||
{
|
||||
FILE *fp = state->fp;
|
||||
nir_block **preds = nir_block_get_predecessors_sorted(block, NULL);
|
||||
for (unsigned i = 0; i < block->predecessors->entries; i++) {
|
||||
if (i != 0)
|
||||
fprintf(fp, " ");
|
||||
fprintf(fp, "b%u", preds[i]->index);
|
||||
}
|
||||
ralloc_free(preds);
|
||||
}
|
||||
|
||||
static void
|
||||
print_block_succs(nir_block *block, print_state *state)
|
||||
{
|
||||
FILE *fp = state->fp;
|
||||
for (unsigned i = 0; i < 2; i++) {
|
||||
if (block->successors[i]) {
|
||||
fprintf(fp, "b%u ", block->successors[i]->index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
print_block(nir_block *block, print_state *state, unsigned tabs)
|
||||
{
|
||||
@@ -1871,18 +1895,25 @@ print_block(nir_block *block, print_state *state, unsigned tabs)
|
||||
state->padding_for_no_dest = 0;
|
||||
|
||||
print_indentation(tabs, fp);
|
||||
fprintf(fp, "block b%u:\n", block->index);
|
||||
fprintf(fp, "block b%u:", block->index);
|
||||
|
||||
nir_block **preds = nir_block_get_predecessors_sorted(block, NULL);
|
||||
|
||||
print_indentation(tabs, fp);
|
||||
fprintf(fp, "// preds: ");
|
||||
for (unsigned i = 0; i < block->predecessors->entries; i++) {
|
||||
fprintf(fp, "b%u ", preds[i]->index);
|
||||
const bool empty_block = exec_list_is_empty(&block->instr_list);
|
||||
if (empty_block) {
|
||||
fprintf(fp, " // preds: ");
|
||||
print_block_preds(block, state);
|
||||
fprintf(fp, ", succs: ");
|
||||
print_block_succs(block, state);
|
||||
fprintf(fp, "\n");
|
||||
return;
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
|
||||
ralloc_free(preds);
|
||||
const unsigned block_length = 7 + count_digits(block->index) + 1;
|
||||
const unsigned pred_padding = block_length < state->padding_for_no_dest ?
|
||||
state->padding_for_no_dest - block_length : 0;
|
||||
|
||||
fprintf(fp, "%*s// preds: ", pred_padding, "");
|
||||
print_block_preds(block, state);
|
||||
fprintf(fp, "\n");
|
||||
|
||||
nir_foreach_instr(instr, block) {
|
||||
print_instr(instr, state, tabs);
|
||||
@@ -1891,11 +1922,8 @@ print_block(nir_block *block, print_state *state, unsigned tabs)
|
||||
}
|
||||
|
||||
print_indentation(tabs, fp);
|
||||
fprintf(fp, "// succs: ");
|
||||
for (unsigned i = 0; i < 2; i++)
|
||||
if (block->successors[i]) {
|
||||
fprintf(fp, "b%u ", block->successors[i]->index);
|
||||
}
|
||||
fprintf(fp, "%*s// succs: ", state->padding_for_no_dest, "");
|
||||
print_block_succs(block, state);
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user