gallivm: Emit debug info for definitions

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28613>
This commit is contained in:
Konstantin Seurer 2024-04-06 14:34:21 +02:00 committed by Marge Bot
parent 77e84aba5c
commit 3f5a576c9e
3 changed files with 48 additions and 5 deletions

View file

@ -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);

View file

@ -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,

View file

@ -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) {