diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:18:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:18:03 +0000 |
commit | b4b8efbd3826ac0af2d1c2e7c40fcf80a4bfba45 (patch) | |
tree | bec866278030c41c624a91037b1dd88f41c99d8e /src/include/jit | |
parent | Adding upstream version 15.5. (diff) | |
download | postgresql-15-b4b8efbd3826ac0af2d1c2e7c40fcf80a4bfba45.tar.xz postgresql-15-b4b8efbd3826ac0af2d1c2e7c40fcf80a4bfba45.zip |
Adding upstream version 15.6.upstream/15.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/include/jit/llvmjit.h | 8 | ||||
-rw-r--r-- | src/include/jit/llvmjit_emit.h | 30 |
2 files changed, 26 insertions, 12 deletions
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h index fe769e0..08fac9e 100644 --- a/src/include/jit/llvmjit.h +++ b/src/include/jit/llvmjit.h @@ -42,6 +42,13 @@ typedef struct LLVMJitContext /* number of modules created */ size_t module_generation; + /* + * The LLVM Context used by this JIT context. An LLVM context is reused + * across many compilations, but occasionally reset to prevent it using + * too much memory due to more and more types accumulating. + */ + LLVMContextRef llvm_context; + /* current, "open for write", module */ LLVMModuleRef module; @@ -107,6 +114,7 @@ extern LLVMValueRef llvm_function_reference(LLVMJitContext *context, LLVMModuleRef mod, FunctionCallInfo fcinfo); +extern void llvm_inline_reset_caches(void); extern void llvm_inline(LLVMModuleRef mod); /* diff --git a/src/include/jit/llvmjit_emit.h b/src/include/jit/llvmjit_emit.h index 27a080b..0a0f876 100644 --- a/src/include/jit/llvmjit_emit.h +++ b/src/include/jit/llvmjit_emit.h @@ -45,36 +45,36 @@ l_ptr(LLVMTypeRef t) * Emit constant integer. */ static inline LLVMValueRef -l_int8_const(int8 i) +l_int8_const(LLVMContextRef lc, int8 i) { - return LLVMConstInt(LLVMInt8Type(), i, false); + return LLVMConstInt(LLVMInt8TypeInContext(lc), i, false); } /* * Emit constant integer. */ static inline LLVMValueRef -l_int16_const(int16 i) +l_int16_const(LLVMContextRef lc, int16 i) { - return LLVMConstInt(LLVMInt16Type(), i, false); + return LLVMConstInt(LLVMInt16TypeInContext(lc), i, false); } /* * Emit constant integer. */ static inline LLVMValueRef -l_int32_const(int32 i) +l_int32_const(LLVMContextRef lc, int32 i) { - return LLVMConstInt(LLVMInt32Type(), i, false); + return LLVMConstInt(LLVMInt32TypeInContext(lc), i, false); } /* * Emit constant integer. */ static inline LLVMValueRef -l_int64_const(int64 i) +l_int64_const(LLVMContextRef lc, int64 i) { - return LLVMConstInt(LLVMInt64Type(), i, false); + return LLVMConstInt(LLVMInt64TypeInContext(lc), i, false); } /* @@ -177,12 +177,15 @@ l_bb_before_v(LLVMBasicBlockRef r, const char *fmt,...) { char buf[512]; va_list args; + LLVMContextRef lc; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); - return LLVMInsertBasicBlock(r, buf); + lc = LLVMGetTypeContext(LLVMTypeOf(LLVMGetBasicBlockParent(r))); + + return LLVMInsertBasicBlockInContext(lc, r, buf); } /* separate, because pg_attribute_printf(2, 3) can't appear in definition */ @@ -197,12 +200,15 @@ l_bb_append_v(LLVMValueRef f, const char *fmt,...) { char buf[512]; va_list args; + LLVMContextRef lc; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); - return LLVMAppendBasicBlock(f, buf); + lc = LLVMGetTypeContext(LLVMTypeOf(f)); + + return LLVMAppendBasicBlockInContext(lc, f, buf); } /* @@ -214,7 +220,7 @@ l_callsite_ro(LLVMValueRef f) const char argname[] = "readonly"; LLVMAttributeRef ref; - ref = LLVMCreateStringAttribute(LLVMGetGlobalContext(), + ref = LLVMCreateStringAttribute(LLVMGetTypeContext(LLVMTypeOf(f)), argname, sizeof(argname) - 1, NULL, 0); @@ -234,7 +240,7 @@ l_callsite_alwaysinline(LLVMValueRef f) id = LLVMGetEnumAttributeKindForName(argname, sizeof(argname) - 1); - attr = LLVMCreateEnumAttribute(LLVMGetGlobalContext(), id, 0); + attr = LLVMCreateEnumAttribute(LLVMGetTypeContext(LLVMTypeOf(f)), id, 0); LLVMAddCallSiteAttribute(f, LLVMAttributeFunctionIndex, attr); } |