summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2020-05-15 10:05:55 +1000
committerDave Airlie <airlied@redhat.com>2020-06-11 06:05:40 +1000
commit333ee94285ac453b9d75ce93b01bc26e48bf96d7 (patch)
treeb68d4cae48551f2dc4b605e6da8e53325f528a15
parentf511d2a553377a58b5eea6c6d1170fcc4972237a (diff)
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>
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.c3
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_init.h1
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_printf.c12
3 files changed, 9 insertions, 7 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c
index e3fd26cd2ec..ce522806669 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c
@@ -643,6 +643,9 @@ gallivm_compile_module(struct gallivm_state *gallivm)
++gallivm->compiled;
+ if (gallivm->debug_printf_hook)
+ LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf);
+
if (gallivm_debug & GALLIVM_DEBUG_ASM) {
LLVMValueRef llvm_func = LLVMGetFirstFunction(gallivm->module);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h
index 1c0c627fb59..cebf6a793d5 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_init.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h
@@ -54,6 +54,7 @@ struct gallivm_state
unsigned compiled;
LLVMValueRef coro_malloc_hook;
LLVMValueRef coro_free_hook;
+ LLVMValueRef debug_printf_hook;
};
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_printf.c b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
index a4233a24e33..1772fd0e8cd 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_printf.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_printf.c
@@ -48,8 +48,6 @@ lp_build_print_args(struct gallivm_state* gallivm,
{
LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context;
- LLVMValueRef func_printf;
- LLVMTypeRef printf_type;
int i;
assert(args);
@@ -64,11 +62,11 @@ lp_build_print_args(struct gallivm_state* gallivm,
args[i] = LLVMBuildFPExt(builder, args[i], LLVMDoubleTypeInContext(context), "");
}
- printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1);
- func_printf = lp_build_const_int_pointer(gallivm, func_to_pointer((func_pointer)debug_printf));
- func_printf = LLVMBuildBitCast(builder, func_printf, LLVMPointerType(printf_type, 0), "debug_printf");
-
- return LLVMBuildCall(builder, func_printf, args, argcount, "");
+ if (!gallivm->debug_printf_hook) {
+ LLVMTypeRef printf_type = LLVMFunctionType(LLVMInt32TypeInContext(context), NULL, 0, 1);
+ gallivm->debug_printf_hook = LLVMAddFunction(gallivm->module, "debug_printf", printf_type);
+ }
+ return LLVMBuildCall(builder, gallivm->debug_printf_hook, args, argcount, "");
}