2121#if LLVM_VERSION_MAJOR > 16
2222#include <llvm-c/Transforms/PassBuilder.h>
2323#endif
24- #if LLVM_VERSION_MAJOR > 11
2524#include <llvm-c/Orc.h>
2625#include <llvm-c/OrcEE.h>
2726#include <llvm-c/LLJIT.h>
28- #else
29- #include <llvm-c/OrcBindings.h>
30- #endif
3127#include <llvm-c/Support.h>
3228#include <llvm-c/Target.h>
3329#if LLVM_VERSION_MAJOR < 17
5046/* Handle of a module emitted via ORC JIT */
5147typedef struct LLVMJitHandle
5248{
53- #if LLVM_VERSION_MAJOR > 11
5449 LLVMOrcLLJITRef lljit ;
5550 LLVMOrcResourceTrackerRef resource_tracker ;
56- #else
57- LLVMOrcJITStackRef stack ;
58- LLVMOrcModuleHandle orc_handle ;
59- #endif
6051} LLVMJitHandle ;
6152
6253
@@ -103,14 +94,9 @@ static LLVMContextRef llvm_context;
10394
10495
10596static LLVMTargetRef llvm_targetref ;
106- #if LLVM_VERSION_MAJOR > 11
10797static LLVMOrcThreadSafeContextRef llvm_ts_context ;
10898static LLVMOrcLLJITRef llvm_opt0_orc ;
10999static LLVMOrcLLJITRef llvm_opt3_orc ;
110- #else /* LLVM_VERSION_MAJOR > 11 */
111- static LLVMOrcJITStackRef llvm_opt0_orc ;
112- static LLVMOrcJITStackRef llvm_opt3_orc ;
113- #endif /* LLVM_VERSION_MAJOR > 11 */
114100
115101
116102static void llvm_release_context (JitContext * context );
@@ -124,10 +110,8 @@ static void llvm_set_target(void);
124110static void llvm_recreate_llvm_context (void );
125111static uint64_t llvm_resolve_symbol (const char * name , void * ctx );
126112
127- #if LLVM_VERSION_MAJOR > 11
128113static LLVMOrcLLJITRef llvm_create_jit_instance (LLVMTargetMachineRef tm );
129114static char * llvm_error_message (LLVMErrorRef error );
130- #endif /* LLVM_VERSION_MAJOR > 11 */
131115
132116/* ResourceOwner callbacks to hold JitContexts */
133117static void ResOwnerReleaseJitContext (Datum res );
@@ -292,7 +276,6 @@ llvm_release_context(JitContext *context)
292276 {
293277 LLVMJitHandle * jit_handle = (LLVMJitHandle * ) lfirst (lc );
294278
295- #if LLVM_VERSION_MAJOR > 11
296279 {
297280 LLVMOrcExecutionSessionRef ee ;
298281 LLVMOrcSymbolStringPoolRef sp ;
@@ -310,11 +293,6 @@ llvm_release_context(JitContext *context)
310293 sp = LLVMOrcExecutionSessionGetSymbolStringPool (ee );
311294 LLVMOrcSymbolStringPoolClearDeadEntries (sp );
312295 }
313- #else /* LLVM_VERSION_MAJOR > 11 */
314- {
315- LLVMOrcRemoveModule (jit_handle -> stack , jit_handle -> orc_handle );
316- }
317- #endif /* LLVM_VERSION_MAJOR > 11 */
318296
319297 pfree (jit_handle );
320298 }
@@ -397,7 +375,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
397375 * to mangle here.
398376 */
399377
400- #if LLVM_VERSION_MAJOR > 11
401378 foreach (lc , context -> handles )
402379 {
403380 LLVMJitHandle * handle = (LLVMJitHandle * ) lfirst (lc );
@@ -427,19 +404,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
427404 if (addr )
428405 return (void * ) (uintptr_t ) addr ;
429406 }
430- #else
431- foreach (lc , context -> handles )
432- {
433- LLVMOrcTargetAddress addr ;
434- LLVMJitHandle * handle = (LLVMJitHandle * ) lfirst (lc );
435-
436- addr = 0 ;
437- if (LLVMOrcGetSymbolAddressIn (handle -> stack , & addr , handle -> orc_handle , funcname ))
438- elog (ERROR , "failed to look up symbol \"%s\"" , funcname );
439- if (addr )
440- return (void * ) (uintptr_t ) addr ;
441- }
442- #endif
443407
444408 elog (ERROR , "failed to JIT: %s" , funcname );
445409
@@ -740,11 +704,7 @@ llvm_compile_module(LLVMJitContext *context)
740704 MemoryContext oldcontext ;
741705 instr_time starttime ;
742706 instr_time endtime ;
743- #if LLVM_VERSION_MAJOR > 11
744707 LLVMOrcLLJITRef compile_orc ;
745- #else
746- LLVMOrcJITStackRef compile_orc ;
747- #endif
748708
749709 if (context -> base .flags & PGJIT_OPT3 )
750710 compile_orc = llvm_opt3_orc ;
@@ -801,7 +761,6 @@ llvm_compile_module(LLVMJitContext *context)
801761 * faster instruction selection mechanism is used.
802762 */
803763 INSTR_TIME_SET_CURRENT (starttime );
804- #if LLVM_VERSION_MAJOR > 11
805764 {
806765 LLVMOrcThreadSafeModuleRef ts_module ;
807766 LLVMErrorRef error ;
@@ -829,16 +788,6 @@ llvm_compile_module(LLVMJitContext *context)
829788
830789 /* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
831790 }
832- #else
833- {
834- handle -> stack = compile_orc ;
835- if (LLVMOrcAddEagerlyCompiledIR (compile_orc , & handle -> orc_handle , context -> module ,
836- llvm_resolve_symbol , NULL ))
837- elog (ERROR , "failed to JIT module" );
838-
839- /* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
840- }
841- #endif
842791
843792 INSTR_TIME_SET_CURRENT (endtime );
844793 INSTR_TIME_ACCUM_DIFF (context -> base .instr .emission_counter ,
@@ -950,7 +899,6 @@ llvm_session_initialize(void)
950899 /* force symbols in main binary to be loaded */
951900 LLVMLoadLibraryPermanently (NULL );
952901
953- #if LLVM_VERSION_MAJOR > 11
954902 {
955903 llvm_ts_context = LLVMOrcCreateNewThreadSafeContext ();
956904
@@ -960,31 +908,6 @@ llvm_session_initialize(void)
960908 llvm_opt3_orc = llvm_create_jit_instance (opt3_tm );
961909 opt3_tm = 0 ;
962910 }
963- #else /* LLVM_VERSION_MAJOR > 11 */
964- {
965- llvm_opt0_orc = LLVMOrcCreateInstance (opt0_tm );
966- llvm_opt3_orc = LLVMOrcCreateInstance (opt3_tm );
967-
968- #if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER ) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
969- if (jit_debugging_support )
970- {
971- LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener ();
972-
973- LLVMOrcRegisterJITEventListener (llvm_opt0_orc , l );
974- LLVMOrcRegisterJITEventListener (llvm_opt3_orc , l );
975- }
976- #endif
977- #if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER ) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
978- if (jit_profiling_support )
979- {
980- LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener ();
981-
982- LLVMOrcRegisterJITEventListener (llvm_opt0_orc , l );
983- LLVMOrcRegisterJITEventListener (llvm_opt3_orc , l );
984- }
985- #endif
986- }
987- #endif /* LLVM_VERSION_MAJOR > 11 */
988911
989912 on_proc_exit (llvm_shutdown , 0 );
990913
@@ -1014,7 +937,6 @@ llvm_shutdown(int code, Datum arg)
1014937 elog (PANIC , "LLVMJitContext in use count not 0 at exit (is %zu)" ,
1015938 llvm_jit_context_in_use_count );
1016939
1017- #if LLVM_VERSION_MAJOR > 11
1018940 {
1019941 if (llvm_opt3_orc )
1020942 {
@@ -1032,23 +954,6 @@ llvm_shutdown(int code, Datum arg)
1032954 llvm_ts_context = NULL ;
1033955 }
1034956 }
1035- #else /* LLVM_VERSION_MAJOR > 11 */
1036- {
1037- /* unregister profiling support, needs to be flushed to be useful */
1038-
1039- if (llvm_opt3_orc )
1040- {
1041- LLVMOrcDisposeInstance (llvm_opt3_orc );
1042- llvm_opt3_orc = NULL ;
1043- }
1044-
1045- if (llvm_opt0_orc )
1046- {
1047- LLVMOrcDisposeInstance (llvm_opt0_orc );
1048- llvm_opt0_orc = NULL ;
1049- }
1050- }
1051- #endif /* LLVM_VERSION_MAJOR > 11 */
1052957}
1053958
1054959/* helper for llvm_create_types, returning a function's return type */
@@ -1218,8 +1123,6 @@ llvm_resolve_symbol(const char *symname, void *ctx)
12181123 return (uint64_t ) addr ;
12191124}
12201125
1221- #if LLVM_VERSION_MAJOR > 11
1222-
12231126static LLVMErrorRef
12241127llvm_resolve_symbols (LLVMOrcDefinitionGeneratorRef GeneratorObj , void * Ctx ,
12251128 LLVMOrcLookupStateRef * LookupState , LLVMOrcLookupKind Kind ,
@@ -1238,9 +1141,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
12381141 {
12391142 const char * name = LLVMOrcSymbolStringPoolEntryStr (LookupSet [i ].Name );
12401143
1241- #if LLVM_VERSION_MAJOR > 12
12421144 LLVMOrcRetainSymbolStringPoolEntry (LookupSet [i ].Name );
1243- #endif
12441145 symbols [i ].Name = LookupSet [i ].Name ;
12451146 symbols [i ].Sym .Address = llvm_resolve_symbol (name , NULL );
12461147 symbols [i ].Sym .Flags .GenericFlags = LLVMJITSymbolGenericFlagsExported ;
@@ -1369,8 +1270,6 @@ llvm_error_message(LLVMErrorRef error)
13691270 return msg ;
13701271}
13711272
1372- #endif /* LLVM_VERSION_MAJOR > 11 */
1373-
13741273/*
13751274 * ResourceOwner callbacks
13761275 */
0 commit comments