pan: improve debug printing of multiple registers

This makes printing of BIR in SSA-form more similar to NIR and after
register allocation, it shows consecutive registers for operands
reading/writing to more than one register.

Reviewed-by: Christoph Pillmayer <christoph.pillmayer@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40711>
This commit is contained in:
Jakob Sinclair 2026-03-30 10:34:15 +02:00 committed by Marge Bot
parent 54515bf8d1
commit c3d56e9f82

View file

@ -1,4 +1,5 @@
# Copyright (C) 2020 Collabora, Ltd.
# Copyright (C) 2026 Arm Ltd.
# SPDX-License-Identifier: MIT
TEMPLATE = """#include <stdio.h>
@ -65,7 +66,7 @@ bir_passthrough_name(unsigned idx)
}
static void
bi_print_index(FILE *fp, bi_index index)
bi_print_index(FILE *fp, bi_index index, unsigned nr_regs)
{
if (index.discard)
fputs("^", fp);
@ -84,9 +85,12 @@ bi_print_index(FILE *fp, bi_index index)
fprintf(fp, "%s", bir_fau_name(index.value));
else if (index.type == BI_INDEX_PASS)
fprintf(fp, "%s", bir_passthrough_name(index.value));
else if (index.type == BI_INDEX_REGISTER)
fprintf(fp, "%s%u", index.memory ? "m" : "r", index.value);
else if (index.type == BI_INDEX_NORMAL)
else if (index.type == BI_INDEX_REGISTER) {
for (int i = 0; i < nr_regs; i++) {
if (i > 0) fputs(":", fp);
fprintf(fp, "%s%u", index.memory ? "m" : "r", index.value + i);
}
} else if (index.type == BI_INDEX_NORMAL)
fprintf(fp, "%s%u", index.memory ? "m" : "", index.value);
else
UNREACHABLE("Invalid index");
@ -153,12 +157,38 @@ bi_${mod}_as_str(enum bi_${mod} ${mod})
void
bi_print_instr_impl(const bi_instr *I, FILE *fp)
{
fputs(" ", fp);
char buf[128];
size_t len = 0;
unsigned indent = 8;
/* Print destination width in SSA-form. For SPLIT, only print one width as
* it is assumed all destinations will have the same width.
*/
bi_foreach_ssa_dest(I, d) {
if (I->op == BI_OPCODE_SPLIT_I32 && d > 0)
continue;
if (len > 0)
len += snprintf(buf + len, sizeof(buf) - len, ",");
unsigned nr_regs = bi_count_write_registers(I, d);
if (nr_regs > 1)
len += snprintf(buf + len, sizeof(buf) - len, "32x%u", nr_regs);
else if (nr_regs == 1)
len += snprintf(buf + len, sizeof(buf) - len, "32");
}
if (len > 0)
fputs(buf, fp);
if (len >= indent)
fputc(' ', fp);
else
fprintf(fp, "%*s", (int)(indent - len), "");
bi_foreach_dest(I, d) {
if (d > 0) fprintf(fp, ", ");
bi_print_index(fp, I->dest[d]);
unsigned nr_regs = bi_count_write_registers(I, d);
bi_print_index(fp, I->dest[d], nr_regs);
}
if (I->nr_dests > 0)
@ -179,7 +209,8 @@ bi_print_instr_impl(const bi_instr *I, FILE *fp)
else
fputs(" ", fp);
bi_print_index(fp, I->src[i]);
unsigned nr_regs = bi_count_read_registers(I, i);
bi_print_index(fp, I->src[i], nr_regs);
}
}
@ -196,7 +227,7 @@ bi_print_instr_impl(const bi_instr *I, FILE *fp)
% if src > 0:
fputs(", ", fp);
% endif
bi_print_index(fp, I->src[${src}]);
bi_print_index(fp, I->src[${src}], bi_count_read_registers(I, ${src}));
${print_source_modifiers([m for m in ops[opcode]["modifiers"] if m[-1] == str(src)], src, modifiers)}
% endfor
% for imm in ops[opcode]["immediates"]: