nir: Stop using instructions for debug info

Annotating ssa defs without affecting compilation is impossible with
debug info instructions since referencing a nir_def from the debug info
instr will add uses.

The old approach also stops worrking if passes reorder instructions.

This patch proposes a solution which should not regress performance just
like the old approach. The difference is that this one allocates a bit
more space for debug info instead of adding a new instruction for it.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33141>
This commit is contained in:
Konstantin Seurer
2024-11-04 21:16:16 +01:00
committed by Marge Bot
parent e73c4ce7c5
commit 60a20bcf3d
21 changed files with 308 additions and 383 deletions
+10 -13
View File
@@ -9947,22 +9947,17 @@ visit_jump(isel_context* ctx, nir_jump_instr* instr)
}
void
visit_debug_info(isel_context* ctx, nir_debug_info_instr* instr)
visit_debug_info(isel_context* ctx, nir_instr_debug_info* instr_info)
{
ac_shader_debug_info info;
memset(&info, 0, sizeof(info));
switch (instr->type) {
case nir_debug_info_src_loc:
info.type = ac_shader_debug_info_src_loc;
info.src_loc.file = strdup(nir_src_as_string(instr->src_loc.filename));
info.src_loc.line = instr->src_loc.line;
info.src_loc.column = instr->src_loc.column;
info.src_loc.spirv_offset = instr->src_loc.spirv_offset;
break;
default:
return;
}
info.type = ac_shader_debug_info_src_loc;
if (instr_info->filename)
info.src_loc.file = strdup(instr_info->filename);
info.src_loc.line = instr_info->line;
info.src_loc.column = instr_info->column;
info.src_loc.spirv_offset = instr_info->spirv_offset;
Builder bld(ctx->program, ctx->block);
bld.pseudo(aco_opcode::p_debug_info, Operand::c32(ctx->program->debug_info.size()));
@@ -9990,6 +9985,9 @@ visit_block(isel_context* ctx, nir_block* block)
ctx->block->instructions.reserve(ctx->block->instructions.size() +
exec_list_length(&block->instr_list) * 2);
nir_foreach_instr (instr, block) {
if (ctx->shader->has_debug_info)
visit_debug_info(ctx, nir_instr_get_debug_info(instr));
switch (instr->type) {
case nir_instr_type_alu: visit_alu_instr(ctx, nir_instr_as_alu(instr)); break;
case nir_instr_type_load_const: visit_load_const(ctx, nir_instr_as_load_const(instr)); break;
@@ -9999,7 +9997,6 @@ visit_block(isel_context* ctx, nir_block* block)
case nir_instr_type_undef: visit_undef(ctx, nir_instr_as_undef(instr)); break;
case nir_instr_type_deref: break;
case nir_instr_type_jump: visit_jump(ctx, nir_instr_as_jump(instr)); break;
case nir_instr_type_debug_info: visit_debug_info(ctx, nir_instr_as_debug_info(instr)); break;
default: isel_err(instr, "Unknown NIR instr type");
}
}