Skip to content

Commit 0397df8

Browse files
jeevanchalkehackorum
authored andcommitted
jit: Support EEOP_AGG_INPUT_RECEIVED in the LLVM expression compiler
Follow-on to the ON EMPTY aggregate/window support. That patch added the EEOP_AGG_INPUT_RECEIVED expression step and implemented it in the interpreter; this patch teaches the LLVM JIT to compile the same step so that JIT-compiled aggregate transition expressions behave identically to the interpreted ones. The compiled step loads the aggregate's per-group state, skips silently if that pointer is NULL (the hashed/spilled case), and otherwise sets the group's inputReceived flag -- mirroring the interpreter's EEOP_AGG_INPUT_RECEIVED case. Without this, building with LLVM and JIT-compiling an ON EMPTY aggregate would fail on the unhandled opcode. Jeevan Chalke
1 parent d439bf1 commit 0397df8

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

src/backend/jit/llvm/llvmjit_expr.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,69 @@ llvm_compile_expr(ExprState *state)
25952595
break;
25962596
}
25972597

2598+
case EEOP_AGG_INPUT_RECEIVED:
2599+
{
2600+
LLVMValueRef v_aggstatep;
2601+
LLVMValueRef v_allpergroupsp;
2602+
LLVMValueRef v_pergroup_allaggs;
2603+
LLVMValueRef v_setoff;
2604+
LLVMValueRef v_transno;
2605+
LLVMValueRef v_pergroupp;
2606+
LLVMBasicBlockRef b_mark;
2607+
2608+
/*
2609+
* Mark that the aggregate's per-group state has received
2610+
* an input row (used by the ON EMPTY clause). Matches
2611+
* the interpreter's EEOP_AGG_INPUT_RECEIVED: skip
2612+
* silently if the per-group pointer is NULL
2613+
* (hashed/spilled case).
2614+
*/
2615+
v_aggstatep = LLVMBuildBitCast(b, v_parent,
2616+
l_ptr(StructAggState), "");
2617+
2618+
v_allpergroupsp = l_load_struct_gep(b,
2619+
StructAggState,
2620+
v_aggstatep,
2621+
FIELDNO_AGGSTATE_ALL_PERGROUPS,
2622+
"aggstate.all_pergroups");
2623+
2624+
v_setoff = l_int32_const(lc, op->d.agg_input_received.setoff);
2625+
v_transno = l_int32_const(lc, op->d.agg_input_received.transno);
2626+
2627+
v_pergroup_allaggs = l_load_gep1(b, l_ptr(StructAggStatePerGroupData),
2628+
v_allpergroupsp, v_setoff, "");
2629+
2630+
b_mark = l_bb_before_v(opblocks[opno + 1],
2631+
"op.%d.inputreceived", opno);
2632+
2633+
LLVMBuildCondBr(b,
2634+
LLVMBuildICmp(b, LLVMIntEQ,
2635+
LLVMBuildPtrToInt(b, v_pergroup_allaggs, TypeDatum, ""),
2636+
l_datum_const(0), ""),
2637+
opblocks[opno + 1],
2638+
b_mark);
2639+
2640+
/* block that performs the store when pergroup is non-NULL */
2641+
LLVMPositionBuilderAtEnd(b, b_mark);
2642+
2643+
v_pergroupp =
2644+
l_gep(b,
2645+
StructAggStatePerGroupData,
2646+
v_pergroup_allaggs,
2647+
&v_transno, 1, "");
2648+
2649+
LLVMBuildStore(b,
2650+
l_sbool_const(1),
2651+
l_struct_gep(b,
2652+
StructAggStatePerGroupData,
2653+
v_pergroupp,
2654+
FIELDNO_AGGSTATEPERGROUPDATA_INPUTRECEIVED,
2655+
"inputreceivedp"));
2656+
2657+
LLVMBuildBr(b, opblocks[opno + 1]);
2658+
break;
2659+
}
2660+
25982661
case EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL:
25992662
case EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL:
26002663
case EEOP_AGG_PLAIN_TRANS_BYVAL:

0 commit comments

Comments
 (0)