Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74d19ec

Browse files
committed
jit: Support opaque pointers in LLVM 16.
Remove use of LLVMGetElementType() and provide the type of all pointersto LLVMBuildXXX() functions when emitting IR, as required by modern LLVMversions[1]. * For LLVM <= 14, we'll still use the old LLVMBuildXXX() functions. * For LLVM == 15, we'll continue to do the same, explicitly opting out of opaque pointer mode. * For LLVM >= 16, we'll use the new LLVMBuildXXX2() functions that take the extra type argument.The difference is hidden behind some new IR emitting wrapper functionsl_load(), l_gep(), l_call() etc. The change is mostly mechanical,except that at each site the correct type had to be provided.In some places we needed to do some extra work to get functions types,including some new wrappers for C++ APIs that are not yet exposed by inLLVM's C API, and some new "example" functions in llvmjit_types.cbecause it's no longer possible to start from the function pointer typeand ask for the function type.Back-patch to 12, because it's a little tricker in 11 and we agreed notto put the latest LLVM support into the upcoming final release of 11.[1]https://llvm.org/docs/OpaquePointers.htmlReviewed-by: Dmitry Dolgov <9erthalion6@gmail.com>Reviewed-by: Ronan Dunklau <ronan.dunklau@aiven.io>Reviewed-by: Andres Freund <andres@anarazel.de>Discussion:https://postgr.es/m/CA%2BhUKGKNX_%3Df%2B1C4r06WETKTq0G4Z_7q4L4Fxn5WWpMycDj9Fw%40mail.gmail.com
1 parent4277bcb commit74d19ec

File tree

8 files changed

+479
-264
lines changed

8 files changed

+479
-264
lines changed

‎src/backend/jit/llvm/llvmjit.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ LLVMTypeRef StructExprState;
8585
LLVMTypeRefStructAggState;
8686
LLVMTypeRefStructAggStatePerGroupData;
8787
LLVMTypeRefStructAggStatePerTransData;
88+
LLVMTypeRefStructPlanState;
8889

8990
LLVMValueRefAttributeTemplate;
91+
LLVMValueRefExecEvalSubroutineTemplate;
92+
LLVMValueRefExecEvalBoolSubroutineTemplate;
9093

9194
LLVMModuleRefllvm_types_module=NULL;
9295

@@ -384,11 +387,7 @@ llvm_pg_var_type(const char *varname)
384387
if (!v_srcvar)
385388
elog(ERROR,"variable %s not in llvmjit_types.c",varname);
386389

387-
/* look at the contained type */
388-
typ=LLVMTypeOf(v_srcvar);
389-
Assert(typ!=NULL&&LLVMGetTypeKind(typ)==LLVMPointerTypeKind);
390-
typ=LLVMGetElementType(typ);
391-
Assert(typ!=NULL);
390+
typ=LLVMGlobalGetValueType(v_srcvar);
392391

393392
returntyp;
394393
}
@@ -400,12 +399,14 @@ llvm_pg_var_type(const char *varname)
400399
LLVMTypeRef
401400
llvm_pg_var_func_type(constchar*varname)
402401
{
403-
LLVMTypeReftyp=llvm_pg_var_type(varname);
402+
LLVMValueRefv_srcvar;
403+
LLVMTypeReftyp;
404+
405+
v_srcvar=LLVMGetNamedFunction(llvm_types_module,varname);
406+
if (!v_srcvar)
407+
elog(ERROR,"function %s not in llvmjit_types.c",varname);
404408

405-
/* look at the contained type */
406-
Assert(LLVMGetTypeKind(typ)==LLVMPointerTypeKind);
407-
typ=LLVMGetElementType(typ);
408-
Assert(typ!=NULL&&LLVMGetTypeKind(typ)==LLVMFunctionTypeKind);
409+
typ=LLVMGetFunctionType(v_srcvar);
409410

410411
returntyp;
411412
}
@@ -435,7 +436,7 @@ llvm_pg_func(LLVMModuleRef mod, const char *funcname)
435436

436437
v_fn=LLVMAddFunction(mod,
437438
funcname,
438-
LLVMGetElementType(LLVMTypeOf(v_srcfn)));
439+
LLVMGetFunctionType(v_srcfn));
439440
llvm_copy_attributes(v_srcfn,v_fn);
440441

441442
returnv_fn;
@@ -531,7 +532,7 @@ llvm_function_reference(LLVMJitContext *context,
531532
fcinfo->flinfo->fn_oid);
532533
v_fn=LLVMGetNamedGlobal(mod,funcname);
533534
if (v_fn!=0)
534-
returnLLVMBuildLoad(builder,v_fn,"");
535+
returnl_load(builder,TypePGFunction,v_fn,"");
535536

536537
v_fn_addr=l_ptr_const(fcinfo->flinfo->fn_addr,TypePGFunction);
537538

@@ -541,15 +542,15 @@ llvm_function_reference(LLVMJitContext *context,
541542
LLVMSetLinkage(v_fn,LLVMPrivateLinkage);
542543
LLVMSetUnnamedAddr(v_fn, true);
543544

544-
returnLLVMBuildLoad(builder,v_fn,"");
545+
returnl_load(builder,TypePGFunction,v_fn,"");
545546
}
546547

547548
/* check if function already has been added */
548549
v_fn=LLVMGetNamedFunction(mod,funcname);
549550
if (v_fn!=0)
550551
returnv_fn;
551552

552-
v_fn=LLVMAddFunction(mod,funcname,LLVMGetElementType(TypePGFunction));
553+
v_fn=LLVMAddFunction(mod,funcname,LLVMGetFunctionType(AttributeTemplate));
553554

554555
returnv_fn;
555556
}
@@ -801,12 +802,15 @@ llvm_session_initialize(void)
801802
LLVMInitializeNativeAsmParser();
802803

803804
/*
804-
* When targeting an LLVM version with opaque pointers enabled by default,
805-
* turn them off for the context we build our code in. We don't need to
806-
* do so for other contexts (e.g. llvm_ts_context). Once the IR is
807-
* generated, it carries the necessary information.
805+
* When targeting LLVM 15, turn off opaque pointers for the context we
806+
* build our code in. We don't need to do so for other contexts (e.g.
807+
* llvm_ts_context). Once the IR is generated, it carries the necessary
808+
* information.
809+
*
810+
* For 16 and above, opaque pointers must be used, and we have special
811+
* code for that.
808812
*/
809-
#ifLLVM_VERSION_MAJOR>14
813+
#ifLLVM_VERSION_MAJOR==15
810814
LLVMContextSetOpaquePointers(LLVMGetGlobalContext(), false);
811815
#endif
812816

@@ -968,15 +972,7 @@ load_return_type(LLVMModuleRef mod, const char *name)
968972
if (!value)
969973
elog(ERROR,"function %s is unknown",name);
970974

971-
/* get type of function pointer */
972-
typ=LLVMTypeOf(value);
973-
Assert(typ!=NULL);
974-
/* dereference pointer */
975-
typ=LLVMGetElementType(typ);
976-
Assert(typ!=NULL);
977-
/* and look at return type */
978-
typ=LLVMGetReturnType(typ);
979-
Assert(typ!=NULL);
975+
typ=LLVMGetFunctionReturnType(value);/* in llvmjit_wrap.cpp */
980976

981977
returntyp;
982978
}
@@ -1031,12 +1027,17 @@ llvm_create_types(void)
10311027
StructHeapTupleTableSlot=llvm_pg_var_type("StructHeapTupleTableSlot");
10321028
StructMinimalTupleTableSlot=llvm_pg_var_type("StructMinimalTupleTableSlot");
10331029
StructHeapTupleData=llvm_pg_var_type("StructHeapTupleData");
1030+
StructHeapTupleHeaderData=llvm_pg_var_type("StructHeapTupleHeaderData");
10341031
StructTupleDescData=llvm_pg_var_type("StructTupleDescData");
10351032
StructAggState=llvm_pg_var_type("StructAggState");
10361033
StructAggStatePerGroupData=llvm_pg_var_type("StructAggStatePerGroupData");
10371034
StructAggStatePerTransData=llvm_pg_var_type("StructAggStatePerTransData");
1035+
StructPlanState=llvm_pg_var_type("StructPlanState");
1036+
StructMinimalTupleData=llvm_pg_var_type("StructMinimalTupleData");
10381037

10391038
AttributeTemplate=LLVMGetNamedFunction(llvm_types_module,"AttributeTemplate");
1039+
ExecEvalSubroutineTemplate=LLVMGetNamedFunction(llvm_types_module,"ExecEvalSubroutineTemplate");
1040+
ExecEvalBoolSubroutineTemplate=LLVMGetNamedFunction(llvm_types_module,"ExecEvalBoolSubroutineTemplate");
10401041
}
10411042

10421043
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp