21
21
#if LLVM_VERSION_MAJOR > 16
22
22
#include <llvm-c/Transforms/PassBuilder.h>
23
23
#endif
24
- #if LLVM_VERSION_MAJOR > 11
25
24
#include <llvm-c/Orc.h>
26
25
#include <llvm-c/OrcEE.h>
27
26
#include <llvm-c/LLJIT.h>
28
- #else
29
- #include <llvm-c/OrcBindings.h>
30
- #endif
31
27
#include <llvm-c/Support.h>
32
28
#include <llvm-c/Target.h>
33
29
#if LLVM_VERSION_MAJOR < 17
50
46
/* Handle of a module emitted via ORC JIT */
51
47
typedef struct LLVMJitHandle
52
48
{
53
- #if LLVM_VERSION_MAJOR > 11
54
49
LLVMOrcLLJITRef lljit ;
55
50
LLVMOrcResourceTrackerRef resource_tracker ;
56
- #else
57
- LLVMOrcJITStackRef stack ;
58
- LLVMOrcModuleHandle orc_handle ;
59
- #endif
60
51
} LLVMJitHandle ;
61
52
62
53
@@ -103,14 +94,9 @@ static LLVMContextRef llvm_context;
103
94
104
95
105
96
static LLVMTargetRef llvm_targetref ;
106
- #if LLVM_VERSION_MAJOR > 11
107
97
static LLVMOrcThreadSafeContextRef llvm_ts_context ;
108
98
static LLVMOrcLLJITRef llvm_opt0_orc ;
109
99
static 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 */
114
100
115
101
116
102
static void llvm_release_context (JitContext * context );
@@ -124,10 +110,8 @@ static void llvm_set_target(void);
124
110
static void llvm_recreate_llvm_context (void );
125
111
static uint64_t llvm_resolve_symbol (const char * name , void * ctx );
126
112
127
- #if LLVM_VERSION_MAJOR > 11
128
113
static LLVMOrcLLJITRef llvm_create_jit_instance (LLVMTargetMachineRef tm );
129
114
static char * llvm_error_message (LLVMErrorRef error );
130
- #endif /* LLVM_VERSION_MAJOR > 11 */
131
115
132
116
/* ResourceOwner callbacks to hold JitContexts */
133
117
static void ResOwnerReleaseJitContext (Datum res );
@@ -292,7 +276,6 @@ llvm_release_context(JitContext *context)
292
276
{
293
277
LLVMJitHandle * jit_handle = (LLVMJitHandle * ) lfirst (lc );
294
278
295
- #if LLVM_VERSION_MAJOR > 11
296
279
{
297
280
LLVMOrcExecutionSessionRef ee ;
298
281
LLVMOrcSymbolStringPoolRef sp ;
@@ -310,11 +293,6 @@ llvm_release_context(JitContext *context)
310
293
sp = LLVMOrcExecutionSessionGetSymbolStringPool (ee );
311
294
LLVMOrcSymbolStringPoolClearDeadEntries (sp );
312
295
}
313
- #else /* LLVM_VERSION_MAJOR > 11 */
314
- {
315
- LLVMOrcRemoveModule (jit_handle -> stack , jit_handle -> orc_handle );
316
- }
317
- #endif /* LLVM_VERSION_MAJOR > 11 */
318
296
319
297
pfree (jit_handle );
320
298
}
@@ -397,7 +375,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
397
375
* to mangle here.
398
376
*/
399
377
400
- #if LLVM_VERSION_MAJOR > 11
401
378
foreach (lc , context -> handles )
402
379
{
403
380
LLVMJitHandle * handle = (LLVMJitHandle * ) lfirst (lc );
@@ -427,19 +404,6 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
427
404
if (addr )
428
405
return (void * ) (uintptr_t ) addr ;
429
406
}
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
443
407
444
408
elog (ERROR , "failed to JIT: %s" , funcname );
445
409
@@ -740,11 +704,7 @@ llvm_compile_module(LLVMJitContext *context)
740
704
MemoryContext oldcontext ;
741
705
instr_time starttime ;
742
706
instr_time endtime ;
743
- #if LLVM_VERSION_MAJOR > 11
744
707
LLVMOrcLLJITRef compile_orc ;
745
- #else
746
- LLVMOrcJITStackRef compile_orc ;
747
- #endif
748
708
749
709
if (context -> base .flags & PGJIT_OPT3 )
750
710
compile_orc = llvm_opt3_orc ;
@@ -801,7 +761,6 @@ llvm_compile_module(LLVMJitContext *context)
801
761
* faster instruction selection mechanism is used.
802
762
*/
803
763
INSTR_TIME_SET_CURRENT (starttime );
804
- #if LLVM_VERSION_MAJOR > 11
805
764
{
806
765
LLVMOrcThreadSafeModuleRef ts_module ;
807
766
LLVMErrorRef error ;
@@ -829,16 +788,6 @@ llvm_compile_module(LLVMJitContext *context)
829
788
830
789
/* LLVMOrcLLJITAddLLVMIRModuleWithRT takes ownership of the module */
831
790
}
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
842
791
843
792
INSTR_TIME_SET_CURRENT (endtime );
844
793
INSTR_TIME_ACCUM_DIFF (context -> base .instr .emission_counter ,
@@ -950,7 +899,6 @@ llvm_session_initialize(void)
950
899
/* force symbols in main binary to be loaded */
951
900
LLVMLoadLibraryPermanently (NULL );
952
901
953
- #if LLVM_VERSION_MAJOR > 11
954
902
{
955
903
llvm_ts_context = LLVMOrcCreateNewThreadSafeContext ();
956
904
@@ -960,31 +908,6 @@ llvm_session_initialize(void)
960
908
llvm_opt3_orc = llvm_create_jit_instance (opt3_tm );
961
909
opt3_tm = 0 ;
962
910
}
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 */
988
911
989
912
on_proc_exit (llvm_shutdown , 0 );
990
913
@@ -1014,7 +937,6 @@ llvm_shutdown(int code, Datum arg)
1014
937
elog (PANIC , "LLVMJitContext in use count not 0 at exit (is %zu)" ,
1015
938
llvm_jit_context_in_use_count );
1016
939
1017
- #if LLVM_VERSION_MAJOR > 11
1018
940
{
1019
941
if (llvm_opt3_orc )
1020
942
{
@@ -1032,23 +954,6 @@ llvm_shutdown(int code, Datum arg)
1032
954
llvm_ts_context = NULL ;
1033
955
}
1034
956
}
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 */
1052
957
}
1053
958
1054
959
/* helper for llvm_create_types, returning a function's return type */
@@ -1218,8 +1123,6 @@ llvm_resolve_symbol(const char *symname, void *ctx)
1218
1123
return (uint64_t ) addr ;
1219
1124
}
1220
1125
1221
- #if LLVM_VERSION_MAJOR > 11
1222
-
1223
1126
static LLVMErrorRef
1224
1127
llvm_resolve_symbols (LLVMOrcDefinitionGeneratorRef GeneratorObj , void * Ctx ,
1225
1128
LLVMOrcLookupStateRef * LookupState , LLVMOrcLookupKind Kind ,
@@ -1238,9 +1141,7 @@ llvm_resolve_symbols(LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx,
1238
1141
{
1239
1142
const char * name = LLVMOrcSymbolStringPoolEntryStr (LookupSet [i ].Name );
1240
1143
1241
- #if LLVM_VERSION_MAJOR > 12
1242
1144
LLVMOrcRetainSymbolStringPoolEntry (LookupSet [i ].Name );
1243
- #endif
1244
1145
symbols [i ].Name = LookupSet [i ].Name ;
1245
1146
symbols [i ].Sym .Address = llvm_resolve_symbol (name , NULL );
1246
1147
symbols [i ].Sym .Flags .GenericFlags = LLVMJITSymbolGenericFlagsExported ;
@@ -1369,8 +1270,6 @@ llvm_error_message(LLVMErrorRef error)
1369
1270
return msg ;
1370
1271
}
1371
1272
1372
- #endif /* LLVM_VERSION_MAJOR > 11 */
1373
-
1374
1273
/*
1375
1274
* ResourceOwner callbacks
1376
1275
*/
0 commit comments