18 #include <llvm-c/Core.h>
19 #include <llvm-c/Target.h>
59 LLVMValueRef *v_fcinfo_isnull);
64 int natts, LLVMValueRef *v_args);
68 #define build_EvalXFunc(b, mod, funcname, v_state, op, ...) \
69 build_EvalXFuncInt(b, mod, funcname, v_state, op, \
70 lengthof(((LLVMValueRef[]){__VA_ARGS__})), \
71 ((LLVMValueRef[]){__VA_ARGS__}))
89 LLVMBasicBlockRef entry;
90 LLVMBasicBlockRef *opblocks;
94 LLVMValueRef v_econtext;
95 LLVMValueRef v_parent;
98 LLVMValueRef v_isnullp;
101 LLVMValueRef v_tmpvaluep;
102 LLVMValueRef v_tmpisnullp;
105 LLVMValueRef v_innerslot;
106 LLVMValueRef v_outerslot;
107 LLVMValueRef v_scanslot;
108 LLVMValueRef v_resultslot;
111 LLVMValueRef v_innervalues;
112 LLVMValueRef v_innernulls;
113 LLVMValueRef v_outervalues;
114 LLVMValueRef v_outernulls;
115 LLVMValueRef v_scanvalues;
116 LLVMValueRef v_scannulls;
117 LLVMValueRef v_resultvalues;
118 LLVMValueRef v_resultnulls;
121 LLVMValueRef v_aggvalues;
122 LLVMValueRef v_aggnulls;
149 lc = LLVMGetModuleContext(mod);
151 b = LLVMCreateBuilderInContext(lc);
156 eval_fn = LLVMAddFunction(mod,
funcname,
158 LLVMSetLinkage(eval_fn, LLVMExternalLinkage);
159 LLVMSetVisibility(eval_fn, LLVMDefaultVisibility);
162 entry = LLVMAppendBasicBlockInContext(lc, eval_fn,
"entry");
165 v_state = LLVMGetParam(eval_fn, 0);
166 v_econtext = LLVMGetParam(eval_fn, 1);
167 v_isnullp = LLVMGetParam(eval_fn, 2);
169 LLVMPositionBuilderAtEnd(
b, entry);
171 v_tmpvaluep = l_struct_gep(
b,
176 v_tmpisnullp = l_struct_gep(
b,
181 v_parent = l_load_struct_gep(
b,
188 v_scanslot = l_load_struct_gep(
b,
193 v_innerslot = l_load_struct_gep(
b,
198 v_outerslot = l_load_struct_gep(
b,
203 v_resultslot = l_load_struct_gep(
b,
210 v_scanvalues = l_load_struct_gep(
b,
215 v_scannulls = l_load_struct_gep(
b,
220 v_innervalues = l_load_struct_gep(
b,
225 v_innernulls = l_load_struct_gep(
b,
230 v_outervalues = l_load_struct_gep(
b,
235 v_outernulls = l_load_struct_gep(
b,
240 v_resultvalues = l_load_struct_gep(
b,
245 v_resultnulls = l_load_struct_gep(
b,
252 v_aggvalues = l_load_struct_gep(
b,
256 "v.econtext.aggvalues");
257 v_aggnulls = l_load_struct_gep(
b,
261 "v.econtext.aggnulls");
264 opblocks =
palloc(
sizeof(LLVMBasicBlockRef) *
state->steps_len);
265 for (
int opno = 0; opno <
state->steps_len; opno++)
266 opblocks[opno] = l_bb_append_v(eval_fn,
"b.op.%d.start", opno);
269 LLVMBuildBr(
b, opblocks[0]);
271 for (
int opno = 0; opno <
state->steps_len; opno++)
275 LLVMValueRef v_resvaluep;
276 LLVMValueRef v_resnullp;
278 LLVMPositionBuilderAtEnd(
b, opblocks[opno]);
280 op = &
state->steps[opno];
290 LLVMValueRef v_tmpisnull;
291 LLVMValueRef v_tmpvalue;
293 v_tmpvalue = l_load(
b,
TypeSizeT, v_tmpvaluep,
"");
296 LLVMBuildStore(
b, v_tmpisnull, v_isnullp);
298 LLVMBuildRet(
b, v_tmpvalue);
308 LLVMBasicBlockRef b_fetch;
309 LLVMValueRef v_nvalid;
310 LLVMValueRef l_jit_deform = NULL;
313 b_fetch = l_bb_before_v(opblocks[opno + 1],
314 "op.%d.fetch", opno);
316 if (op->
d.
fetch.known_desc)
317 desc = op->
d.
fetch.known_desc;
320 tts_ops = op->
d.
fetch.kind;
326 v_slot = v_innerslot;
328 v_slot = v_outerslot;
343 LLVMBuildICmp(
b, LLVMIntUGE, v_nvalid,
344 l_int16_const(lc, op->
d.
fetch.last_var),
346 opblocks[opno + 1], b_fetch);
348 LLVMPositionBuilderAtEnd(
b, b_fetch);
365 deform_endtime, deform_starttime);
370 LLVMValueRef params[1];
381 LLVMValueRef params[2];
384 params[1] = l_int32_const(lc, op->
d.
fetch.last_var);
392 LLVMBuildBr(
b, opblocks[opno + 1]);
402 LLVMValueRef v_attnum;
403 LLVMValueRef v_values;
404 LLVMValueRef v_nulls;
408 v_values = v_innervalues;
409 v_nulls = v_innernulls;
413 v_values = v_outervalues;
414 v_nulls = v_outernulls;
418 v_values = v_scanvalues;
419 v_nulls = v_scannulls;
422 v_attnum = l_int32_const(lc, op->
d.
var.attnum);
425 LLVMBuildStore(
b,
value, v_resvaluep);
426 LLVMBuildStore(
b, isnull, v_resnullp);
428 LLVMBuildBr(
b, opblocks[opno + 1]);
439 v_slot = v_innerslot;
441 v_slot = v_outerslot;
446 v_state, op, v_econtext, v_slot);
448 LLVMBuildBr(
b, opblocks[opno + 1]);
454 v_state, op, v_econtext);
455 LLVMBuildBr(
b, opblocks[opno + 1]);
462 LLVMValueRef v_value;
463 LLVMValueRef v_isnull;
464 LLVMValueRef v_rvaluep;
465 LLVMValueRef v_risnullp;
466 LLVMValueRef v_attnum;
467 LLVMValueRef v_resultnum;
468 LLVMValueRef v_values;
469 LLVMValueRef v_nulls;
473 v_values = v_innervalues;
474 v_nulls = v_innernulls;
478 v_values = v_outervalues;
479 v_nulls = v_outernulls;
483 v_values = v_scanvalues;
484 v_nulls = v_scannulls;
488 v_attnum = l_int32_const(lc, op->
d.
assign_var.attnum);
489 v_value = l_load_gep1(
b,
TypeSizeT, v_values, v_attnum,
"");
493 v_resultnum = l_int32_const(lc, op->
d.
assign_var.resultnum);
497 &v_resultnum, 1,
"");
498 v_risnullp = l_gep(
b,
501 &v_resultnum, 1,
"");
504 LLVMBuildStore(
b, v_value, v_rvaluep);
505 LLVMBuildStore(
b, v_isnull, v_risnullp);
507 LLVMBuildBr(
b, opblocks[opno + 1]);
514 LLVMValueRef v_value,
516 LLVMValueRef v_rvaluep,
518 LLVMValueRef v_resultnum;
522 v_value = l_load(
b,
TypeSizeT, v_tmpvaluep,
"");
526 v_resultnum = l_int32_const(lc, resultnum);
528 l_gep(
b,
TypeSizeT, v_resultvalues, &v_resultnum, 1,
"");
533 LLVMBuildStore(
b, v_isnull, v_risnullp);
538 LLVMBasicBlockRef b_notnull;
539 LLVMValueRef v_params[1];
541 b_notnull = l_bb_before_v(opblocks[opno + 1],
542 "op.%d.assign_tmp.notnull", opno);
546 LLVMBuildICmp(
b, LLVMIntEQ, v_isnull,
547 l_sbool_const(0),
""),
548 b_notnull, opblocks[opno + 1]);
551 LLVMPositionBuilderAtEnd(
b, b_notnull);
552 v_params[0] = v_value;
556 llvm_pg_func(mod,
"MakeExpandedObjectReadOnlyInternal"),
566 LLVMBuildStore(
b, v_value, v_rvaluep);
568 LLVMBuildBr(
b, opblocks[opno + 1]);
574 LLVMValueRef v_constvalue,
577 v_constvalue = l_sizet_const(op->
d.
constval.value);
578 v_constnull = l_sbool_const(op->
d.
constval.isnull);
580 LLVMBuildStore(
b, v_constvalue, v_resvaluep);
581 LLVMBuildStore(
b, v_constnull, v_resnullp);
583 LLVMBuildBr(
b, opblocks[opno + 1]);
591 LLVMValueRef v_fcinfo_isnull;
592 LLVMValueRef v_retval;
596 LLVMBasicBlockRef b_nonull;
597 LLVMBasicBlockRef *b_checkargnulls;
598 LLVMValueRef v_fcinfo;
604 b_nonull = l_bb_before_v(opblocks[opno + 1],
605 "b.%d.no-null-args", opno);
608 if (op->
d.
func.nargs == 0)
609 elog(
ERROR,
"argumentless strict functions are pointless");
618 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
622 palloc(
sizeof(LLVMBasicBlockRef *) * op->
d.
func.nargs);
623 for (
int argno = 0; argno < op->
d.
func.nargs; argno++)
624 b_checkargnulls[argno] =
625 l_bb_before_v(b_nonull,
"b.%d.isnull.%d", opno,
629 LLVMBuildBr(
b, b_checkargnulls[0]);
632 for (
int argno = 0; argno < op->
d.
func.nargs; argno++)
634 LLVMValueRef v_argisnull;
635 LLVMBasicBlockRef b_argnotnull;
637 LLVMPositionBuilderAtEnd(
b, b_checkargnulls[argno]);
643 if (argno + 1 == op->
d.
func.nargs)
644 b_argnotnull = b_nonull;
646 b_argnotnull = b_checkargnulls[argno + 1];
649 v_argisnull = l_funcnull(
b, v_fcinfo, argno);
651 LLVMBuildICmp(
b, LLVMIntEQ,
659 LLVMPositionBuilderAtEnd(
b, b_nonull);
664 LLVMBuildStore(
b, v_retval, v_resvaluep);
665 LLVMBuildStore(
b, v_fcinfo_isnull, v_resnullp);
667 LLVMBuildBr(
b, opblocks[opno + 1]);
673 v_state, op, v_econtext);
674 LLVMBuildBr(
b, opblocks[opno + 1]);
680 v_state, op, v_econtext);
681 LLVMBuildBr(
b, opblocks[opno + 1]);
693 LLVMValueRef v_boolvalue;
694 LLVMValueRef v_boolnull;
695 LLVMValueRef v_boolanynullp,
697 LLVMBasicBlockRef b_boolisnull;
698 LLVMBasicBlockRef b_boolcheckfalse;
699 LLVMBasicBlockRef b_boolisfalse;
700 LLVMBasicBlockRef b_boolcont;
701 LLVMBasicBlockRef b_boolisanynull;
703 b_boolisnull = l_bb_before_v(opblocks[opno + 1],
704 "b.%d.boolisnull", opno);
705 b_boolcheckfalse = l_bb_before_v(opblocks[opno + 1],
706 "b.%d.boolcheckfalse", opno);
707 b_boolisfalse = l_bb_before_v(opblocks[opno + 1],
708 "b.%d.boolisfalse", opno);
709 b_boolisanynull = l_bb_before_v(opblocks[opno + 1],
710 "b.%d.boolisanynull", opno);
711 b_boolcont = l_bb_before_v(opblocks[opno + 1],
712 "b.%d.boolcont", opno);
714 v_boolanynullp = l_ptr_const(op->
d.
boolexpr.anynull,
718 LLVMBuildStore(
b, l_sbool_const(0), v_boolanynullp);
721 v_boolvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
724 LLVMBuildStore(
b, v_boolnull, v_resnullp);
726 LLVMBuildStore(
b, v_boolvalue, v_resvaluep);
730 LLVMBuildICmp(
b, LLVMIntEQ, v_boolnull,
731 l_sbool_const(1),
""),
736 LLVMPositionBuilderAtEnd(
b, b_boolisnull);
738 LLVMBuildStore(
b, l_sbool_const(1), v_boolanynullp);
740 LLVMBuildBr(
b, b_boolcont);
743 LLVMPositionBuilderAtEnd(
b, b_boolcheckfalse);
745 LLVMBuildICmp(
b, LLVMIntEQ, v_boolvalue,
746 l_sizet_const(0),
""),
754 LLVMPositionBuilderAtEnd(
b, b_boolisfalse);
757 LLVMBuildBr(
b, opblocks[op->
d.
boolexpr.jumpdone]);
760 LLVMPositionBuilderAtEnd(
b, b_boolcont);
766 LLVMBuildICmp(
b, LLVMIntEQ, v_boolanynull,
767 l_sbool_const(0),
""),
768 opblocks[opno + 1], b_boolisanynull);
770 LLVMPositionBuilderAtEnd(
b, b_boolisanynull);
772 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
774 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
776 LLVMBuildBr(
b, opblocks[opno + 1]);
789 LLVMValueRef v_boolvalue;
790 LLVMValueRef v_boolnull;
791 LLVMValueRef v_boolanynullp,
794 LLVMBasicBlockRef b_boolisnull;
795 LLVMBasicBlockRef b_boolchecktrue;
796 LLVMBasicBlockRef b_boolistrue;
797 LLVMBasicBlockRef b_boolcont;
798 LLVMBasicBlockRef b_boolisanynull;
800 b_boolisnull = l_bb_before_v(opblocks[opno + 1],
801 "b.%d.boolisnull", opno);
802 b_boolchecktrue = l_bb_before_v(opblocks[opno + 1],
803 "b.%d.boolchecktrue", opno);
804 b_boolistrue = l_bb_before_v(opblocks[opno + 1],
805 "b.%d.boolistrue", opno);
806 b_boolisanynull = l_bb_before_v(opblocks[opno + 1],
807 "b.%d.boolisanynull", opno);
808 b_boolcont = l_bb_before_v(opblocks[opno + 1],
809 "b.%d.boolcont", opno);
811 v_boolanynullp = l_ptr_const(op->
d.
boolexpr.anynull,
815 LLVMBuildStore(
b, l_sbool_const(0), v_boolanynullp);
817 v_boolvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
820 LLVMBuildStore(
b, v_boolnull, v_resnullp);
822 LLVMBuildStore(
b, v_boolvalue, v_resvaluep);
825 LLVMBuildICmp(
b, LLVMIntEQ, v_boolnull,
826 l_sbool_const(1),
""),
831 LLVMPositionBuilderAtEnd(
b, b_boolisnull);
833 LLVMBuildStore(
b, l_sbool_const(1), v_boolanynullp);
835 LLVMBuildBr(
b, b_boolcont);
838 LLVMPositionBuilderAtEnd(
b, b_boolchecktrue);
840 LLVMBuildICmp(
b, LLVMIntEQ, v_boolvalue,
841 l_sizet_const(1),
""),
849 LLVMPositionBuilderAtEnd(
b, b_boolistrue);
852 LLVMBuildBr(
b, opblocks[op->
d.
boolexpr.jumpdone]);
855 LLVMPositionBuilderAtEnd(
b, b_boolcont);
861 LLVMBuildICmp(
b, LLVMIntEQ, v_boolanynull,
862 l_sbool_const(0),
""),
863 opblocks[opno + 1], b_boolisanynull);
865 LLVMPositionBuilderAtEnd(
b, b_boolisanynull);
867 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
869 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
871 LLVMBuildBr(
b, opblocks[opno + 1]);
877 LLVMValueRef v_boolvalue;
878 LLVMValueRef v_boolnull;
879 LLVMValueRef v_negbool;
882 v_boolvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
884 v_negbool = LLVMBuildZExt(
b,
885 LLVMBuildICmp(
b, LLVMIntEQ,
891 LLVMBuildStore(
b, v_boolnull, v_resnullp);
893 LLVMBuildStore(
b, v_negbool, v_resvaluep);
895 LLVMBuildBr(
b, opblocks[opno + 1]);
901 LLVMValueRef v_resnull;
902 LLVMValueRef v_resvalue;
903 LLVMValueRef v_nullorfalse;
904 LLVMBasicBlockRef b_qualfail;
906 b_qualfail = l_bb_before_v(opblocks[opno + 1],
907 "op.%d.qualfail", opno);
909 v_resvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
914 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
915 l_sbool_const(1),
""),
916 LLVMBuildICmp(
b, LLVMIntEQ, v_resvalue,
917 l_sizet_const(0),
""),
926 LLVMPositionBuilderAtEnd(
b, b_qualfail);
928 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
930 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
932 LLVMBuildBr(
b, opblocks[op->
d.
qualexpr.jumpdone]);
938 LLVMBuildBr(
b, opblocks[op->
d.
jump.jumpdone]);
944 LLVMValueRef v_resnull;
951 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
952 l_sbool_const(1),
""),
953 opblocks[op->
d.
jump.jumpdone],
960 LLVMValueRef v_resnull;
967 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
968 l_sbool_const(0),
""),
969 opblocks[op->
d.
jump.jumpdone],
977 LLVMValueRef v_resnull;
978 LLVMValueRef v_resvalue;
979 LLVMValueRef v_nullorfalse;
983 v_resvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
988 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
989 l_sbool_const(1),
""),
990 LLVMBuildICmp(
b, LLVMIntEQ, v_resvalue,
991 l_sizet_const(0),
""),
996 opblocks[op->
d.
jump.jumpdone],
1004 LLVMValueRef v_resvalue;
1008 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
1009 l_sbool_const(1),
""),
1013 LLVMBuildStore(
b, v_resvalue, v_resvaluep);
1014 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1016 LLVMBuildBr(
b, opblocks[opno + 1]);
1023 LLVMValueRef v_resvalue;
1027 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
1028 l_sbool_const(1),
""),
1032 LLVMBuildStore(
b, v_resvalue, v_resvaluep);
1033 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1035 LLVMBuildBr(
b, opblocks[opno + 1]);
1041 v_state, op, v_econtext);
1042 LLVMBuildBr(
b, opblocks[opno + 1]);
1047 v_state, op, v_econtext);
1048 LLVMBuildBr(
b, opblocks[opno + 1]);
1056 LLVMBasicBlockRef b_isnull,
1060 b_isnull = l_bb_before_v(opblocks[opno + 1],
1061 "op.%d.isnull", opno);
1062 b_notnull = l_bb_before_v(opblocks[opno + 1],
1063 "op.%d.isnotnull", opno);
1067 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
1068 l_sbool_const(1),
""),
1069 b_isnull, b_notnull);
1072 LLVMPositionBuilderAtEnd(
b, b_isnull);
1075 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1080 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
1084 LLVMBuildStore(
b, l_sizet_const(1), v_resvaluep);
1087 LLVMBuildBr(
b, opblocks[opno + 1]);
1089 LLVMPositionBuilderAtEnd(
b, b_notnull);
1101 LLVMValueRef v_value =
1104 v_value = LLVMBuildZExt(
b,
1105 LLVMBuildICmp(
b, LLVMIntEQ,
1110 LLVMBuildStore(
b, v_value, v_resvaluep);
1112 LLVMBuildBr(
b, opblocks[opno + 1]);
1118 v_state, op, v_econtext);
1119 LLVMBuildBr(
b, opblocks[opno + 1]);
1124 v_state, op, v_econtext);
1125 LLVMBuildBr(
b, opblocks[opno + 1]);
1130 LLVMValueRef v_func;
1131 LLVMValueRef v_params[3];
1133 v_func = l_ptr_const(op->
d.
cparam.paramfunc,
1136 v_params[0] = v_state;
1138 v_params[2] = v_econtext;
1144 LLVMBuildBr(
b, opblocks[opno + 1]);
1150 v_state, op, v_econtext);
1151 LLVMBuildBr(
b, opblocks[opno + 1]);
1157 LLVMValueRef v_func;
1158 LLVMValueRef v_params[3];
1164 v_params[0] = v_state;
1166 v_params[2] = v_econtext;
1174 LLVMBuildICmp(
b, LLVMIntEQ, v_ret,
1175 l_sbool_const(1),
""),
1177 opblocks[jumpdone]);
1185 LLVMValueRef v_func;
1186 LLVMValueRef v_params[3];
1188 v_func = l_ptr_const(op->
d.
sbsref.subscriptfunc,
1191 v_params[0] = v_state;
1193 v_params[2] = v_econtext;
1199 LLVMBuildBr(
b, opblocks[opno + 1]);
1205 LLVMBasicBlockRef b_avail,
1207 LLVMValueRef v_casevaluep,
1209 LLVMValueRef v_casenullp,
1211 LLVMValueRef v_casevaluenull;
1213 b_avail = l_bb_before_v(opblocks[opno + 1],
1214 "op.%d.avail", opno);
1215 b_notavail = l_bb_before_v(opblocks[opno + 1],
1216 "op.%d.notavail", opno);
1218 v_casevaluep = l_ptr_const(op->
d.
casetest.value,
1220 v_casenullp = l_ptr_const(op->
d.
casetest.isnull,
1224 LLVMBuildICmp(
b, LLVMIntEQ,
1225 LLVMBuildPtrToInt(
b, v_casevaluep,
1227 l_sizet_const(0),
"");
1228 LLVMBuildCondBr(
b, v_casevaluenull, b_notavail, b_avail);
1231 LLVMPositionBuilderAtEnd(
b, b_avail);
1232 v_casevalue = l_load(
b,
TypeSizeT, v_casevaluep,
"");
1234 LLVMBuildStore(
b, v_casevalue, v_resvaluep);
1235 LLVMBuildStore(
b, v_casenull, v_resnullp);
1236 LLVMBuildBr(
b, opblocks[opno + 1]);
1239 LLVMPositionBuilderAtEnd(
b, b_notavail);
1241 l_load_struct_gep(
b,
1246 l_load_struct_gep(
b,
1250 LLVMBuildStore(
b, v_casevalue, v_resvaluep);
1251 LLVMBuildStore(
b, v_casenull, v_resnullp);
1253 LLVMBuildBr(
b, opblocks[opno + 1]);
1259 LLVMBasicBlockRef b_notnull;
1260 LLVMValueRef v_params[1];
1262 LLVMValueRef v_nullp;
1263 LLVMValueRef v_valuep;
1264 LLVMValueRef v_null;
1265 LLVMValueRef v_value;
1267 b_notnull = l_bb_before_v(opblocks[opno + 1],
1268 "op.%d.readonly.notnull", opno);
1276 LLVMBuildStore(
b, v_null, v_resnullp);
1280 LLVMBuildICmp(
b, LLVMIntEQ, v_null,
1281 l_sbool_const(1),
""),
1282 opblocks[opno + 1], b_notnull);
1285 LLVMPositionBuilderAtEnd(
b, b_notnull);
1290 v_value = l_load(
b,
TypeSizeT, v_valuep,
"");
1292 v_params[0] = v_value;
1296 llvm_pg_func(mod,
"MakeExpandedObjectReadOnlyInternal"),
1298 LLVMBuildStore(
b, v_ret, v_resvaluep);
1300 LLVMBuildBr(
b, opblocks[opno + 1]);
1308 LLVMValueRef v_fn_out,
1310 LLVMValueRef v_fcinfo_out,
1312 LLVMValueRef v_fcinfo_in_isnullp;
1313 LLVMValueRef v_retval;
1314 LLVMValueRef v_resvalue;
1315 LLVMValueRef v_resnull;
1317 LLVMValueRef v_output_skip;
1318 LLVMValueRef v_output;
1320 LLVMBasicBlockRef b_skipoutput;
1321 LLVMBasicBlockRef b_calloutput;
1322 LLVMBasicBlockRef b_input;
1323 LLVMBasicBlockRef b_inputcall;
1325 fcinfo_out = op->
d.
iocoerce.fcinfo_data_out;
1326 fcinfo_in = op->
d.
iocoerce.fcinfo_data_in;
1328 b_skipoutput = l_bb_before_v(opblocks[opno + 1],
1329 "op.%d.skipoutputnull", opno);
1330 b_calloutput = l_bb_before_v(opblocks[opno + 1],
1331 "op.%d.calloutput", opno);
1332 b_input = l_bb_before_v(opblocks[opno + 1],
1333 "op.%d.input", opno);
1334 b_inputcall = l_bb_before_v(opblocks[opno + 1],
1335 "op.%d.inputcall", opno);
1342 v_fcinfo_in_isnullp =
1347 "v_fcinfo_in_isnull");
1352 LLVMBuildICmp(
b, LLVMIntEQ, v_resnull,
1353 l_sbool_const(1),
""),
1357 LLVMPositionBuilderAtEnd(
b, b_skipoutput);
1358 v_output_skip = l_sizet_const(0);
1359 LLVMBuildBr(
b, b_input);
1361 LLVMPositionBuilderAtEnd(
b, b_calloutput);
1362 v_resvalue = l_load(
b,
TypeSizeT, v_resvaluep,
"");
1367 l_funcvaluep(
b, v_fcinfo_out, 0));
1370 l_funcnullp(
b, v_fcinfo_out, 0));
1372 v_output = l_call(
b,
1374 v_fn_out, &v_fcinfo_out,
1375 1,
"funccall_coerce_out");
1376 LLVMBuildBr(
b, b_input);
1379 LLVMPositionBuilderAtEnd(
b, b_input);
1383 LLVMValueRef incoming_values[2];
1384 LLVMBasicBlockRef incoming_blocks[2];
1386 incoming_values[0] = v_output_skip;
1387 incoming_blocks[0] = b_skipoutput;
1389 incoming_values[1] = v_output;
1390 incoming_blocks[1] = b_calloutput;
1392 v_output = LLVMBuildPhi(
b,
TypeSizeT,
"output");
1393 LLVMAddIncoming(v_output,
1394 incoming_values, incoming_blocks,
1405 LLVMBuildICmp(
b, LLVMIntEQ, v_output,
1406 l_sizet_const(0),
""),
1412 LLVMBuildBr(
b, b_inputcall);
1415 LLVMPositionBuilderAtEnd(
b, b_inputcall);
1418 LLVMBuildStore(
b, v_output,
1419 l_funcvaluep(
b, v_fcinfo_in, 0));
1420 LLVMBuildStore(
b, v_resnull,
1421 l_funcnullp(
b, v_fcinfo_in, 0));
1427 LLVMBuildStore(
b, l_sbool_const(0), v_fcinfo_in_isnullp);
1429 v_retval = l_call(
b,
1431 v_fn_in, &v_fcinfo_in, 1,
1432 "funccall_iocoerce_in");
1434 LLVMBuildStore(
b, v_retval, v_resvaluep);
1436 LLVMBuildBr(
b, opblocks[opno + 1]);
1443 LLVMBuildBr(
b, opblocks[opno + 1]);
1451 LLVMValueRef v_fcinfo;
1452 LLVMValueRef v_fcinfo_isnull;
1454 LLVMValueRef v_argnull0,
1456 LLVMValueRef v_argnull1,
1459 LLVMValueRef v_anyargisnull;
1460 LLVMValueRef v_bothargisnull;
1462 LLVMValueRef v_result;
1464 LLVMBasicBlockRef b_noargnull;
1465 LLVMBasicBlockRef b_checkbothargnull;
1466 LLVMBasicBlockRef b_bothargnull;
1467 LLVMBasicBlockRef b_anyargnull;
1469 b_noargnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.noargnull", opno);
1470 b_checkbothargnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.checkbothargnull", opno);
1471 b_bothargnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.bothargnull", opno);
1472 b_anyargnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.anyargnull", opno);
1477 v_argnull0 = l_funcnull(
b, v_fcinfo, 0);
1478 v_argisnull0 = LLVMBuildICmp(
b, LLVMIntEQ, v_argnull0,
1479 l_sbool_const(1),
"");
1480 v_argnull1 = l_funcnull(
b, v_fcinfo, 1);
1481 v_argisnull1 = LLVMBuildICmp(
b, LLVMIntEQ, v_argnull1,
1482 l_sbool_const(1),
"");
1484 v_anyargisnull = LLVMBuildOr(
b, v_argisnull0, v_argisnull1,
"");
1485 v_bothargisnull = LLVMBuildAnd(
b, v_argisnull0, v_argisnull1,
"");
1492 LLVMBuildCondBr(
b, v_anyargisnull, b_checkbothargnull,
1498 LLVMPositionBuilderAtEnd(
b, b_checkbothargnull);
1499 LLVMBuildCondBr(
b, v_bothargisnull, b_bothargnull,
1504 LLVMPositionBuilderAtEnd(
b, b_bothargnull);
1505 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1507 LLVMBuildStore(
b, l_sizet_const(1), v_resvaluep);
1509 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
1511 LLVMBuildBr(
b, opblocks[opno + 1]);
1514 LLVMPositionBuilderAtEnd(
b, b_anyargnull);
1515 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1517 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
1519 LLVMBuildStore(
b, l_sizet_const(1), v_resvaluep);
1520 LLVMBuildBr(
b, opblocks[opno + 1]);
1523 LLVMPositionBuilderAtEnd(
b, b_noargnull);
1533 LLVMBuildICmp(
b, LLVMIntEQ,
1535 l_sizet_const(0),
""),
1539 LLVMBuildStore(
b, v_fcinfo_isnull, v_resnullp);
1540 LLVMBuildStore(
b, v_result, v_resvaluep);
1542 LLVMBuildBr(
b, opblocks[opno + 1]);
1550 LLVMValueRef v_fcinfo;
1551 LLVMValueRef v_fcinfo_isnull;
1552 LLVMValueRef v_argnull0;
1553 LLVMValueRef v_argnull1;
1554 LLVMValueRef v_anyargisnull;
1555 LLVMValueRef v_arg0;
1556 LLVMBasicBlockRef b_hasnull;
1557 LLVMBasicBlockRef b_nonull;
1558 LLVMBasicBlockRef b_argsequal;
1559 LLVMValueRef v_retval;
1560 LLVMValueRef v_argsequal;
1562 b_hasnull = l_bb_before_v(opblocks[opno + 1],
1563 "b.%d.null-args", opno);
1564 b_nonull = l_bb_before_v(opblocks[opno + 1],
1565 "b.%d.no-null-args", opno);
1566 b_argsequal = l_bb_before_v(opblocks[opno + 1],
1567 "b.%d.argsequal", opno);
1572 v_argnull0 = l_funcnull(
b, v_fcinfo, 0);
1573 v_argnull1 = l_funcnull(
b, v_fcinfo, 1);
1577 LLVMBuildICmp(
b, LLVMIntEQ, v_argnull0,
1578 l_sbool_const(1),
""),
1579 LLVMBuildICmp(
b, LLVMIntEQ, v_argnull1,
1580 l_sbool_const(1),
""),
1583 LLVMBuildCondBr(
b, v_anyargisnull, b_hasnull, b_nonull);
1586 LLVMPositionBuilderAtEnd(
b, b_hasnull);
1587 v_arg0 = l_funcvalue(
b, v_fcinfo, 0);
1588 LLVMBuildStore(
b, v_argnull0, v_resnullp);
1589 LLVMBuildStore(
b, v_arg0, v_resvaluep);
1590 LLVMBuildBr(
b, opblocks[opno + 1]);
1593 LLVMPositionBuilderAtEnd(
b, b_nonull);
1602 v_argsequal = LLVMBuildAnd(
b,
1603 LLVMBuildICmp(
b, LLVMIntEQ,
1607 LLVMBuildICmp(
b, LLVMIntEQ,
1612 LLVMBuildCondBr(
b, v_argsequal, b_argsequal, b_hasnull);
1615 LLVMPositionBuilderAtEnd(
b, b_argsequal);
1616 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
1617 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
1618 LLVMBuildStore(
b, v_retval, v_resvaluep);
1620 LLVMBuildBr(
b, opblocks[opno + 1]);
1627 LLVMBuildBr(
b, opblocks[opno + 1]);
1633 LLVMBuildBr(
b, opblocks[opno + 1]);
1639 LLVMBuildBr(
b, opblocks[opno + 1]);
1645 LLVMBuildBr(
b, opblocks[opno + 1]);
1650 v_state, op, v_econtext);
1651 LLVMBuildBr(
b, opblocks[opno + 1]);
1657 LLVMBuildBr(
b, opblocks[opno + 1]);
1663 LLVMValueRef v_fcinfo_isnull;
1664 LLVMBasicBlockRef b_null;
1665 LLVMBasicBlockRef b_compare;
1666 LLVMBasicBlockRef b_compare_result;
1668 LLVMValueRef v_retval;
1670 b_null = l_bb_before_v(opblocks[opno + 1],
1671 "op.%d.row-null", opno);
1672 b_compare = l_bb_before_v(opblocks[opno + 1],
1673 "op.%d.row-compare", opno);
1675 l_bb_before_v(opblocks[opno + 1],
1676 "op.%d.row-compare-result",
1685 LLVMValueRef v_fcinfo;
1686 LLVMValueRef v_argnull0;
1687 LLVMValueRef v_argnull1;
1688 LLVMValueRef v_anyargisnull;
1690 v_fcinfo = l_ptr_const(fcinfo,
1693 v_argnull0 = l_funcnull(
b, v_fcinfo, 0);
1694 v_argnull1 = l_funcnull(
b, v_fcinfo, 1);
1703 LLVMBuildICmp(
b, LLVMIntEQ,
1705 l_sbool_const(1),
""),
1708 LLVMBuildCondBr(
b, v_anyargisnull, b_null, b_compare);
1712 LLVMBuildBr(
b, b_compare);
1716 LLVMPositionBuilderAtEnd(
b, b_compare);
1721 LLVMBuildStore(
b, v_retval, v_resvaluep);
1734 LLVMPositionBuilderAtEnd(
b, b_compare_result);
1741 l_sizet_const(0),
""),
1749 LLVMPositionBuilderAtEnd(
b, b_null);
1750 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
1760 LLVMValueRef v_cmpresult;
1761 LLVMValueRef v_result;
1762 LLVMIntPredicate predicate;
1772 LLVMInt32TypeInContext(lc),
"");
1777 predicate = LLVMIntSLT;
1780 predicate = LLVMIntSLE;
1783 predicate = LLVMIntSGT;
1786 predicate = LLVMIntSGE;
1795 v_result = LLVMBuildICmp(
b,
1798 l_int32_const(lc, 0),
1800 v_result = LLVMBuildZExt(
b, v_result,
TypeSizeT,
"");
1802 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1803 LLVMBuildStore(
b, v_result, v_resvaluep);
1805 LLVMBuildBr(
b, opblocks[opno + 1]);
1812 LLVMBuildBr(
b, opblocks[opno + 1]);
1817 v_state, op, v_econtext);
1818 LLVMBuildBr(
b, opblocks[opno + 1]);
1823 v_state, op, v_econtext);
1824 LLVMBuildBr(
b, opblocks[opno + 1]);
1829 v_state, op, v_econtext);
1830 LLVMBuildBr(
b, opblocks[opno + 1]);
1835 LLVMBasicBlockRef b_avail,
1837 LLVMValueRef v_casevaluep,
1839 LLVMValueRef v_casenullp,
1841 LLVMValueRef v_casevaluenull;
1843 b_avail = l_bb_before_v(opblocks[opno + 1],
1844 "op.%d.avail", opno);
1845 b_notavail = l_bb_before_v(opblocks[opno + 1],
1846 "op.%d.notavail", opno);
1848 v_casevaluep = l_ptr_const(op->
d.
casetest.value,
1850 v_casenullp = l_ptr_const(op->
d.
casetest.isnull,
1854 LLVMBuildICmp(
b, LLVMIntEQ,
1855 LLVMBuildPtrToInt(
b, v_casevaluep,
1857 l_sizet_const(0),
"");
1860 b_notavail, b_avail);
1863 LLVMPositionBuilderAtEnd(
b, b_avail);
1864 v_casevalue = l_load(
b,
TypeSizeT, v_casevaluep,
"");
1866 LLVMBuildStore(
b, v_casevalue, v_resvaluep);
1867 LLVMBuildStore(
b, v_casenull, v_resnullp);
1868 LLVMBuildBr(
b, opblocks[opno + 1]);
1871 LLVMPositionBuilderAtEnd(
b, b_notavail);
1873 l_load_struct_gep(
b,
1879 l_load_struct_gep(
b,
1884 LLVMBuildStore(
b, v_casevalue, v_resvaluep);
1885 LLVMBuildStore(
b, v_casenull, v_resnullp);
1887 LLVMBuildBr(
b, opblocks[opno + 1]);
1894 LLVMBuildBr(
b, opblocks[opno + 1]);
1900 LLVMBuildBr(
b, opblocks[opno + 1]);
1905 LLVMValueRef v_initvalue;
1909 LLVMBuildStore(
b, v_initvalue, v_resvaluep);
1910 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
1911 LLVMBuildBr(
b, opblocks[opno + 1]);
1921 LLVMValueRef v_fcinfo;
1922 LLVMValueRef v_fcinfo_isnull;
1923 LLVMValueRef v_retval;
1924 LLVMBasicBlockRef b_checkargnull;
1925 LLVMBasicBlockRef b_ifnotnull;
1926 LLVMBasicBlockRef b_ifnullblock;
1927 LLVMValueRef v_argisnull;
1928 LLVMValueRef v_prevhash = NULL;
1941 LLVMValueRef v_tmp1;
1942 LLVMValueRef v_tmp2;
1945 tmp = l_ptr_const(&op->
d.
hashdatum.iresult->value,
1952 v_prevhash = l_load(
b,
TypeSizeT, tmp,
"prevhash");
1958 v_tmp1 = LLVMBuildShl(
b, v_prevhash, l_sizet_const(1),
1960 v_tmp1 = LLVMBuildAnd(
b, v_tmp1,
1961 l_sizet_const(0xffffffff),
"");
1962 v_tmp2 = LLVMBuildLShr(
b, v_prevhash,
1963 l_sizet_const(31),
"");
1964 v_prevhash = LLVMBuildOr(
b, v_tmp1, v_tmp2,
1972 b_ifnotnull = l_bb_before_v(opblocks[opno + 1],
1977 if (fcinfo->
nargs != 1)
1978 elog(
ERROR,
"incorrect number of function arguments");
1980 v_fcinfo = l_ptr_const(fcinfo,
1983 b_checkargnull = l_bb_before_v(b_ifnotnull,
1984 "b.%d.isnull.0", opno);
1986 LLVMBuildBr(
b, b_checkargnull);
1995 b_ifnullblock = l_bb_before_v(b_ifnotnull,
1999 LLVMPositionBuilderAtEnd(
b, b_ifnullblock);
2005 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
2006 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
2007 LLVMBuildBr(
b, opblocks[op->
d.
hashdatum.jumpdone]);
2011 b_ifnullblock = l_bb_before_v(b_ifnotnull,
2015 LLVMPositionBuilderAtEnd(
b, b_ifnullblock);
2018 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
2022 Assert(v_prevhash != NULL);
2028 LLVMBuildStore(
b, v_prevhash, v_resvaluep);
2038 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
2041 LLVMBuildBr(
b, opblocks[opno + 1]);
2044 LLVMPositionBuilderAtEnd(
b, b_checkargnull);
2047 v_argisnull = l_funcnull(
b, v_fcinfo, 0);
2057 LLVMPositionBuilderAtEnd(
b, b_ifnotnull);
2066 LLVMValueRef v_tmp1;
2067 LLVMValueRef v_tmp2;
2070 tmp = l_ptr_const(&op->
d.
hashdatum.iresult->value,
2077 v_prevhash = l_load(
b,
TypeSizeT, tmp,
"prevhash");
2083 v_tmp1 = LLVMBuildShl(
b, v_prevhash, l_sizet_const(1),
2085 v_tmp1 = LLVMBuildAnd(
b, v_tmp1,
2086 l_sizet_const(0xffffffff),
"");
2087 v_tmp2 = LLVMBuildLShr(
b, v_prevhash,
2088 l_sizet_const(31),
"");
2089 v_prevhash = LLVMBuildOr(
b, v_tmp1, v_tmp2,
2103 v_retval = LLVMBuildXor(
b, v_prevhash, v_retval,
2106 LLVMBuildStore(
b, v_retval, v_resvaluep);
2107 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
2109 LLVMBuildBr(
b, opblocks[opno + 1]);
2115 v_state, op, v_econtext);
2116 LLVMBuildBr(
b, opblocks[opno + 1]);
2122 LLVMBuildBr(
b, opblocks[opno + 1]);
2127 v_state, op, v_econtext);
2128 LLVMBuildBr(
b, opblocks[opno + 1]);
2134 LLVMBuildBr(
b, opblocks[opno + 1]);
2139 v_state, op, v_econtext);
2140 LLVMBuildBr(
b, opblocks[opno + 1]);
2146 LLVMBuildBr(
b, opblocks[opno + 1]);
2159 v_state, op, v_econtext);
2171 LLVMValueRef v_jump_empty;
2172 LLVMValueRef v_jump_error;
2173 LLVMValueRef v_jump_coercion;
2174 LLVMValueRef v_switch;
2175 LLVMBasicBlockRef b_done,
2181 l_bb_before_v(opblocks[opno + 1],
2182 "op.%d.jsonexpr_empty", opno);
2184 l_bb_before_v(opblocks[opno + 1],
2185 "op.%d.jsonexpr_error", opno);
2187 l_bb_before_v(opblocks[opno + 1],
2188 "op.%d.jsonexpr_coercion", opno);
2190 l_bb_before_v(opblocks[opno + 1],
2191 "op.%d.jsonexpr_done", opno);
2193 v_switch = LLVMBuildSwitch(
b,
2200 v_jump_empty = l_int32_const(lc, jsestate->
jump_empty);
2201 LLVMAddCase(v_switch, v_jump_empty, b_empty);
2204 LLVMPositionBuilderAtEnd(
b, b_empty);
2208 LLVMBuildUnreachable(
b);
2213 v_jump_error = l_int32_const(lc, jsestate->
jump_error);
2214 LLVMAddCase(v_switch, v_jump_error, b_error);
2217 LLVMPositionBuilderAtEnd(
b, b_error);
2221 LLVMBuildUnreachable(
b);
2227 LLVMAddCase(v_switch, v_jump_coercion, b_coercion);
2230 LLVMPositionBuilderAtEnd(
b, b_coercion);
2234 LLVMBuildUnreachable(
b);
2236 LLVMPositionBuilderAtEnd(
b, b_done);
2239 LLVMBuildBr(
b, opblocks[jsestate->
jump_end]);
2245 v_state, op, v_econtext);
2247 LLVMBuildBr(
b, opblocks[opno + 1]);
2254 LLVMBuildBr(
b, opblocks[opno + 1]);
2259 LLVMValueRef v_aggno;
2263 v_aggno = l_int32_const(lc, op->
d.
aggref.aggno);
2270 LLVMBuildStore(
b,
value, v_resvaluep);
2271 LLVMBuildStore(
b, isnull, v_resnullp);
2273 LLVMBuildBr(
b, opblocks[opno + 1]);
2280 LLVMBuildBr(
b, opblocks[opno + 1]);
2286 LLVMValueRef v_wfuncnop;
2287 LLVMValueRef v_wfuncno;
2296 v_wfuncnop = l_ptr_const(&wfunc->
wfuncno,
2297 l_ptr(LLVMInt32TypeInContext(lc)));
2298 v_wfuncno = l_load(
b, LLVMInt32TypeInContext(lc), v_wfuncnop,
"v_wfuncno");
2306 LLVMBuildStore(
b,
value, v_resvaluep);
2307 LLVMBuildStore(
b, isnull, v_resnullp);
2309 LLVMBuildBr(
b, opblocks[opno + 1]);
2315 v_state, op, v_econtext);
2316 LLVMBuildBr(
b, opblocks[opno + 1]);
2321 v_state, op, v_econtext);
2322 LLVMBuildBr(
b, opblocks[opno + 1]);
2331 LLVMValueRef v_retval;
2332 LLVMValueRef v_fcinfo_isnull;
2333 LLVMValueRef v_tmpcontext;
2334 LLVMValueRef v_oldcontext;
2338 LLVMValueRef v_fcinfo;
2339 LLVMValueRef v_argnull0;
2340 LLVMBasicBlockRef b_deserialize;
2342 b_deserialize = l_bb_before_v(opblocks[opno + 1],
2343 "op.%d.deserialize", opno);
2345 v_fcinfo = l_ptr_const(fcinfo,
2347 v_argnull0 = l_funcnull(
b, v_fcinfo, 0);
2357 LLVMPositionBuilderAtEnd(
b, b_deserialize);
2366 v_oldcontext = l_mcxt_switch(mod,
b, v_tmpcontext);
2369 l_mcxt_switch(mod,
b, v_oldcontext);
2371 LLVMBuildStore(
b, v_retval, v_resvaluep);
2372 LLVMBuildStore(
b, v_fcinfo_isnull, v_resnullp);
2374 LLVMBuildBr(
b, opblocks[opno + 1]);
2386 LLVMValueRef v_argsp;
2387 LLVMValueRef v_nullsp;
2388 LLVMBasicBlockRef *b_checknulls;
2397 b_checknulls =
palloc(
sizeof(LLVMBasicBlockRef *) * nargs);
2398 for (
int argno = 0; argno < nargs; argno++)
2400 b_checknulls[argno] =
2401 l_bb_before_v(opblocks[opno + 1],
2402 "op.%d.check-null.%d",
2406 LLVMBuildBr(
b, b_checknulls[0]);
2409 for (
int argno = 0; argno < nargs; argno++)
2411 LLVMValueRef v_argno = l_int32_const(lc, argno);
2412 LLVMValueRef v_argisnull;
2413 LLVMBasicBlockRef b_argnotnull;
2415 LLVMPositionBuilderAtEnd(
b, b_checknulls[argno]);
2417 if (argno + 1 == nargs)
2418 b_argnotnull = opblocks[opno + 1];
2420 b_argnotnull = b_checknulls[argno + 1];
2426 LLVMValueRef v_argn;
2439 l_sbool_const(1),
""),
2450 LLVMValueRef v_aggstatep;
2451 LLVMValueRef v_allpergroupsp;
2452 LLVMValueRef v_pergroup_allaggs;
2453 LLVMValueRef v_setoff;
2461 v_aggstatep = LLVMBuildBitCast(
b, v_parent,
2464 v_allpergroupsp = l_load_struct_gep(
b,
2468 "aggstate.all_pergroups");
2473 v_allpergroupsp, v_setoff,
"");
2476 LLVMBuildICmp(
b, LLVMIntEQ,
2477 LLVMBuildPtrToInt(
b, v_pergroup_allaggs,
TypeSizeT,
""),
2478 l_sizet_const(0),
""),
2480 opblocks[opno + 1]);
2495 LLVMValueRef v_aggstatep;
2496 LLVMValueRef v_fcinfo;
2497 LLVMValueRef v_fcinfo_isnull;
2499 LLVMValueRef v_transvaluep;
2500 LLVMValueRef v_transnullp;
2502 LLVMValueRef v_setoff;
2503 LLVMValueRef v_transno;
2505 LLVMValueRef v_aggcontext;
2507 LLVMValueRef v_allpergroupsp;
2508 LLVMValueRef v_current_setp;
2509 LLVMValueRef v_current_pertransp;
2510 LLVMValueRef v_curaggcontext;
2512 LLVMValueRef v_pertransp;
2514 LLVMValueRef v_pergroupp;
2516 LLVMValueRef v_retval;
2518 LLVMValueRef v_tmpcontext;
2519 LLVMValueRef v_oldcontext;
2528 v_pertransp = l_ptr_const(pertrans,
2536 l_load_struct_gep(
b,
2540 "aggstate.all_pergroups");
2541 v_setoff = l_int32_const(lc, op->
d.
agg_trans.setoff);
2542 v_transno = l_int32_const(lc, op->
d.
agg_trans.transno);
2547 v_allpergroupsp, v_setoff,
""),
2554 LLVMValueRef v_notransvalue;
2555 LLVMBasicBlockRef b_init;
2556 LLVMBasicBlockRef b_no_init;
2559 l_load_struct_gep(
b,
2565 b_init = l_bb_before_v(opblocks[opno + 1],
2566 "op.%d.inittrans", opno);
2567 b_no_init = l_bb_before_v(opblocks[opno + 1],
2568 "op.%d.no_inittrans", opno);
2571 LLVMBuildICmp(
b, LLVMIntEQ, v_notransvalue,
2572 l_sbool_const(1),
""),
2578 LLVMValueRef params[4];
2580 LLVMPositionBuilderAtEnd(
b, b_init);
2582 v_aggcontext = l_ptr_const(op->
d.
agg_trans.aggcontext,
2585 params[0] = v_aggstatep;
2586 params[1] = v_pertransp;
2587 params[2] = v_pergroupp;
2588 params[3] = v_aggcontext;
2596 LLVMBuildBr(
b, opblocks[opno + 1]);
2599 LLVMPositionBuilderAtEnd(
b, b_no_init);
2607 LLVMValueRef v_transnull;
2608 LLVMBasicBlockRef b_strictpass;
2610 b_strictpass = l_bb_before_v(opblocks[opno + 1],
2611 "op.%d.strictpass", opno);
2613 l_load_struct_gep(
b,
2620 LLVMBuildICmp(
b, LLVMIntEQ, v_transnull,
2621 l_sbool_const(1),
""),
2625 LLVMPositionBuilderAtEnd(
b, b_strictpass);
2629 v_fcinfo = l_ptr_const(fcinfo,
2631 v_aggcontext = l_ptr_const(op->
d.
agg_trans.aggcontext,
2639 "aggstate.current_set");
2645 "aggstate.curaggcontext");
2646 v_current_pertransp =
2651 "aggstate.curpertrans");
2654 LLVMBuildStore(
b, v_aggcontext, v_curaggcontext);
2655 LLVMBuildStore(
b, l_int32_const(lc, op->
d.
agg_trans.setno),
2657 LLVMBuildStore(
b, v_pertransp, v_current_pertransp);
2663 v_oldcontext = l_mcxt_switch(mod,
b, v_tmpcontext);
2683 l_funcvaluep(
b, v_fcinfo, 0));
2686 l_funcnullp(
b, v_fcinfo, 0));
2705 LLVMBasicBlockRef b_call;
2706 LLVMBasicBlockRef b_nocall;
2708 LLVMValueRef v_transvalue;
2709 LLVMValueRef v_transnull;
2710 LLVMValueRef v_newval;
2711 LLVMValueRef params[6];
2713 b_call = l_bb_before_v(opblocks[opno + 1],
2714 "op.%d.transcall", opno);
2715 b_nocall = l_bb_before_v(opblocks[opno + 1],
2716 "op.%d.transnocall", opno);
2718 v_transvalue = l_load(
b,
TypeSizeT, v_transvaluep,
"");
2726 LLVMBuildICmp(
b, LLVMIntEQ,
2732 LLVMPositionBuilderAtEnd(
b, b_call);
2734 params[0] = v_aggstatep;
2735 params[1] = v_pertransp;
2736 params[2] = v_retval;
2737 params[3] = LLVMBuildTrunc(
b, v_fcinfo_isnull,
2739 params[4] = v_transvalue;
2740 params[5] = LLVMBuildTrunc(
b, v_transnull,
2752 LLVMBuildStore(
b, v_newval, v_transvaluep);
2753 LLVMBuildStore(
b, v_fcinfo_isnull, v_transnullp);
2755 l_mcxt_switch(mod,
b, v_oldcontext);
2756 LLVMBuildBr(
b, opblocks[opno + 1]);
2759 LLVMPositionBuilderAtEnd(
b, b_nocall);
2763 LLVMBuildStore(
b, v_retval, v_transvaluep);
2764 LLVMBuildStore(
b, v_fcinfo_isnull, v_transnullp);
2766 l_mcxt_switch(mod,
b, v_oldcontext);
2768 LLVMBuildBr(
b, opblocks[opno + 1]);
2778 LLVMValueRef v_fn =
llvm_pg_func(mod,
"ExecEvalPreOrderedDistinctSingle");
2779 LLVMValueRef v_args[2];
2789 LLVMBuildICmp(
b, LLVMIntEQ, v_ret,
2790 l_sbool_const(1),
""),
2792 opblocks[jumpdistinct]);
2802 LLVMValueRef v_fn =
llvm_pg_func(mod,
"ExecEvalPreOrderedDistinctMulti");
2803 LLVMValueRef v_args[2];
2813 LLVMBuildICmp(
b, LLVMIntEQ, v_ret,
2814 l_sbool_const(1),
""),
2816 opblocks[jumpdistinct]);
2822 v_state, op, v_econtext);
2823 LLVMBuildBr(
b, opblocks[opno + 1]);
2828 v_state, op, v_econtext);
2829 LLVMBuildBr(
b, opblocks[opno + 1]);
2838 LLVMDisposeBuilder(
b);
2854 state->evalfunc_private = cstate;
2861 endtime, starttime);
2889 state->evalfunc = func;
2891 return func(
state, econtext, isNull);
2897 LLVMValueRef *v_fcinfo_isnull)
2901 LLVMValueRef v_fcinfo_isnullp;
2902 LLVMValueRef v_retval;
2903 LLVMValueRef v_fcinfo;
2905 lc = LLVMGetModuleContext(mod);
2910 v_fcinfo_isnullp = l_struct_gep(
b,
2915 LLVMBuildStore(
b, l_sbool_const(0), v_fcinfo_isnullp);
2919 if (v_fcinfo_isnull)
2928 LLVMValueRef params[2];
2931 params[1] = l_ptr_const(fcinfo->
args, l_ptr(LLVMInt8TypeInContext(lc)));
2934 params[0] = l_int64_const(lc,
sizeof(fcinfo->
isnull));
2935 params[1] = l_ptr_const(&fcinfo->
isnull, l_ptr(LLVMInt8TypeInContext(lc)));
2948 int nargs, LLVMValueRef *v_args)
2951 LLVMValueRef *params;
2956 if (LLVMCountParams(v_fn) != (nargs + 2))
2957 elog(
ERROR,
"parameter mismatch: %s expects %d passed %d",
2958 funcname, LLVMCountParams(v_fn), nargs + 2);
2960 params =
palloc(
sizeof(LLVMValueRef) * (2 + nargs));
2962 params[argno++] = v_state;
2965 for (
int i = 0;
i < nargs;
i++)
2966 params[argno++] = v_args[
i];
2980 LLVMTypeRef param_types[2];
2984 const char *nm =
"llvm.lifetime.end.p0";
2986 fn = LLVMGetNamedFunction(mod, nm);
2990 lc = LLVMGetModuleContext(mod);
2991 param_types[0] = LLVMInt64TypeInContext(lc);
2992 param_types[1] = l_ptr(LLVMInt8TypeInContext(lc));
2994 sig = LLVMFunctionType(LLVMVoidTypeInContext(lc), param_types,
2996 fn = LLVMAddFunction(mod, nm,
sig);
2998 LLVMSetFunctionCallConv(
fn, LLVMCCallConv);
#define Assert(condition)
void CheckExprStillValid(ExprState *state, ExprContext *econtext)
ExprEvalOp ExecEvalStepOp(ExprState *state, ExprEvalStep *op)
@ EEOP_FUNCEXPR_STRICT_FUSAGE
@ EEOP_HASHDATUM_NEXT32_STRICT
@ EEOP_JSONEXPR_COERCION_FINISH
@ EEOP_HASHDATUM_FIRST_STRICT
@ EEOP_AGG_PLAIN_PERGROUP_NULLCHECK
@ EEOP_AGG_STRICT_DESERIALIZE
@ EEOP_BOOLTEST_IS_NOT_FALSE
@ EEOP_AGG_PLAIN_TRANS_BYREF
@ EEOP_AGG_PRESORTED_DISTINCT_MULTI
@ EEOP_AGG_PLAIN_TRANS_BYVAL
@ EEOP_NULLTEST_ROWISNOTNULL
@ EEOP_ASSIGN_TMP_MAKE_RO
@ EEOP_BOOL_OR_STEP_FIRST
@ EEOP_AGG_STRICT_INPUT_CHECK_NULLS
@ EEOP_AGG_STRICT_INPUT_CHECK_ARGS
@ EEOP_NULLTEST_ROWISNULL
@ EEOP_NULLTEST_ISNOTNULL
@ EEOP_MERGE_SUPPORT_FUNC
@ EEOP_AGG_PRESORTED_DISTINCT_SINGLE
@ EEOP_BOOL_AND_STEP_FIRST
@ EEOP_BOOL_AND_STEP_LAST
@ EEOP_AGG_ORDERED_TRANS_DATUM
@ EEOP_HASHDATUM_SET_INITVAL
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYREF
@ EEOP_BOOLTEST_IS_NOT_TRUE
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL
@ EEOP_AGG_PLAIN_TRANS_STRICT_BYVAL
@ EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYREF
@ EEOP_HASHED_SCALARARRAYOP
@ EEOP_AGG_ORDERED_TRANS_TUPLE
const TupleTableSlotOps TTSOpsVirtual
#define FIELDNO_EXPRSTATE_RESULTSLOT
#define FIELDNO_EXPRCONTEXT_CASENULL
#define FIELDNO_EXPRCONTEXT_INNERTUPLE
#define FIELDNO_EXPRCONTEXT_DOMAINNULL
#define FIELDNO_EXPRCONTEXT_DOMAINDATUM
#define FIELDNO_EXPRCONTEXT_CASEDATUM
#define FIELDNO_AGGSTATE_CURPERTRANS
#define FIELDNO_EXPRSTATE_RESNULL
#define FIELDNO_EXPRCONTEXT_AGGNULLS
#define FIELDNO_EXPRSTATE_RESVALUE
#define FIELDNO_AGGSTATE_CURRENT_SET
#define FIELDNO_EXPRCONTEXT_AGGVALUES
#define FIELDNO_EXPRCONTEXT_OUTERTUPLE
#define FIELDNO_AGGSTATE_ALL_PERGROUPS
#define FIELDNO_EXPRSTATE_PARENT
#define FIELDNO_EXPRCONTEXT_SCANTUPLE
#define FIELDNO_AGGSTATE_CURAGGCONTEXT
Datum(* ExprStateEvalFunc)(struct ExprState *expression, struct ExprContext *econtext, bool *isNull)
#define FIELDNO_FUNCTIONCALLINFODATA_ISNULL
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
LLVMTypeRef StructFunctionCallInfoData
LLVMTypeRef StructExprState
LLVMTypeRef StructExprEvalStep
LLVMValueRef llvm_pg_func(LLVMModuleRef mod, const char *funcname)
LLVMTypeRef TypeParamBool
LLVMTypeRef StructMemoryContextData
LLVMTypeRef StructAggStatePerGroupData
LLVMTypeRef llvm_pg_var_type(const char *varname)
LLVMValueRef llvm_function_reference(LLVMJitContext *context, LLVMBuilderRef builder, LLVMModuleRef mod, FunctionCallInfo fcinfo)
char * llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
LLVMTypeRef llvm_pg_var_func_type(const char *varname)
LLVMTypeRef StructTupleTableSlot
LLVMTypeRef TypeStorageBool
LLVMJitContext * llvm_create_context(int jitFlags)
LLVMModuleRef llvm_mutable_module(LLVMJitContext *context)
LLVMTypeRef StructAggState
LLVMValueRef AttributeTemplate
LLVMTypeRef StructExprContext
LLVMTypeRef StructNullableDatum
LLVMValueRef ExecEvalSubroutineTemplate
LLVMValueRef ExecEvalBoolSubroutineTemplate
void * llvm_get_function(LLVMJitContext *context, const char *funcname)
LLVMTypeRef StructAggStatePerTransData
void llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
void llvm_enter_fatal_on_oom(void)
void llvm_leave_fatal_on_oom(void)
static Datum ExecRunCompiledExpr(ExprState *state, ExprContext *econtext, bool *isNull)
#define build_EvalXFunc(b, mod, funcname, v_state, op,...)
bool llvm_compile_expr(ExprState *state)
struct CompiledExprState CompiledExprState
static LLVMValueRef build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod, const char *funcname, LLVMValueRef v_state, ExprEvalStep *op, int natts, LLVMValueRef *v_args)
static LLVMValueRef create_LifetimeEnd(LLVMModuleRef mod)
static LLVMValueRef BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b, LLVMModuleRef mod, FunctionCallInfo fcinfo, LLVMValueRef *v_fcinfo_isnull)
LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r)
void pfree(void *pointer)
void * palloc0(Size size)
#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE
#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL
#define FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE
#define castNode(_type_, nodeptr)
#define FIELDNO_NULLABLE_DATUM_ISNULL
FunctionCallInfo transfn_fcinfo
struct JitContext * es_jit
MemoryContext ecxt_per_tuple_memory
struct ExprEvalStep::@52::@62 jump
struct ExprEvalStep::@52::@68 iocoerce
struct ExprEvalStep::@52::@56 assign_var
struct ExprEvalStep::@52::@95 agg_plain_pergroup_nullcheck
struct ExprEvalStep::@52::@97 agg_trans
struct ExprEvalStep::@52::@75 rowcompare_final
struct ExprEvalStep::@52::@96 agg_presorted_distinctcheck
struct ExprEvalStep::@52::@53 fetch
struct ExprEvalStep::@52::@79 sbsref_subscript
struct ExprEvalStep::@52::@59 func
struct ExprEvalStep::@52::@67 make_readonly
struct ExprEvalStep::@52::@80 sbsref
struct ExprEvalStep::@52::@61 qualexpr
struct ExprEvalStep::@52::@91 window_func
struct ExprEvalStep::@52::@82 hashdatum_initvalue
struct ExprEvalStep::@52::@54 var
struct ExprEvalStep::@52::@65 cparam
union ExprEvalStep::@52 d
struct ExprEvalStep::@52::@57 assign_tmp
struct ExprEvalStep::@52::@58 constval
struct ExprEvalStep::@52::@99 jsonexpr
struct ExprEvalStep::@52::@94 agg_strict_input_check
struct ExprEvalStep::@52::@74 rowcompare_step
struct ExprEvalStep::@52::@89 aggref
struct ExprEvalStep::@52::@93 agg_deserialize
struct ExprEvalStep::@52::@66 casetest
struct ExprEvalStep::@52::@83 hashdatum
struct ExprEvalStep::@52::@60 boolexpr
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
static void * fn(void *arg)
#define FIELDNO_TUPLETABLESLOT_ISNULL
#define FIELDNO_TUPLETABLESLOT_VALUES
#define FIELDNO_TUPLETABLESLOT_NVALID