From ebe124eacd7c3faa36ed358e7cc1d7c5b419e5f6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:18:09 +0200 Subject: Merging upstream version 15.6. Signed-off-by: Daniel Baumann --- src/backend/jit/llvm/llvmjit_expr.c | 60 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'src/backend/jit/llvm/llvmjit_expr.c') diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c index 49b19c9..95836af 100644 --- a/src/backend/jit/llvm/llvmjit_expr.c +++ b/src/backend/jit/llvm/llvmjit_expr.c @@ -84,6 +84,7 @@ llvm_compile_expr(ExprState *state) LLVMBuilderRef b; LLVMModuleRef mod; + LLVMContextRef lc; LLVMValueRef eval_fn; LLVMBasicBlockRef entry; LLVMBasicBlockRef *opblocks; @@ -143,8 +144,9 @@ llvm_compile_expr(ExprState *state) INSTR_TIME_SET_CURRENT(starttime); mod = llvm_mutable_module(context); + lc = LLVMGetModuleContext(mod); - b = LLVMCreateBuilder(); + b = LLVMCreateBuilderInContext(lc); funcname = llvm_expand_funcname(context, "evalexpr"); @@ -155,7 +157,7 @@ llvm_compile_expr(ExprState *state) LLVMSetVisibility(eval_fn, LLVMDefaultVisibility); llvm_copy_attributes(AttributeTemplate, eval_fn); - entry = LLVMAppendBasicBlock(eval_fn, "entry"); + entry = LLVMAppendBasicBlockInContext(lc, eval_fn, "entry"); /* build state */ v_state = LLVMGetParam(eval_fn, 0); @@ -337,7 +339,7 @@ llvm_compile_expr(ExprState *state) ""); LLVMBuildCondBr(b, LLVMBuildICmp(b, LLVMIntUGE, v_nvalid, - l_int16_const(op->d.fetch.last_var), + l_int16_const(lc, op->d.fetch.last_var), ""), opblocks[opno + 1], b_fetch); @@ -373,7 +375,7 @@ llvm_compile_expr(ExprState *state) LLVMValueRef params[2]; params[0] = v_slot; - params[1] = l_int32_const(op->d.fetch.last_var); + params[1] = l_int32_const(lc, op->d.fetch.last_var); l_call(b, llvm_pg_var_func_type("slot_getsomeattrs_int"), @@ -411,7 +413,7 @@ llvm_compile_expr(ExprState *state) v_nulls = v_scannulls; } - v_attnum = l_int32_const(op->d.var.attnum); + v_attnum = l_int32_const(lc, op->d.var.attnum); value = l_load_gep1(b, TypeSizeT, v_values, v_attnum, ""); isnull = l_load_gep1(b, TypeStorageBool, v_nulls, v_attnum, ""); LLVMBuildStore(b, value, v_resvaluep); @@ -477,12 +479,12 @@ llvm_compile_expr(ExprState *state) } /* load data */ - v_attnum = l_int32_const(op->d.assign_var.attnum); + v_attnum = l_int32_const(lc, op->d.assign_var.attnum); v_value = l_load_gep1(b, TypeSizeT, v_values, v_attnum, ""); v_isnull = l_load_gep1(b, TypeStorageBool, v_nulls, v_attnum, ""); /* compute addresses of targets */ - v_resultnum = l_int32_const(op->d.assign_var.resultnum); + v_resultnum = l_int32_const(lc, op->d.assign_var.resultnum); v_rvaluep = l_gep(b, TypeSizeT, v_resultvalues, @@ -515,7 +517,7 @@ llvm_compile_expr(ExprState *state) v_isnull = l_load(b, TypeStorageBool, v_tmpisnullp, ""); /* compute addresses of targets */ - v_resultnum = l_int32_const(resultnum); + v_resultnum = l_int32_const(lc, resultnum); v_rvaluep = l_gep(b, TypeSizeT, v_resultvalues, &v_resultnum, 1, ""); v_risnullp = @@ -1749,7 +1751,7 @@ llvm_compile_expr(ExprState *state) v_cmpresult = LLVMBuildTrunc(b, l_load(b, TypeSizeT, v_resvaluep, ""), - LLVMInt32Type(), ""); + LLVMInt32TypeInContext(lc), ""); switch (rctype) { @@ -1775,7 +1777,7 @@ llvm_compile_expr(ExprState *state) v_result = LLVMBuildICmp(b, predicate, v_cmpresult, - l_int32_const(0), + l_int32_const(lc, 0), ""); v_result = LLVMBuildZExt(b, v_result, TypeSizeT, ""); @@ -1910,7 +1912,7 @@ llvm_compile_expr(ExprState *state) LLVMValueRef value, isnull; - v_aggno = l_int32_const(op->d.aggref.aggno); + v_aggno = l_int32_const(lc, op->d.aggref.aggno); /* load agg value / null */ value = l_load_gep1(b, TypeSizeT, v_aggvalues, v_aggno, "aggvalue"); @@ -1944,8 +1946,8 @@ llvm_compile_expr(ExprState *state) * expression). So load it from memory each time round. */ v_wfuncnop = l_ptr_const(&wfunc->wfuncno, - l_ptr(LLVMInt32Type())); - v_wfuncno = l_load(b, LLVMInt32Type(), v_wfuncnop, "v_wfuncno"); + l_ptr(LLVMInt32TypeInContext(lc))); + v_wfuncno = l_load(b, LLVMInt32TypeInContext(lc), v_wfuncnop, "v_wfuncno"); /* load window func value / null */ value = l_load_gep1(b, TypeSizeT, v_aggvalues, v_wfuncno, @@ -2052,7 +2054,7 @@ llvm_compile_expr(ExprState *state) /* strict function, check for NULL args */ for (int argno = 0; argno < nargs; argno++) { - LLVMValueRef v_argno = l_int32_const(argno); + LLVMValueRef v_argno = l_int32_const(lc, argno); LLVMValueRef v_argisnull; LLVMBasicBlockRef b_argnotnull; @@ -2111,7 +2113,7 @@ llvm_compile_expr(ExprState *state) FIELDNO_AGGSTATE_ALL_PERGROUPS, "aggstate.all_pergroups"); - v_setoff = l_int32_const(op->d.agg_plain_pergroup_nullcheck.setoff); + v_setoff = l_int32_const(lc, op->d.agg_plain_pergroup_nullcheck.setoff); v_pergroup_allaggs = l_load_gep1(b, l_ptr(StructAggStatePerGroupData), v_allpergroupsp, v_setoff, ""); @@ -2183,8 +2185,8 @@ llvm_compile_expr(ExprState *state) v_aggstatep, FIELDNO_AGGSTATE_ALL_PERGROUPS, "aggstate.all_pergroups"); - v_setoff = l_int32_const(op->d.agg_trans.setoff); - v_transno = l_int32_const(op->d.agg_trans.transno); + v_setoff = l_int32_const(lc, op->d.agg_trans.setoff); + v_transno = l_int32_const(lc, op->d.agg_trans.transno); v_pergroupp = l_gep(b, StructAggStatePerGroupData, @@ -2297,7 +2299,7 @@ llvm_compile_expr(ExprState *state) /* set aggstate globals */ LLVMBuildStore(b, v_aggcontext, v_curaggcontext); - LLVMBuildStore(b, l_int32_const(op->d.agg_trans.setno), + LLVMBuildStore(b, l_int32_const(lc, op->d.agg_trans.setno), v_current_setp); LLVMBuildStore(b, v_pertransp, v_current_pertransp); @@ -2493,11 +2495,14 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b, LLVMModuleRef mod, FunctionCallInfo fcinfo, LLVMValueRef *v_fcinfo_isnull) { + LLVMContextRef lc; LLVMValueRef v_fn; LLVMValueRef v_fcinfo_isnullp; LLVMValueRef v_retval; LLVMValueRef v_fcinfo; + lc = LLVMGetModuleContext(mod); + v_fn = llvm_function_reference(context, b, mod, fcinfo); v_fcinfo = l_ptr_const(fcinfo, l_ptr(StructFunctionCallInfoData)); @@ -2521,12 +2526,12 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b, LLVMValueRef v_lifetime = create_LifetimeEnd(mod); LLVMValueRef params[2]; - params[0] = l_int64_const(sizeof(NullableDatum) * fcinfo->nargs); - params[1] = l_ptr_const(fcinfo->args, l_ptr(LLVMInt8Type())); + 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), ""); - params[0] = l_int64_const(sizeof(fcinfo->isnull)); - params[1] = l_ptr_const(&fcinfo->isnull, l_ptr(LLVMInt8Type())); + 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), ""); } @@ -2572,6 +2577,7 @@ create_LifetimeEnd(LLVMModuleRef mod) LLVMTypeRef sig; LLVMValueRef fn; LLVMTypeRef param_types[2]; + LLVMContextRef lc; /* LLVM 5+ has a variadic pointer argument */ #if LLVM_VERSION_MAJOR < 5 @@ -2584,12 +2590,12 @@ create_LifetimeEnd(LLVMModuleRef mod) if (fn) return fn; - param_types[0] = LLVMInt64Type(); - param_types[1] = l_ptr(LLVMInt8Type()); + lc = LLVMGetModuleContext(mod); + param_types[0] = LLVMInt64TypeInContext(lc); + param_types[1] = l_ptr(LLVMInt8TypeInContext(lc)); - sig = LLVMFunctionType(LLVMVoidType(), - param_types, lengthof(param_types), - false); + sig = LLVMFunctionType(LLVMVoidTypeInContext(lc), param_types, + lengthof(param_types), false); fn = LLVMAddFunction(mod, nm, sig); LLVMSetFunctionCallConv(fn, LLVMCCallConv); -- cgit v1.2.3