gallivm: orcjit: use atexit to release LPJit singleton at exit

Valgrind will report some memory possibly lost because of this singleton
(it's dynamically allocated when it is first accessed).

Use atexit() to register a handler that releases this singleton.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30216>
This commit is contained in:
Icenowy Zheng 2024-07-18 12:09:28 +08:00 committed by Marge Bot
parent 3423e73cec
commit 5f22e152ad

View file

@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include <mutex>
#include <cstdlib>
#include "lp_bld.h"
#include "lp_bld_debug.h"
#include "lp_bld_init.h"
@ -102,6 +103,8 @@ public:
class LPJit;
void lpjit_exit();
class LLVMEnsureMultithreaded {
public:
LLVMEnsureMultithreaded()
@ -270,11 +273,14 @@ private:
LPJit(const LPJit&) = delete;
LPJit& operator=(const LPJit&) = delete;
friend void lpjit_exit();
static void init_native_targets();
llvm::orc::JITTargetMachineBuilder create_jtdb();
static void init_lpjit() {
jit = new LPJit;
std::atexit(lpjit_exit);
}
static LPJit* jit;
@ -293,6 +299,11 @@ private:
LPJit* LPJit::jit = NULL;
void lpjit_exit()
{
delete LPJit::jit;
}
LLVMErrorRef module_transform(void *Ctx, LLVMModuleRef mod) {
struct lp_passmgr *mgr;