diff options
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_misc.cpp | 37 | ||||
-rw-r--r-- | src/gallium/auxiliary/gallivm/lp_bld_misc.h | 2 | ||||
-rw-r--r-- | src/gallium/targets/opencl/Makefile.am | 3 |
3 files changed, 34 insertions, 8 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp index 5e25819ac55..72fab8ccf06 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp @@ -81,6 +81,8 @@ # pragma pop_macro("DEBUG") #endif +#include "c11/threads.h" +#include "os/os_thread.h" #include "pipe/p_config.h" #include "util/u_debug.h" #include "util/u_cpu_detect.h" @@ -103,6 +105,33 @@ static LLVMEnsureMultithreaded lLVMEnsureMultithreaded; } +static once_flag init_native_targets_once_flag; + +static void init_native_targets() +{ + // If we have a native target, initialize it to ensure it is linked in and + // usable by the JIT. + llvm::InitializeNativeTarget(); + + llvm::InitializeNativeTargetAsmPrinter(); + + llvm::InitializeNativeTargetDisassembler(); +} + +/** + * The llvm target registry is not thread-safe, so drivers and state-trackers + * that want to initialize targets should use the gallivm_init_llvm_targets() + * function to safely initialize targets. + * + * LLVM targets should be initialized before the driver or state-tracker tries + * to access the registry. + */ +extern "C" void +gallivm_init_llvm_targets(void) +{ + call_once(&init_native_targets_once_flag, init_native_targets); +} + extern "C" void lp_set_target_options(void) { @@ -115,13 +144,7 @@ lp_set_target_options(void) llvm::DisablePrettyStackTrace = true; #endif - // If we have a native target, initialize it to ensure it is linked in and - // usable by the JIT. - llvm::InitializeNativeTarget(); - - llvm::InitializeNativeTargetAsmPrinter(); - - llvm::InitializeNativeTargetDisassembler(); + gallivm_init_llvm_targets(); } diff --git a/src/gallium/auxiliary/gallivm/lp_bld_misc.h b/src/gallium/auxiliary/gallivm/lp_bld_misc.h index 36923aa423f..86d2f86ac45 100644 --- a/src/gallium/auxiliary/gallivm/lp_bld_misc.h +++ b/src/gallium/auxiliary/gallivm/lp_bld_misc.h @@ -41,6 +41,8 @@ extern "C" { struct lp_generated_code; +extern void +gallivm_init_llvm_targets(void); extern void lp_set_target_options(void); diff --git a/src/gallium/targets/opencl/Makefile.am b/src/gallium/targets/opencl/Makefile.am index 4ab706ef2ac..c78b26832ff 100644 --- a/src/gallium/targets/opencl/Makefile.am +++ b/src/gallium/targets/opencl/Makefile.am @@ -35,7 +35,8 @@ lib@OPENCL_LIBNAME@_la_LIBADD = \ -lclangEdit \ -lclangLex \ -lclangBasic \ - $(LLVM_LIBS) + $(LLVM_LIBS) \ + $(PTHREAD_LIBS) nodist_EXTRA_lib@OPENCL_LIBNAME@_la_SOURCES = dummy.cpp lib@OPENCL_LIBNAME@_la_SOURCES = |