gallivm: orcjit: remember Context in addition to ThreadSafeContext
The llvm::orc::ThreadSafeContext object wraps an llvm::Context and keeps
its reference.
As we are no longer able to squeeze out Context from ThreadSafeContext
in LLVM 21, do not let ThreadSafeContext create Context implicitly for
LLVM 21, instead explicitly create Context and then remember it.
This also eliminates the code creating a Context that is never disposed.
Fixes: cd129dbf8a ("gallivm: support LLVM 21")
Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37684>
This commit is contained in:
@@ -88,10 +88,9 @@
|
||||
#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
|
||||
|
||||
typedef struct lp_context_ref {
|
||||
#if GALLIVM_USE_ORCJIT
|
||||
LLVMOrcThreadSafeContextRef ref;
|
||||
#else
|
||||
LLVMContextRef ref;
|
||||
#if GALLIVM_USE_ORCJIT
|
||||
LLVMOrcThreadSafeContextRef tsref;
|
||||
#endif
|
||||
bool owned;
|
||||
} lp_context_ref;
|
||||
@@ -101,18 +100,21 @@ lp_context_create(lp_context_ref *context)
|
||||
{
|
||||
assert(context != NULL);
|
||||
#if GALLIVM_USE_ORCJIT
|
||||
context->ref = LLVMOrcCreateNewThreadSafeContext();
|
||||
#if LLVM_VERSION_MAJOR >= 21
|
||||
context->ref = LLVMContextCreate();
|
||||
/* Ownership of ref is then transferred to tsref */
|
||||
context->tsref = LLVMOrcCreateNewThreadSafeContextFromLLVMContext(context->ref);
|
||||
#else
|
||||
context->tsref = LLVMOrcCreateNewThreadSafeContext();
|
||||
context->ref = LLVMOrcThreadSafeContextGetContext(context->tsref);
|
||||
#endif
|
||||
#else
|
||||
context->ref = LLVMContextCreate();
|
||||
#endif
|
||||
context->owned = true;
|
||||
#if LLVM_VERSION_MAJOR == 15
|
||||
if (context->ref) {
|
||||
#if GALLIVM_USE_ORCJIT
|
||||
LLVMContextSetOpaquePointers(LLVMOrcThreadSafeContextGetContext(context->ref), false);
|
||||
#else
|
||||
LLVMContextSetOpaquePointers(context->ref, false);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -123,7 +125,7 @@ lp_context_destroy(lp_context_ref *context)
|
||||
assert(context != NULL);
|
||||
if (context->owned) {
|
||||
#if GALLIVM_USE_ORCJIT
|
||||
LLVMOrcDisposeThreadSafeContext(context->ref);
|
||||
LLVMOrcDisposeThreadSafeContext(context->tsref);
|
||||
#else
|
||||
LLVMContextDispose(context->ref);
|
||||
#endif
|
||||
|
||||
@@ -555,8 +555,8 @@ init_gallivm_state(struct gallivm_state *gallivm, const char *name,
|
||||
|
||||
gallivm->cache = cache;
|
||||
|
||||
gallivm->_ts_context = context->ref;
|
||||
gallivm->context = LLVMContextCreate();
|
||||
gallivm->_ts_context = context->tsref;
|
||||
gallivm->context = context->ref;
|
||||
|
||||
gallivm->module_name = LPJit::get_unique_name(name);
|
||||
gallivm->module = LLVMModuleCreateWithNameInContext(gallivm->module_name,
|
||||
|
||||
Reference in New Issue
Block a user