From cf94cb58665a784acdf2091351b8c1ecb633263c Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Wed, 19 Oct 2022 22:38:58 +1300 Subject: Track LLVM 15 changes. Per https://llvm.org/docs/OpaquePointers.html, support for non-opaque pointers still exists and we can request that on our context. We have until LLVM 16 to move to opaque pointers, a much larger change. Back-patch to 11, where LLVM support arrived. Author: Thomas Munro Author: Andres Freund Discussion: https://postgr.es/m/CAMHz58Sf_xncdyqsekoVsNeKcruKootLtVH6cYXVhhUR1oKPCg%40mail.gmail.com --- src/backend/jit/llvm/llvmjit.c | 18 ++++++++++++++++++ src/backend/jit/llvm/llvmjit_inline.cpp | 1 + 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 8babf09f2a6..11678eb0136 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -757,6 +757,16 @@ llvm_session_initialize(void) LLVMInitializeNativeAsmPrinter(); LLVMInitializeNativeAsmParser(); + /* + * When targeting an LLVM version with opaque pointers enabled by + * default, turn them off for the context we build our code in. We don't + * need to do so for other contexts (e.g. llvm_ts_context). Once the IR is + * generated, it carries the necessary information. + */ +#if LLVM_VERSION_MAJOR > 14 + LLVMContextSetOpaquePointers(LLVMGetGlobalContext(), false); +#endif + /* * Synchronize types early, as that also includes inferring the target * triple. @@ -1091,7 +1101,11 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags, LLVMOrcCLookupSet LookupSet, size_t LookupSetSize) { +#if LLVM_VERSION_MAJOR > 14 + LLVMOrcCSymbolMapPairs symbols = palloc0(sizeof(LLVMOrcCSymbolMapPair) * LookupSetSize); +#else LLVMOrcCSymbolMapPairs symbols = palloc0(sizeof(LLVMJITCSymbolMapPair) * LookupSetSize); +#endif LLVMErrorRef error; LLVMOrcMaterializationUnitRef mu; @@ -1209,7 +1223,11 @@ llvm_create_jit_instance(LLVMTargetMachineRef tm) * Symbol resolution support for "special" functions, e.g. a call into an * SQL callable function. */ +#if LLVM_VERSION_MAJOR > 14 + ref_gen = LLVMOrcCreateCustomCAPIDefinitionGenerator(llvm_resolve_symbols, NULL, NULL); +#else ref_gen = LLVMOrcCreateCustomCAPIDefinitionGenerator(llvm_resolve_symbols, NULL); +#endif LLVMOrcJITDylibAddGenerator(LLVMOrcLLJITGetMainJITDylib(lljit), ref_gen); return lljit; diff --git a/src/backend/jit/llvm/llvmjit_inline.cpp b/src/backend/jit/llvm/llvmjit_inline.cpp index 01168cab41b..f675d0f9dbe 100644 --- a/src/backend/jit/llvm/llvmjit_inline.cpp +++ b/src/backend/jit/llvm/llvmjit_inline.cpp @@ -62,6 +62,7 @@ extern "C" #include #include #include +#include /* -- cgit v1.2.3