nir/sweep: Fix handling instructions with debug info

When debug information is present, the nir_instr pointer is not the
start of the allocation.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28613>
This commit is contained in:
Konstantin Seurer 2025-02-24 19:50:13 +01:00 committed by Marge Bot
parent fbc55afbdf
commit a04b5ebd3c
3 changed files with 16 additions and 10 deletions

View file

@ -817,15 +817,6 @@ nir_tex_instr_create(nir_shader *shader, unsigned num_srcs)
return instr;
}
static void *
nir_instr_get_gc_pointer(nir_instr *instr)
{
if (unlikely(instr->has_debug_info))
return nir_instr_get_debug_info(instr);
return instr;
}
static gc_ctx *
nir_instr_get_gc_context(nir_instr *instr)
{

View file

@ -4241,6 +4241,15 @@ nir_instr_get_debug_info(nir_instr *instr)
return container_of(instr, nir_instr_debug_info, instr);
}
static inline void *
nir_instr_get_gc_pointer(nir_instr *instr)
{
if (unlikely(instr->has_debug_info))
return nir_instr_get_debug_info(instr);
return instr;
}
typedef bool (*nir_foreach_def_cb)(nir_def *def, void *state);
typedef bool (*nir_foreach_src_cb)(nir_src *src, void *state);
static inline bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state);

View file

@ -49,7 +49,13 @@ sweep_block(nir_shader *nir, nir_block *block)
ralloc_steal(nir, block);
nir_foreach_instr(instr, block) {
gc_mark_live(nir->gctx, instr);
gc_mark_live(nir->gctx, nir_instr_get_gc_pointer(instr));
if (instr->has_debug_info) {
nir_instr_debug_info *debug_info = nir_instr_get_debug_info(instr);
ralloc_steal(nir, debug_info->filename);
ralloc_steal(nir, debug_info->variable_name);
}
switch (instr->type) {
case nir_instr_type_tex: