0004-jit-Drop-LLVMGetFunctionType-wrapper.patch
text/x-patch
Filename: 0004-jit-Drop-LLVMGetFunctionType-wrapper.patch
Type: text/x-patch
Part: 3
Message:
Minor LLVM cleanups
From 5458f84cf92d8d454f1755b1d99fb763d7090f08 Mon Sep 17 00:00:00 2001
From: Thomas Munro <thomas.munro@gmail.com>
Date: Fri, 28 Nov 2025 02:16:29 +1300
Subject: [PATCH 4/6] jit: Drop LLVMGetFunctionType() wrapper.
Commit 37d5babb added this wrapper function to reach the C++ function
llvm::Function::getFunctionType(), but it turns out that we can just use
the existing LLVMGlobalGetValueType() function instead, at least for our
usage where the functions are all global or we have a reference function
that is global.
---
src/backend/jit/llvm/llvmjit.c | 10 +++++-----
src/backend/jit/llvm/llvmjit_deform.c | 2 +-
src/backend/jit/llvm/llvmjit_expr.c | 26 +++++++++++++-------------
src/backend/jit/llvm/llvmjit_wrap.cpp | 6 ------
src/include/jit/llvmjit.h | 1 -
5 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 6cd457e429a..6a0db9de7c6 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -449,7 +449,7 @@ llvm_pg_var_func_type(const char *varname)
if (!v_srcvar)
elog(ERROR, "function %s not in llvmjit_types.c", varname);
- typ = LLVMGetFunctionType(v_srcvar);
+ typ = LLVMGlobalGetValueType(v_srcvar);
return typ;
}
@@ -479,7 +479,7 @@ llvm_pg_func(LLVMModuleRef mod, const char *funcname)
v_fn = LLVMAddFunction(mod,
funcname,
- LLVMGetFunctionType(v_srcfn));
+ LLVMGlobalGetValueType(v_srcfn));
llvm_copy_attributes(v_srcfn, v_fn);
return v_fn;
@@ -521,7 +521,7 @@ llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
/* copy function attributes */
llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeFunctionIndex);
- if (LLVMGetTypeKind(LLVMGetReturnType(LLVMGetFunctionType(v_to))) != LLVMVoidTypeKind)
+ if (LLVMGetTypeKind(LLVMGetReturnType(LLVMGlobalGetValueType(v_to))) != LLVMVoidTypeKind)
{
/* and the return value attributes */
llvm_copy_attributes_at_index(v_from, v_to, LLVMAttributeReturnIndex);
@@ -592,7 +592,7 @@ llvm_function_reference(LLVMJitContext *context,
if (v_fn != 0)
return v_fn;
- v_fn = LLVMAddFunction(mod, funcname, LLVMGetFunctionType(AttributeTemplate));
+ v_fn = LLVMAddFunction(mod, funcname, LLVMGlobalGetValueType(AttributeTemplate));
return v_fn;
}
@@ -960,7 +960,7 @@ load_return_type(LLVMModuleRef mod, const char *name)
if (!value)
elog(ERROR, "function %s is unknown", name);
- typ = LLVMGetReturnType(LLVMGetFunctionType(value));
+ typ = LLVMGetReturnType(LLVMGlobalGetValueType(value));
return typ;
}
diff --git a/src/backend/jit/llvm/llvmjit_deform.c b/src/backend/jit/llvm/llvmjit_deform.c
index f500cbda893..f37c8141f55 100644
--- a/src/backend/jit/llvm/llvmjit_deform.c
+++ b/src/backend/jit/llvm/llvmjit_deform.c
@@ -351,7 +351,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc,
v_params[2] = l_int32_const(lc, natts);
f = llvm_pg_func(mod, "slot_getmissingattrs");
l_call(b,
- LLVMGetFunctionType(f), f,
+ LLVMGlobalGetValueType(f), f,
v_params, lengthof(v_params), "");
LLVMBuildBr(b, b_find_start);
}
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c
index ac88881e995..426ad8ee735 100644
--- a/src/backend/jit/llvm/llvmjit_expr.c
+++ b/src/backend/jit/llvm/llvmjit_expr.c
@@ -418,7 +418,7 @@ llvm_compile_expr(ExprState *state)
params[0] = v_slot;
l_call(b,
- LLVMGetFunctionType(l_jit_deform),
+ LLVMGlobalGetValueType(l_jit_deform),
l_jit_deform,
params, lengthof(params), "");
}
@@ -1208,7 +1208,7 @@ llvm_compile_expr(ExprState *state)
v_params[1] = l_ptr_const(op, l_ptr(StructExprEvalStep));
v_params[2] = v_econtext;
l_call(b,
- LLVMGetFunctionType(ExecEvalSubroutineTemplate),
+ LLVMGlobalGetValueType(ExecEvalSubroutineTemplate),
v_func,
v_params, lengthof(v_params), "");
@@ -1236,7 +1236,7 @@ llvm_compile_expr(ExprState *state)
v_params[1] = l_ptr_const(op, l_ptr(StructExprEvalStep));
v_params[2] = v_econtext;
v_ret = l_call(b,
- LLVMGetFunctionType(ExecEvalBoolSubroutineTemplate),
+ LLVMGlobalGetValueType(ExecEvalBoolSubroutineTemplate),
v_func,
v_params, lengthof(v_params), "");
v_ret = LLVMBuildZExt(b, v_ret, TypeStorageBool, "");
@@ -1263,7 +1263,7 @@ llvm_compile_expr(ExprState *state)
v_params[1] = l_ptr_const(op, l_ptr(StructExprEvalStep));
v_params[2] = v_econtext;
l_call(b,
- LLVMGetFunctionType(ExecEvalSubroutineTemplate),
+ LLVMGlobalGetValueType(ExecEvalSubroutineTemplate),
v_func,
v_params, lengthof(v_params), "");
@@ -1430,7 +1430,7 @@ llvm_compile_expr(ExprState *state)
l_funcnullp(b, v_fcinfo_out, 0));
/* and call output function (can never return NULL) */
v_output = l_call(b,
- LLVMGetFunctionType(v_fn_out),
+ LLVMGlobalGetValueType(v_fn_out),
v_fn_out, &v_fcinfo_out,
1, "funccall_coerce_out");
LLVMBuildBr(b, b_input);
@@ -1487,7 +1487,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, l_sbool_const(0), v_fcinfo_in_isnullp);
/* and call function */
v_retval = l_call(b,
- LLVMGetFunctionType(v_fn_in),
+ LLVMGlobalGetValueType(v_fn_in),
v_fn_in, &v_fcinfo_in, 1,
"funccall_iocoerce_in");
@@ -2854,7 +2854,7 @@ llvm_compile_expr(ExprState *state)
v_fn = llvm_pg_func(mod, "ExecAggCopyTransValue");
v_newval =
l_call(b,
- LLVMGetFunctionType(v_fn),
+ LLVMGlobalGetValueType(v_fn),
v_fn,
params, lengthof(params),
"");
@@ -2893,7 +2893,7 @@ llvm_compile_expr(ExprState *state)
v_args[0] = l_ptr_const(aggstate, l_ptr(StructAggState));
v_args[1] = l_ptr_const(pertrans, l_ptr(StructAggStatePerTransData));
- v_ret = l_call(b, LLVMGetFunctionType(v_fn), v_fn, v_args, 2, "");
+ v_ret = l_call(b, LLVMGlobalGetValueType(v_fn), v_fn, v_args, 2, "");
v_ret = LLVMBuildZExt(b, v_ret, TypeStorageBool, "");
LLVMBuildCondBr(b,
@@ -2917,7 +2917,7 @@ llvm_compile_expr(ExprState *state)
v_args[0] = l_ptr_const(aggstate, l_ptr(StructAggState));
v_args[1] = l_ptr_const(pertrans, l_ptr(StructAggStatePerTransData));
- v_ret = l_call(b, LLVMGetFunctionType(v_fn), v_fn, v_args, 2, "");
+ v_ret = l_call(b, LLVMGlobalGetValueType(v_fn), v_fn, v_args, 2, "");
v_ret = LLVMBuildZExt(b, v_ret, TypeStorageBool, "");
LLVMBuildCondBr(b,
@@ -3025,7 +3025,7 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
"v_fcinfo_isnull");
LLVMBuildStore(b, l_sbool_const(0), v_fcinfo_isnullp);
- v_retval = l_call(b, LLVMGetFunctionType(AttributeTemplate), v_fn, &v_fcinfo, 1, "funccall");
+ v_retval = l_call(b, LLVMGlobalGetValueType(AttributeTemplate), v_fn, &v_fcinfo, 1, "funccall");
if (v_fcinfo_isnull)
*v_fcinfo_isnull = l_load(b, TypeStorageBool, v_fcinfo_isnullp, "");
@@ -3040,11 +3040,11 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
params[0] = l_int64_const(lc, sizeof(NullableDatum) * fcinfo->nargs);
params[1] = l_ptr_const(fcinfo->args, l_ptr(LLVMInt8TypeInContext(lc)));
- l_call(b, LLVMGetFunctionType(v_lifetime), v_lifetime, params, lengthof(params), "");
+ l_call(b, LLVMGlobalGetValueType(v_lifetime), v_lifetime, params, lengthof(params), "");
params[0] = l_int64_const(lc, sizeof(fcinfo->isnull));
params[1] = l_ptr_const(&fcinfo->isnull, l_ptr(LLVMInt8TypeInContext(lc)));
- l_call(b, LLVMGetFunctionType(v_lifetime), v_lifetime, params, lengthof(params), "");
+ l_call(b, LLVMGlobalGetValueType(v_lifetime), v_lifetime, params, lengthof(params), "");
}
return v_retval;
@@ -3076,7 +3076,7 @@ build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod, const char *funcname,
for (int i = 0; i < nargs; i++)
params[argno++] = v_args[i];
- v_ret = l_call(b, LLVMGetFunctionType(v_fn), v_fn, params, argno, "");
+ v_ret = l_call(b, LLVMGlobalGetValueType(v_fn), v_fn, params, argno, "");
pfree(params);
diff --git a/src/backend/jit/llvm/llvmjit_wrap.cpp b/src/backend/jit/llvm/llvmjit_wrap.cpp
index 4033e730d7c..0dd311c59df 100644
--- a/src/backend/jit/llvm/llvmjit_wrap.cpp
+++ b/src/backend/jit/llvm/llvmjit_wrap.cpp
@@ -34,12 +34,6 @@ extern "C"
* C-API extensions.
*/
-LLVMTypeRef
-LLVMGetFunctionType(LLVMValueRef r)
-{
- return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType());
-}
-
#ifdef USE_LLVM_BACKPORT_SECTION_MEMORY_MANAGER
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ExecutionSession, LLVMOrcExecutionSessionRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ObjectLayer, LLVMOrcObjectLayerRef);
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 1a8369005ef..d03d508add5 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -139,7 +139,6 @@ extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDes
* Error handling related functions.
****************************************************************************
*/
-extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
#ifdef USE_LLVM_BACKPORT_SECTION_MEMORY_MANAGER
extern LLVMOrcObjectLayerRef LLVMOrcCreateRTDyldObjectLinkingLayerWithSafeSectionMemoryManager(LLVMOrcExecutionSessionRef ES);
#endif
--
2.51.2