From fae6a8737adb47b325e827c84a71bfb6d72be1c8 Mon Sep 17 00:00:00 2001 From: Yukari Chiba Date: Wed, 19 Jun 2024 16:22:13 +0800 Subject: [PATCH] llvmpipe: add gallivm_add_global_mapping Reviewed-by: Dave Airlie Part-of: --- src/gallium/auxiliary/gallivm/lp_bld_coro.c | 4 ++-- src/gallium/auxiliary/gallivm/lp_bld_init.c | 9 +++++++-- src/gallium/auxiliary/gallivm/lp_bld_init.h | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_coro.c b/src/gallium/auxiliary/gallivm/lp_bld_coro.c index 75aaa7d2b84..c2d6cc11cc6 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_coro.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_coro.c @@ -165,8 +165,8 @@ void lp_build_coro_add_malloc_hooks(struct gallivm_state *gallivm) assert(gallivm->coro_malloc_hook); assert(gallivm->coro_free_hook); - LLVMAddGlobalMapping(gallivm->engine, gallivm->coro_malloc_hook, coro_malloc); - LLVMAddGlobalMapping(gallivm->engine, gallivm->coro_free_hook, coro_free); + gallivm_add_global_mapping(gallivm, gallivm->coro_malloc_hook, coro_malloc); + gallivm_add_global_mapping(gallivm, gallivm->coro_free_hook, coro_free); } void lp_build_coro_declare_malloc_hooks(struct gallivm_state *gallivm) diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.c b/src/gallium/auxiliary/gallivm/lp_bld_init.c index 195cfa7cdc9..38daf0bc9dc 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.c +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.c @@ -420,6 +420,11 @@ gallivm_destroy(struct gallivm_state *gallivm) FREE(gallivm); } +void +gallivm_add_global_mapping(struct gallivm_state *gallivm, LLVMValueRef sym, void* addr) +{ + LLVMAddGlobalMapping(gallivm->engine, sym, addr); +} /** * Validate a function. @@ -522,10 +527,10 @@ gallivm_compile_module(struct gallivm_state *gallivm) ++gallivm->compiled; lp_init_printf_hook(gallivm); - LLVMAddGlobalMapping(gallivm->engine, gallivm->debug_printf_hook, debug_printf); + gallivm_add_global_mapping(gallivm, gallivm->debug_printf_hook, debug_printf); lp_init_clock_hook(gallivm); - LLVMAddGlobalMapping(gallivm->engine, gallivm->get_time_hook, os_time_get_nano); + gallivm_add_global_mapping(gallivm, gallivm->get_time_hook, os_time_get_nano); lp_build_coro_add_malloc_hooks(gallivm); diff --git a/src/gallium/auxiliary/gallivm/lp_bld_init.h b/src/gallium/auxiliary/gallivm/lp_bld_init.h index 62ad8a9a60a..b9ff4b376d0 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_init.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_init.h @@ -89,6 +89,14 @@ gallivm_verify_function(struct gallivm_state *gallivm, LLVMValueRef func); void +gallivm_add_global_mapping(struct gallivm_state *gallivm, LLVMValueRef sym, void* addr); + +/** + * for ORCJIT, after this function gets called, all access and modification to + * module and any structure associated to it should be avoided, + * as module has been moved into ORCJIT and may be recycled + */ +void gallivm_compile_module(struct gallivm_state *gallivm); func_pointer