diff --git a/src/gallium/auxiliary/gallivm/lp_bld_debug.h b/src/gallium/auxiliary/gallivm/lp_bld_debug.h index 9eb103369d5..13ca40de56c 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_debug.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_debug.h @@ -35,6 +35,8 @@ #include "util/compiler.h" #include "util/u_string.h" +#include + #define GALLIVM_DEBUG_TGSI (1 << 0) #define GALLIVM_DEBUG_IR (1 << 1) @@ -42,6 +44,7 @@ #define GALLIVM_DEBUG_PERF (1 << 3) #define GALLIVM_DEBUG_GC (1 << 4) #define GALLIVM_DEBUG_DUMP_BC (1 << 5) +#define GALLIVM_DEBUG_SYMBOLS (1 << 8) #define GALLIVM_PERF_BRILINEAR (1 << 0) #define GALLIVM_PERF_RHO_APPROX (1 << 1) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c index 8a4c5b0b58e..4ce233c83e1 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c @@ -92,8 +92,11 @@ gallivm_free_ir(struct gallivm_state *gallivm) lp_passmgr_dispose(gallivm->passmgr); if (gallivm->engine) { - /* This will already destroy any associated module */ - LLVMDisposeExecutionEngine(gallivm->engine); + /* This will already destroy any associated module. + *Destroy the execution engine later if we need to keep debug info around. + */ + if (!(gallivm_debug & GALLIVM_DEBUG_SYMBOLS)) + LLVMDisposeExecutionEngine(gallivm->engine); } else if (gallivm->module) { LLVMDisposeModule(gallivm->module); } @@ -111,6 +114,9 @@ gallivm_free_ir(struct gallivm_state *gallivm) if (gallivm->builder) LLVMDisposeBuilder(gallivm->builder); + if (gallivm->di_builder) + LLVMDisposeDIBuilder(gallivm->di_builder); + /* The LLVMContext should be owned by the parent of gallivm. */ gallivm->engine = NULL; @@ -284,6 +290,9 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name, if (!create_pass_manager(gallivm)) goto fail; + if (gallivm_debug & GALLIVM_DEBUG_SYMBOLS) + gallivm->di_builder = LLVMCreateDIBuilder(gallivm->module); + lp_build_coro_declare_malloc_hooks(gallivm); return true; @@ -349,6 +358,8 @@ void gallivm_destroy(struct gallivm_state *gallivm) { gallivm_free_ir(gallivm); + if (gallivm->engine) + LLVMDisposeExecutionEngine(gallivm->engine); gallivm_free_code(gallivm); FREE(gallivm); } @@ -373,6 +384,12 @@ gallivm_compile_module(struct gallivm_state *gallivm) gallivm->builder = NULL; } + if (gallivm->di_builder) { + LLVMDIBuilderFinalize(gallivm->di_builder); + LLVMDisposeDIBuilder(gallivm->di_builder); + gallivm->di_builder = NULL; + } + LLVMSetDataLayout(gallivm->module, ""); assert(!gallivm->engine); if (!init_gallivm_engine(gallivm)) { diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h index 6894e9ecac7..15bcc6cefb0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h @@ -65,6 +65,7 @@ struct gallivm_state #endif LLVMContextRef context; LLVMBuilderRef builder; + LLVMDIBuilderRef di_builder; struct lp_cached_code *cache; unsigned compiled; LLVMValueRef coro_malloc_hook; diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init_common.c b/src/gallium/auxiliary/gallivm/lp_bld_init_common.c index 0ab69acd11c..324555b6205 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init_common.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init_common.c @@ -58,6 +58,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = { #if MESA_DEBUG { "dumpbc", GALLIVM_DEBUG_DUMP_BC, NULL }, #endif + { "symbols", GALLIVM_DEBUG_SYMBOLS, NULL }, DEBUG_NAMED_VALUE_END }; @@ -83,6 +84,9 @@ lp_init_env_options(void) { gallivm_debug = debug_get_option_gallivm_debug(); + if (!__normal_user()) + gallivm_debug &= ~GALLIVM_DEBUG_SYMBOLS; + gallivm_perf = debug_get_flags_option("GALLIVM_PERF", lp_bld_perf_flags, 0 ); }