gallivm: rework debug printf hook to use global mapping.

Cached shaders require relinking, so hardcoding the pointer
can't work. This switches out the printf code to use new
proper API.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5049>
This commit is contained in:
Dave Airlie 2020-05-15 10:05:55 +10:00
parent f511d2a553
commit 333ee94285
3 changed files with 9 additions and 7 deletions

View File

@ -643,6 +643,9 @@ gallivm_compile_module(struct gallivm_state *gallivm)
++gallivm->compiled; ++gallivm->compiled;
if (gallivm->debug_printf_hook)
LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf);
if (gallivm_debug & GALLIVM_DEBUG_ASM) { if (gallivm_debug & GALLIVM_DEBUG_ASM) {
LLVMValueRef llvm_func = LLVMGetFirstFunction(gallivm->module); LLVMValueRef llvm_func = LLVMGetFirstFunction(gallivm->module);

View File

@ -54,6 +54,7 @@ struct gallivm_state
unsigned compiled; unsigned compiled;
LLVMValueRef coro_malloc_hook; LLVMValueRef coro_malloc_hook;
LLVMValueRef coro_free_hook; LLVMValueRef coro_free_hook;
LLVMValueRef debug_printf_hook;
}; };

View File

@ -48,8 +48,6 @@ lp_build_print_args(struct gallivm_state* gallivm,
{ {
LLVMBuilderRef builder = gallivm->builder; LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context; LLVMContextRef context = gallivm->context;
LLVMValueRef func_printf;
LLVMTypeRef printf_type;
int i; int i;
assert(args); assert(args);
@ -64,11 +62,11 @@ lp_build_print_args(struct gallivm_state* gallivm,
args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), ""); args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), "");
} }
printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1); if (!gallivm->debug_printf_hook) {
func_printf = lp_build_const_int_pointer(gallivm, func_to_pointer((func_pointer)debug_printf)); LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1);
func_printf = LLVMBuildBitCast(builder, func_printf, LLVMPointerType(printf_type, 0), "debug_printf"); gallivm->debug_printf_hook = LLVMAddFunction(gallivm->module, "debug_printf", printf_type);
}
return LLVMBuildCall(builder, func_printf, args, argcount, ""); return LLVMBuildCall(builder, gallivm->debug_printf_hook, args, argcount, "");
} }