Skip to content

Commit d23fb4d

Browse files
committed
jit: API changes for LLVM 22.
The lifetime.end intrinsic can now only be used for stack memory allocated with alloca. We were using it to tell the optimizer that we are no longer interested in the arguments and null flag in a FunctionCallInfo struct, so it could avoid actually storing them if it managed to inline the function and keep everything in registers. It can't figure that out by itself because it's part of the ExecEvalStep struct and we scribble on it directly rather than building a new one on the stack. Instead, store the special poison value (undef would work too). This is a no-op, but tells the optimizer that we are not interested in the values. XXX Verify inlined results! Deform functions use LLVMBuildAlloca() for a stack variable, but that memory is reclaimed implicitly by the ret instruction. llvm/llvm-project#149310 https://llvm.org/docs/LangRef.html#llvm-lifetime-end-intrinsic https://llvm.org/docs/LangRef.html#i-alloca
1 parent 75e82b2 commit d23fb4d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/backend/jit/llvm/llvmjit_expr.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod,
6262
LLVMValueRef v_state,
6363
ExprEvalStep *op,
6464
int natts, LLVMValueRef *v_args);
65+
#if LLVM_VERSION_MAJOR < 22
6566
static LLVMValueRef create_LifetimeEnd(LLVMModuleRef mod);
67+
#endif
6668

6769
/* macro making it easier to call ExecEval* functions */
6870
#define build_EvalXFunc(b, mod, funcname, v_state, op, ...) \
@@ -3007,14 +3009,11 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
30073009
LLVMModuleRef mod, FunctionCallInfo fcinfo,
30083010
LLVMValueRef *v_fcinfo_isnull)
30093011
{
3010-
LLVMContextRef lc;
30113012
LLVMValueRef v_fn;
30123013
LLVMValueRef v_fcinfo_isnullp;
30133014
LLVMValueRef v_retval;
30143015
LLVMValueRef v_fcinfo;
30153016

3016-
lc = LLVMGetModuleContext(mod);
3017-
30183017
v_fn = llvm_function_reference(context, b, mod, fcinfo);
30193018

30203019
v_fcinfo = l_ptr_const(fcinfo, l_ptr(StructFunctionCallInfoData));
@@ -3030,11 +3029,21 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
30303029
if (v_fcinfo_isnull)
30313030
*v_fcinfo_isnull = l_load(b, TypeStorageBool, v_fcinfo_isnullp, "");
30323031

3032+
#if LLVM_VERSION_MAJOR >= 22
3033+
/*
3034+
* Mark memory as unimportant, signaling that writes to memory don't to be
3035+
* retained (important for inlining potential).
3036+
*/
3037+
for (int i = 0; i < fcinfo->nargs; ++i)
3038+
LLVMBuildStore(b, LLVMGetPoison(StructNullableDatum), l_funcvaluep(b, v_fcinfo, i));
3039+
LLVMBuildStore(b, LLVMGetPoison(TypeStorageBool), v_fcinfo_isnullp);
3040+
#else
30333041
/*
30343042
* Add lifetime-end annotation, signaling that writes to memory don't have
30353043
* to be retained (important for inlining potential).
30363044
*/
30373045
{
3046+
LLVMContextRef lc = LLVMGetModuleContext(mod);
30383047
LLVMValueRef v_lifetime = create_LifetimeEnd(mod);
30393048
LLVMValueRef params[2];
30403049

@@ -3046,6 +3055,7 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
30463055
params[1] = l_ptr_const(&fcinfo->isnull, l_ptr(LLVMInt8TypeInContext(lc)));
30473056
l_call(b, LLVMGetFunctionType(v_lifetime), v_lifetime, params, lengthof(params), "");
30483057
}
3058+
#endif
30493059

30503060
return v_retval;
30513061
}
@@ -3083,6 +3093,7 @@ build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod, const char *funcname,
30833093
return v_ret;
30843094
}
30853095

3096+
#if LLVM_VERSION_MAJOR < 22
30863097
static LLVMValueRef
30873098
create_LifetimeEnd(LLVMModuleRef mod)
30883099
{
@@ -3112,3 +3123,4 @@ create_LifetimeEnd(LLVMModuleRef mod)
31123123

31133124
return fn;
31143125
}
3126+
#endif

0 commit comments

Comments
 (0)