@@ -85,8 +85,10 @@ LLVMTypeRef StructExprState;
85
85
LLVMTypeRef StructAggState ;
86
86
LLVMTypeRef StructAggStatePerGroupData ;
87
87
LLVMTypeRef StructAggStatePerTransData ;
88
+ LLVMTypeRef StructPlanState ;
88
89
89
90
LLVMValueRef AttributeTemplate ;
91
+ LLVMValueRef ExecEvalSubroutineTemplate ;
90
92
91
93
LLVMModuleRef llvm_types_module = NULL ;
92
94
@@ -369,6 +371,45 @@ llvm_get_function(LLVMJitContext *context, const char *funcname)
369
371
return NULL ;
370
372
}
371
373
374
+ /*
375
+ * Return type of a variable in llvmjit_types.c. This is useful to keep types
376
+ * in sync between plain C and JIT related code.
377
+ */
378
+ LLVMTypeRef
379
+ llvm_pg_var_type (const char * varname )
380
+ {
381
+ LLVMValueRef v_srcvar ;
382
+ LLVMTypeRef typ ;
383
+
384
+ /* this'll return a *pointer* to the global */
385
+ v_srcvar = LLVMGetNamedGlobal (llvm_types_module ,varname );
386
+ if (!v_srcvar )
387
+ elog (ERROR ,"variable %s not in llvmjit_types.c" ,varname );
388
+
389
+ typ = LLVMGlobalGetValueType (v_srcvar );
390
+
391
+ return typ ;
392
+ }
393
+
394
+ /*
395
+ * Return function type of a variable in llvmjit_types.c. This is useful to
396
+ * keep function types in sync between C and JITed code.
397
+ */
398
+ LLVMTypeRef
399
+ llvm_pg_var_func_type (const char * varname )
400
+ {
401
+ LLVMValueRef v_srcvar ;
402
+ LLVMTypeRef typ ;
403
+
404
+ v_srcvar = LLVMGetNamedFunction (llvm_types_module ,varname );
405
+ if (!v_srcvar )
406
+ elog (ERROR ,"function %s not in llvmjit_types.c" ,varname );
407
+
408
+ typ = LLVMGetFunctionType (v_srcvar );
409
+
410
+ return typ ;
411
+ }
412
+
372
413
/*
373
414
* Return declaration for a function referenced in llvmjit_types.c, adding it
374
415
* to the module if necessary.
@@ -394,7 +435,7 @@ llvm_pg_func(LLVMModuleRef mod, const char *funcname)
394
435
395
436
v_fn = LLVMAddFunction (mod ,
396
437
funcname ,
397
- LLVMGetElementType ( LLVMTypeOf ( v_srcfn ) ));
438
+ LLVMGetFunctionType ( v_srcfn ));
398
439
llvm_copy_attributes (v_srcfn ,v_fn );
399
440
400
441
return v_fn ;
@@ -490,7 +531,7 @@ llvm_function_reference(LLVMJitContext *context,
490
531
fcinfo -> flinfo -> fn_oid );
491
532
v_fn = LLVMGetNamedGlobal (mod ,funcname );
492
533
if (v_fn != 0 )
493
- return LLVMBuildLoad (builder ,v_fn ,"" );
534
+ return l_load (builder , TypePGFunction ,v_fn ,"" );
494
535
495
536
v_fn_addr = l_ptr_const (fcinfo -> flinfo -> fn_addr ,TypePGFunction );
496
537
@@ -500,15 +541,15 @@ llvm_function_reference(LLVMJitContext *context,
500
541
LLVMSetLinkage (v_fn ,LLVMPrivateLinkage );
501
542
LLVMSetUnnamedAddr (v_fn , true);
502
543
503
- return LLVMBuildLoad (builder ,v_fn ,"" );
544
+ return l_load (builder , TypePGFunction ,v_fn ,"" );
504
545
}
505
546
506
547
/* check if function already has been added */
507
548
v_fn = LLVMGetNamedFunction (mod ,funcname );
508
549
if (v_fn != 0 )
509
550
return v_fn ;
510
551
511
- v_fn = LLVMAddFunction (mod ,funcname ,LLVMGetElementType ( TypePGFunction ));
552
+ v_fn = LLVMAddFunction (mod ,funcname ,LLVMGetFunctionType ( AttributeTemplate ));
512
553
513
554
return v_fn ;
514
555
}
@@ -760,12 +801,15 @@ llvm_session_initialize(void)
760
801
LLVMInitializeNativeAsmParser ();
761
802
762
803
/*
763
- * When targeting an LLVM version with opaque pointers enabled by
764
- * default, turn them off for the context we build our code in. We don't
765
- * need to do so for other contexts (e.g. llvm_ts_context). Once the IR is
766
- * generated, it carries the necessary information.
804
+ * When targeting LLVM 15, turn off opaque pointers for the context we
805
+ * build our code in. We don't need to do so for other contexts (e.g.
806
+ * llvm_ts_context). Once the IR is generated, it carries the necessary
807
+ * information.
808
+ *
809
+ * For 16 and above, opaque pointers must be used, and we have special
810
+ * code for that.
767
811
*/
768
- #if LLVM_VERSION_MAJOR > 14
812
+ #if LLVM_VERSION_MAJOR == 15
769
813
LLVMContextSetOpaquePointers (LLVMGetGlobalContext (), false);
770
814
#endif
771
815
@@ -915,26 +959,6 @@ llvm_shutdown(int code, Datum arg)
915
959
#endif /* LLVM_VERSION_MAJOR > 11 */
916
960
}
917
961
918
- /* helper for llvm_create_types, returning a global var's type */
919
- static LLVMTypeRef
920
- load_type (LLVMModuleRef mod ,const char * name )
921
- {
922
- LLVMValueRef value ;
923
- LLVMTypeRef typ ;
924
-
925
- /* this'll return a *pointer* to the global */
926
- value = LLVMGetNamedGlobal (mod ,name );
927
- if (!value )
928
- elog (ERROR ,"type %s is unknown" ,name );
929
-
930
- /* therefore look at the contained type and return that */
931
- typ = LLVMTypeOf (value );
932
- Assert (typ != NULL );
933
- typ = LLVMGetElementType (typ );
934
- Assert (typ != NULL );
935
- return typ ;
936
- }
937
-
938
962
/* helper for llvm_create_types, returning a function's return type */
939
963
static LLVMTypeRef
940
964
load_return_type (LLVMModuleRef mod ,const char * name )
@@ -947,15 +971,7 @@ load_return_type(LLVMModuleRef mod, const char *name)
947
971
if (!value )
948
972
elog (ERROR ,"function %s is unknown" ,name );
949
973
950
- /* get type of function pointer */
951
- typ = LLVMTypeOf (value );
952
- Assert (typ != NULL );
953
- /* dereference pointer */
954
- typ = LLVMGetElementType (typ );
955
- Assert (typ != NULL );
956
- /* and look at return type */
957
- typ = LLVMGetReturnType (typ );
958
- Assert (typ != NULL );
974
+ typ = LLVMGetFunctionReturnType (value );/* in llvmjit_wrap.cpp */
959
975
960
976
return typ ;
961
977
}
@@ -996,26 +1012,30 @@ llvm_create_types(void)
996
1012
llvm_triple = pstrdup (LLVMGetTarget (llvm_types_module ));
997
1013
llvm_layout = pstrdup (LLVMGetDataLayoutStr (llvm_types_module ));
998
1014
999
- TypeSizeT = load_type ( llvm_types_module , "TypeSizeT" );
1015
+ TypeSizeT = llvm_pg_var_type ( "TypeSizeT" );
1000
1016
TypeParamBool = load_return_type (llvm_types_module ,"FunctionReturningBool" );
1001
- TypeStorageBool = load_type (llvm_types_module ,"TypeStorageBool" );
1002
- TypePGFunction = load_type (llvm_types_module ,"TypePGFunction" );
1003
- StructNullableDatum = load_type (llvm_types_module ,"StructNullableDatum" );
1004
- StructExprContext = load_type (llvm_types_module ,"StructExprContext" );
1005
- StructExprEvalStep = load_type (llvm_types_module ,"StructExprEvalStep" );
1006
- StructExprState = load_type (llvm_types_module ,"StructExprState" );
1007
- StructFunctionCallInfoData = load_type (llvm_types_module ,"StructFunctionCallInfoData" );
1008
- StructMemoryContextData = load_type (llvm_types_module ,"StructMemoryContextData" );
1009
- StructTupleTableSlot = load_type (llvm_types_module ,"StructTupleTableSlot" );
1010
- StructHeapTupleTableSlot = load_type (llvm_types_module ,"StructHeapTupleTableSlot" );
1011
- StructMinimalTupleTableSlot = load_type (llvm_types_module ,"StructMinimalTupleTableSlot" );
1012
- StructHeapTupleData = load_type (llvm_types_module ,"StructHeapTupleData" );
1013
- StructTupleDescData = load_type (llvm_types_module ,"StructTupleDescData" );
1014
- StructAggState = load_type (llvm_types_module ,"StructAggState" );
1015
- StructAggStatePerGroupData = load_type (llvm_types_module ,"StructAggStatePerGroupData" );
1016
- StructAggStatePerTransData = load_type (llvm_types_module ,"StructAggStatePerTransData" );
1017
+ TypeStorageBool = llvm_pg_var_type ("TypeStorageBool" );
1018
+ TypePGFunction = llvm_pg_var_type ("TypePGFunction" );
1019
+ StructNullableDatum = llvm_pg_var_type ("StructNullableDatum" );
1020
+ StructExprContext = llvm_pg_var_type ("StructExprContext" );
1021
+ StructExprEvalStep = llvm_pg_var_type ("StructExprEvalStep" );
1022
+ StructExprState = llvm_pg_var_type ("StructExprState" );
1023
+ StructFunctionCallInfoData = llvm_pg_var_type ("StructFunctionCallInfoData" );
1024
+ StructMemoryContextData = llvm_pg_var_type ("StructMemoryContextData" );
1025
+ StructTupleTableSlot = llvm_pg_var_type ("StructTupleTableSlot" );
1026
+ StructHeapTupleTableSlot = llvm_pg_var_type ("StructHeapTupleTableSlot" );
1027
+ StructMinimalTupleTableSlot = llvm_pg_var_type ("StructMinimalTupleTableSlot" );
1028
+ StructHeapTupleData = llvm_pg_var_type ("StructHeapTupleData" );
1029
+ StructHeapTupleHeaderData = llvm_pg_var_type ("StructHeapTupleHeaderData" );
1030
+ StructTupleDescData = llvm_pg_var_type ("StructTupleDescData" );
1031
+ StructAggState = llvm_pg_var_type ("StructAggState" );
1032
+ StructAggStatePerGroupData = llvm_pg_var_type ("StructAggStatePerGroupData" );
1033
+ StructAggStatePerTransData = llvm_pg_var_type ("StructAggStatePerTransData" );
1034
+ StructPlanState = llvm_pg_var_type ("StructPlanState" );
1035
+ StructMinimalTupleData = llvm_pg_var_type ("StructMinimalTupleData" );
1017
1036
1018
1037
AttributeTemplate = LLVMGetNamedFunction (llvm_types_module ,"AttributeTemplate" );
1038
+ ExecEvalSubroutineTemplate = LLVMGetNamedFunction (llvm_types_module ,"ExecEvalSubroutineTemplate" );
1019
1039
}
1020
1040
1021
1041
/*