diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.c b/src/gallium/auxiliary/gallivm/lp_bld_flow.c index 8858aac9cb4..ff3440cf803 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_flow.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.c @@ -481,8 +481,8 @@ lp_build_endif(struct lp_build_if_state *ifthen) } -static LLVMBuilderRef -create_builder_at_entry(struct gallivm_state *gallivm) +LLVMBuilderRef +lp_create_builder_at_entry(struct gallivm_state *gallivm) { LLVMBuilderRef builder = gallivm->builder; LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder); @@ -522,7 +522,7 @@ lp_build_alloca(struct gallivm_state *gallivm, const char *name) { LLVMBuilderRef builder = gallivm->builder; - LLVMBuilderRef first_builder = create_builder_at_entry(gallivm); + LLVMBuilderRef first_builder = lp_create_builder_at_entry(gallivm); LLVMValueRef res; res = LLVMBuildAlloca(first_builder, type, name); @@ -542,7 +542,7 @@ lp_build_alloca_undef(struct gallivm_state *gallivm, LLVMTypeRef type, const char *name) { - LLVMBuilderRef first_builder = create_builder_at_entry(gallivm); + LLVMBuilderRef first_builder = lp_create_builder_at_entry(gallivm); LLVMValueRef res; res = LLVMBuildAlloca(first_builder, type, name); @@ -573,7 +573,7 @@ lp_build_array_alloca(struct gallivm_state *gallivm, LLVMValueRef count, const char *name) { - LLVMBuilderRef first_builder = create_builder_at_entry(gallivm); + LLVMBuilderRef first_builder = lp_create_builder_at_entry(gallivm); LLVMValueRef res; res = LLVMBuildArrayAlloca(first_builder, type, count, name); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_flow.h b/src/gallium/auxiliary/gallivm/lp_bld_flow.h index c79502af5c4..f1d034ca0a2 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_flow.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_flow.h @@ -203,6 +203,9 @@ lp_build_endif(struct lp_build_if_state *ctx); LLVMBasicBlockRef lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name); +LLVMBuilderRef +lp_create_builder_at_entry(struct gallivm_state *gallivm); + LLVMValueRef lp_build_alloca(struct gallivm_state *gallivm, LLVMTypeRef type, diff --git a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c index 1ceaed1955a..d994619bd94 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_nir_soa.c @@ -2929,6 +2929,46 @@ assign_ssa_dest(struct lp_build_nir_soa_context *bld, const nir_def *ssa, struct gallivm_state *gallivm = bld->base.gallivm; LLVMBuilderRef builder = gallivm->builder; + if (gallivm->di_builder && ssa->parent_instr->has_debug_info) { + nir_instr_debug_info *debug_info = nir_instr_get_debug_info(ssa->parent_instr); + + /* Use "ssa_%u" because GDB cannot handle "%%%u" */ + char name[16]; + snprintf(name, sizeof(name), "ssa_%u", ssa->index); + + LLVMTypeRef type = LLVMTypeOf(vals[0]); + if (ssa->num_components > 1) + type = LLVMArrayType(type, ssa->num_components); + + LLVMBuilderRef first_builder = lp_create_builder_at_entry(gallivm); + LLVMValueRef var = LLVMBuildAlloca(first_builder, type, name); + LLVMBuildStore(first_builder, LLVMConstNull(type), var); + LLVMDisposeBuilder(first_builder); + + if (ssa->num_components > 1) + LLVMBuildStore(builder, lp_nir_array_build_gather_values(builder, vals, ssa->num_components), var); + else + LLVMBuildStore(builder, vals[0], var); + + LLVMMetadataRef di_type = lp_bld_debug_info_type(gallivm, type); + LLVMMetadataRef di_var = LLVMDIBuilderCreateAutoVariable( + gallivm->di_builder, gallivm->di_function, name, strlen(name), + gallivm->file, debug_info->line, di_type, true, LLVMDIFlagZero, 0); + + LLVMMetadataRef di_expr = LLVMDIBuilderCreateExpression(gallivm->di_builder, NULL, 0); + + LLVMMetadataRef di_loc = LLVMDIBuilderCreateDebugLocation( + gallivm->context, debug_info->line, debug_info->column, gallivm->di_function, NULL); + +#if LLVM_VERSION_MAJOR >= 19 + LLVMDIBuilderInsertDeclareRecordAtEnd(gallivm->di_builder, var, di_var, di_expr, di_loc, + LLVMGetInsertBlock(builder)); +#else + LLVMDIBuilderInsertDeclareAtEnd(gallivm->di_builder, var, di_var, di_expr, di_loc, + LLVMGetInsertBlock(builder)); +#endif + } + bool used_by_uniform = false; bool used_by_divergent = false; nir_foreach_use_including_if(use, ssa) {