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;
1948 v_prevhash = l_load(
b,
TypeSizeT, v_resvaluep,
1955 v_tmp1 = LLVMBuildShl(
b, v_prevhash, l_sizet_const(1),
1957 v_tmp1 = LLVMBuildAnd(
b, v_tmp1,
1958 l_sizet_const(0xffffffff),
"");
1959 v_tmp2 = LLVMBuildLShr(
b, v_prevhash,
1960 l_sizet_const(31),
"");
1961 v_prevhash = LLVMBuildOr(
b, v_tmp1, v_tmp2,
1969 b_ifnotnull = l_bb_before_v(opblocks[opno + 1],
1974 if (fcinfo->
nargs != 1)
1975 elog(
ERROR,
"incorrect number of function arguments");
1977 v_fcinfo = l_ptr_const(fcinfo,
1980 b_checkargnull = l_bb_before_v(b_ifnotnull,
1981 "b.%d.isnull.0", opno);
1983 LLVMBuildBr(
b, b_checkargnull);
1992 b_ifnullblock = l_bb_before_v(b_ifnotnull,
1996 LLVMPositionBuilderAtEnd(
b, b_ifnullblock);
2002 LLVMBuildStore(
b, l_sbool_const(1), v_resnullp);
2003 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
2004 LLVMBuildBr(
b, opblocks[op->
d.
hashdatum.jumpdone]);
2008 b_ifnullblock = l_bb_before_v(b_ifnotnull,
2012 LLVMPositionBuilderAtEnd(
b, b_ifnullblock);
2015 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
2019 Assert(v_prevhash != NULL);
2025 LLVMBuildStore(
b, v_prevhash, v_resvaluep);
2035 LLVMBuildStore(
b, l_sizet_const(0), v_resvaluep);
2038 LLVMBuildBr(
b, opblocks[opno + 1]);
2041 LLVMPositionBuilderAtEnd(
b, b_checkargnull);
2044 v_argisnull = l_funcnull(
b, v_fcinfo, 0);
2054 LLVMPositionBuilderAtEnd(
b, b_ifnotnull);
2063 LLVMValueRef v_tmp1;
2064 LLVMValueRef v_tmp2;
2070 v_prevhash = l_load(
b,
TypeSizeT, v_resvaluep,
2077 v_tmp1 = LLVMBuildShl(
b, v_prevhash, l_sizet_const(1),
2079 v_tmp1 = LLVMBuildAnd(
b, v_tmp1,
2080 l_sizet_const(0xffffffff),
"");
2081 v_tmp2 = LLVMBuildLShr(
b, v_prevhash,
2082 l_sizet_const(31),
"");
2083 v_prevhash = LLVMBuildOr(
b, v_tmp1, v_tmp2,
2097 v_retval = LLVMBuildXor(
b, v_prevhash, v_retval,
2100 LLVMBuildStore(
b, v_retval, v_resvaluep);
2101 LLVMBuildStore(
b, l_sbool_const(0), v_resnullp);
2103 LLVMBuildBr(
b, opblocks[opno + 1]);
2109 v_state, op, v_econtext);
2110 LLVMBuildBr(
b, opblocks[opno + 1]);
2116 LLVMBuildBr(
b, opblocks[opno + 1]);
2121 v_state, op, v_econtext);
2122 LLVMBuildBr(
b, opblocks[opno + 1]);
2128 LLVMBuildBr(
b, opblocks[opno + 1]);
2133 v_state, op, v_econtext);
2134 LLVMBuildBr(
b, opblocks[opno + 1]);
2140 LLVMBuildBr(
b, opblocks[opno + 1]);
2153 v_state, op, v_econtext);
2165 LLVMValueRef v_jump_empty;
2166 LLVMValueRef v_jump_error;
2167 LLVMValueRef v_jump_coercion;
2168 LLVMValueRef v_switch;
2169 LLVMBasicBlockRef b_done,
2175 l_bb_before_v(opblocks[opno + 1],
2176 "op.%d.jsonexpr_empty", opno);
2178 l_bb_before_v(opblocks[opno + 1],
2179 "op.%d.jsonexpr_error", opno);
2181 l_bb_before_v(opblocks[opno + 1],
2182 "op.%d.jsonexpr_coercion", opno);
2184 l_bb_before_v(opblocks[opno + 1],
2185 "op.%d.jsonexpr_done", opno);
2187 v_switch = LLVMBuildSwitch(
b,
2194 v_jump_empty = l_int32_const(lc, jsestate->
jump_empty);
2195 LLVMAddCase(v_switch, v_jump_empty, b_empty);
2198 LLVMPositionBuilderAtEnd(
b, b_empty);
2202 LLVMBuildUnreachable(
b);
2207 v_jump_error = l_int32_const(lc, jsestate->
jump_error);
2208 LLVMAddCase(v_switch, v_jump_error, b_error);
2211 LLVMPositionBuilderAtEnd(
b, b_error);
2215 LLVMBuildUnreachable(
b);
2221 LLVMAddCase(v_switch, v_jump_coercion, b_coercion);
2224 LLVMPositionBuilderAtEnd(
b, b_coercion);
2228 LLVMBuildUnreachable(
b);
2230 LLVMPositionBuilderAtEnd(
b, b_done);
2233 LLVMBuildBr(
b, opblocks[jsestate->
jump_end]);
2239 v_state, op, v_econtext);
2241 LLVMBuildBr(
b, opblocks[opno + 1]);
2248 LLVMBuildBr(
b, opblocks[opno + 1]);
2253 LLVMValueRef v_aggno;
2257 v_aggno = l_int32_const(lc, op->
d.
aggref.aggno);
2264 LLVMBuildStore(
b,
value, v_resvaluep);
2265 LLVMBuildStore(
b, isnull, v_resnullp);
2267 LLVMBuildBr(
b, opblocks[opno + 1]);
2274 LLVMBuildBr(
b, opblocks[opno + 1]);
2280 LLVMValueRef v_wfuncnop;
2281 LLVMValueRef v_wfuncno;
2290 v_wfuncnop = l_ptr_const(&wfunc->
wfuncno,
2291 l_ptr(LLVMInt32TypeInContext(lc)));
2292 v_wfuncno = l_load(
b, LLVMInt32TypeInContext(lc), v_wfuncnop,
"v_wfuncno");
2300 LLVMBuildStore(
b,
value, v_resvaluep);
2301 LLVMBuildStore(
b, isnull, v_resnullp);
2303 LLVMBuildBr(
b, opblocks[opno + 1]);
2309 v_state, op, v_econtext);
2310 LLVMBuildBr(
b, opblocks[opno + 1]);
2315 v_state, op, v_econtext);
2316 LLVMBuildBr(
b, opblocks[opno + 1]);
2325 LLVMValueRef v_retval;
2326 LLVMValueRef v_fcinfo_isnull;
2327 LLVMValueRef v_tmpcontext;
2328 LLVMValueRef v_oldcontext;
2332 LLVMValueRef v_fcinfo;
2333 LLVMValueRef v_argnull0;
2334 LLVMBasicBlockRef b_deserialize;
2336 b_deserialize = l_bb_before_v(opblocks[opno + 1],
2337 "op.%d.deserialize", opno);
2339 v_fcinfo = l_ptr_const(fcinfo,
2341 v_argnull0 = l_funcnull(
b, v_fcinfo, 0);
2351 LLVMPositionBuilderAtEnd(
b, b_deserialize);
2360 v_oldcontext = l_mcxt_switch(mod,
b, v_tmpcontext);
2363 l_mcxt_switch(mod,
b, v_oldcontext);
2365 LLVMBuildStore(
b, v_retval, v_resvaluep);
2366 LLVMBuildStore(
b, v_fcinfo_isnull, v_resnullp);
2368 LLVMBuildBr(
b, opblocks[opno + 1]);
2380 LLVMValueRef v_argsp;
2381 LLVMValueRef v_nullsp;
2382 LLVMBasicBlockRef *b_checknulls;
2391 b_checknulls =
palloc(
sizeof(LLVMBasicBlockRef *) * nargs);
2392 for (
int argno = 0; argno < nargs; argno++)
2394 b_checknulls[argno] =
2395 l_bb_before_v(opblocks[opno + 1],
2396 "op.%d.check-null.%d",
2400 LLVMBuildBr(
b, b_checknulls[0]);
2403 for (
int argno = 0; argno < nargs; argno++)
2405 LLVMValueRef v_argno = l_int32_const(lc, argno);
2406 LLVMValueRef v_argisnull;
2407 LLVMBasicBlockRef b_argnotnull;
2409 LLVMPositionBuilderAtEnd(
b, b_checknulls[argno]);
2411 if (argno + 1 == nargs)
2412 b_argnotnull = opblocks[opno + 1];
2414 b_argnotnull = b_checknulls[argno + 1];
2420 LLVMValueRef v_argn;
2433 l_sbool_const(1),
""),
2444 LLVMValueRef v_aggstatep;
2445 LLVMValueRef v_allpergroupsp;
2446 LLVMValueRef v_pergroup_allaggs;
2447 LLVMValueRef v_setoff;
2455 v_aggstatep = LLVMBuildBitCast(
b, v_parent,
2458 v_allpergroupsp = l_load_struct_gep(
b,
2462 "aggstate.all_pergroups");
2467 v_allpergroupsp, v_setoff,
"");
2470 LLVMBuildICmp(
b, LLVMIntEQ,
2471 LLVMBuildPtrToInt(
b, v_pergroup_allaggs,
TypeSizeT,
""),
2472 l_sizet_const(0),
""),
2474 opblocks[opno + 1]);
2489 LLVMValueRef v_aggstatep;
2490 LLVMValueRef v_fcinfo;
2491 LLVMValueRef v_fcinfo_isnull;
2493 LLVMValueRef v_transvaluep;
2494 LLVMValueRef v_transnullp;
2496 LLVMValueRef v_setoff;
2497 LLVMValueRef v_transno;
2499 LLVMValueRef v_aggcontext;
2501 LLVMValueRef v_allpergroupsp;
2502 LLVMValueRef v_current_setp;
2503 LLVMValueRef v_current_pertransp;
2504 LLVMValueRef v_curaggcontext;
2506 LLVMValueRef v_pertransp;
2508 LLVMValueRef v_pergroupp;
2510 LLVMValueRef v_retval;
2512 LLVMValueRef v_tmpcontext;
2513 LLVMValueRef v_oldcontext;
2522 v_pertransp = l_ptr_const(pertrans,
2530 l_load_struct_gep(
b,
2534 "aggstate.all_pergroups");
2535 v_setoff = l_int32_const(lc, op->
d.
agg_trans.setoff);
2536 v_transno = l_int32_const(lc, op->
d.
agg_trans.transno);
2541 v_allpergroupsp, v_setoff,
""),
2548 LLVMValueRef v_notransvalue;
2549 LLVMBasicBlockRef b_init;
2550 LLVMBasicBlockRef b_no_init;
2553 l_load_struct_gep(
b,
2559 b_init = l_bb_before_v(opblocks[opno + 1],
2560 "op.%d.inittrans", opno);
2561 b_no_init = l_bb_before_v(opblocks[opno + 1],
2562 "op.%d.no_inittrans", opno);
2565 LLVMBuildICmp(
b, LLVMIntEQ, v_notransvalue,
2566 l_sbool_const(1),
""),
2572 LLVMValueRef params[4];
2574 LLVMPositionBuilderAtEnd(
b, b_init);
2576 v_aggcontext = l_ptr_const(op->
d.
agg_trans.aggcontext,
2579 params[0] = v_aggstatep;
2580 params[1] = v_pertransp;
2581 params[2] = v_pergroupp;
2582 params[3] = v_aggcontext;
2590 LLVMBuildBr(
b, opblocks[opno + 1]);
2593 LLVMPositionBuilderAtEnd(
b, b_no_init);
2601 LLVMValueRef v_transnull;
2602 LLVMBasicBlockRef b_strictpass;
2604 b_strictpass = l_bb_before_v(opblocks[opno + 1],
2605 "op.%d.strictpass", opno);
2607 l_load_struct_gep(
b,
2614 LLVMBuildICmp(
b, LLVMIntEQ, v_transnull,
2615 l_sbool_const(1),
""),
2619 LLVMPositionBuilderAtEnd(
b, b_strictpass);
2623 v_fcinfo = l_ptr_const(fcinfo,
2625 v_aggcontext = l_ptr_const(op->
d.
agg_trans.aggcontext,
2633 "aggstate.current_set");
2639 "aggstate.curaggcontext");
2640 v_current_pertransp =
2645 "aggstate.curpertrans");
2648 LLVMBuildStore(
b, v_aggcontext, v_curaggcontext);
2649 LLVMBuildStore(
b, l_int32_const(lc, op->
d.
agg_trans.setno),
2651 LLVMBuildStore(
b, v_pertransp, v_current_pertransp);
2657 v_oldcontext = l_mcxt_switch(mod,
b, v_tmpcontext);
2677 l_funcvaluep(
b, v_fcinfo, 0));
2680 l_funcnullp(
b, v_fcinfo, 0));
2699 LLVMBasicBlockRef b_call;
2700 LLVMBasicBlockRef b_nocall;
2702 LLVMValueRef v_transvalue;
2703 LLVMValueRef v_transnull;
2704 LLVMValueRef v_newval;
2705 LLVMValueRef params[6];
2707 b_call = l_bb_before_v(opblocks[opno + 1],
2708 "op.%d.transcall", opno);
2709 b_nocall = l_bb_before_v(opblocks[opno + 1],
2710 "op.%d.transnocall", opno);
2712 v_transvalue = l_load(
b,
TypeSizeT, v_transvaluep,
"");
2720 LLVMBuildICmp(
b, LLVMIntEQ,
2726 LLVMPositionBuilderAtEnd(
b, b_call);
2728 params[0] = v_aggstatep;
2729 params[1] = v_pertransp;
2730 params[2] = v_retval;
2731 params[3] = LLVMBuildTrunc(
b, v_fcinfo_isnull,
2733 params[4] = v_transvalue;
2734 params[5] = LLVMBuildTrunc(
b, v_transnull,
2746 LLVMBuildStore(
b, v_newval, v_transvaluep);
2747 LLVMBuildStore(
b, v_fcinfo_isnull, v_transnullp);
2749 l_mcxt_switch(mod,
b, v_oldcontext);
2750 LLVMBuildBr(
b, opblocks[opno + 1]);
2753 LLVMPositionBuilderAtEnd(
b, b_nocall);
2757 LLVMBuildStore(
b, v_retval, v_transvaluep);
2758 LLVMBuildStore(
b, v_fcinfo_isnull, v_transnullp);
2760 l_mcxt_switch(mod,
b, v_oldcontext);
2762 LLVMBuildBr(
b, opblocks[opno + 1]);
2772 LLVMValueRef v_fn =
llvm_pg_func(mod,
"ExecEvalPreOrderedDistinctSingle");
2773 LLVMValueRef v_args[2];
2783 LLVMBuildICmp(
b, LLVMIntEQ, v_ret,
2784 l_sbool_const(1),
""),
2786 opblocks[jumpdistinct]);
2796 LLVMValueRef v_fn =
llvm_pg_func(mod,
"ExecEvalPreOrderedDistinctMulti");
2797 LLVMValueRef v_args[2];
2807 LLVMBuildICmp(
b, LLVMIntEQ, v_ret,
2808 l_sbool_const(1),
""),
2810 opblocks[jumpdistinct]);
2816 v_state, op, v_econtext);
2817 LLVMBuildBr(
b, opblocks[opno + 1]);
2822 v_state, op, v_econtext);
2823 LLVMBuildBr(
b, opblocks[opno + 1]);
2832 LLVMDisposeBuilder(
b);
2848 state->evalfunc_private = cstate;
2855 endtime, starttime);
2883 state->evalfunc = func;
2885 return func(
state, econtext, isNull);
2891 LLVMValueRef *v_fcinfo_isnull)
2895 LLVMValueRef v_fcinfo_isnullp;
2896 LLVMValueRef v_retval;
2897 LLVMValueRef v_fcinfo;
2899 lc = LLVMGetModuleContext(mod);
2904 v_fcinfo_isnullp = l_struct_gep(
b,
2909 LLVMBuildStore(
b, l_sbool_const(0), v_fcinfo_isnullp);
2913 if (v_fcinfo_isnull)
2922 LLVMValueRef params[2];
2925 params[1] = l_ptr_const(fcinfo->
args, l_ptr(LLVMInt8TypeInContext(lc)));
2928 params[0] = l_int64_const(lc,
sizeof(fcinfo->
isnull));
2929 params[1] = l_ptr_const(&fcinfo->
isnull, l_ptr(LLVMInt8TypeInContext(lc)));
2942 int nargs, LLVMValueRef *v_args)
2945 LLVMValueRef *params;
2950 if (LLVMCountParams(v_fn) != (nargs + 2))
2951 elog(
ERROR,
"parameter mismatch: %s expects %d passed %d",
2952 funcname, LLVMCountParams(v_fn), nargs + 2);
2954 params =
palloc(
sizeof(LLVMValueRef) * (2 + nargs));
2956 params[argno++] = v_state;
2959 for (
int i = 0;
i < nargs;
i++)
2960 params[argno++] = v_args[
i];
2974 LLVMTypeRef param_types[2];
2978 const char *nm =
"llvm.lifetime.end.p0";
2980 fn = LLVMGetNamedFunction(mod, nm);
2984 lc = LLVMGetModuleContext(mod);
2985 param_types[0] = LLVMInt64TypeInContext(lc);
2986 param_types[1] = l_ptr(LLVMInt8TypeInContext(lc));
2988 sig = LLVMFunctionType(LLVMVoidTypeInContext(lc), param_types,
2990 fn = LLVMAddFunction(mod, nm,
sig);
2992 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
union ExprEvalStep::@54 d
struct ExprEvalStep::@54::@85 hashdatum
struct ExprEvalStep::@54::@99 agg_trans
struct ExprEvalStep::@54::@77 rowcompare_final
struct ExprEvalStep::@54::@60 constval
struct ExprEvalStep::@54::@91 aggref
struct ExprEvalStep::@54::@96 agg_strict_input_check
struct ExprEvalStep::@54::@70 iocoerce
struct ExprEvalStep::@54::@97 agg_plain_pergroup_nullcheck
struct ExprEvalStep::@54::@56 var
struct ExprEvalStep::@54::@82 sbsref
struct ExprEvalStep::@54::@69 make_readonly
struct ExprEvalStep::@54::@67 cparam
struct ExprEvalStep::@54::@62 boolexpr
struct ExprEvalStep::@54::@64 jump
struct ExprEvalStep::@54::@59 assign_tmp
struct ExprEvalStep::@54::@76 rowcompare_step
struct ExprEvalStep::@54::@95 agg_deserialize
struct ExprEvalStep::@54::@58 assign_var
struct ExprEvalStep::@54::@61 func
struct ExprEvalStep::@54::@101 jsonexpr
struct ExprEvalStep::@54::@84 hashdatum_initvalue
struct ExprEvalStep::@54::@63 qualexpr
struct ExprEvalStep::@54::@98 agg_presorted_distinctcheck
struct ExprEvalStep::@54::@68 casetest
struct ExprEvalStep::@54::@55 fetch
struct ExprEvalStep::@54::@81 sbsref_subscript
struct ExprEvalStep::@54::@93 window_func
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
static void * fn(void *arg)
#define FIELDNO_TUPLETABLESLOT_ISNULL
#define FIELDNO_TUPLETABLESLOT_VALUES
#define FIELDNO_TUPLETABLESLOT_NVALID