From a04b5ebd3c9292df4e87c1146447f49718bbd29c Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Mon, 24 Feb 2025 19:50:13 +0100 Subject: [PATCH] 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 Part-of: --- src/compiler/nir/nir.c | 9 --------- src/compiler/nir/nir.h | 9 +++++++++ src/compiler/nir/nir_sweep.c | 8 +++++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c index c2f816c7bb6..eb05cea70bc 100644 --- a/src/compiler/nir/nir.c +++ b/src/compiler/nir/nir.c @@ -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) { diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 31a658c6e50..a41e9e36739 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -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); diff --git a/src/compiler/nir/nir_sweep.c b/src/compiler/nir/nir_sweep.c index bf6278af38a..29caf897193 100644 --- a/src/compiler/nir/nir_sweep.c +++ b/src/compiler/nir/nir_sweep.c @@ -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: