Commit 1ec7679f authored by Andres Freund's avatar Andres Freund

expression eval, jit: Minor code cleanups.

This mostly consists of using C99 style for loops, moving variables
into narrower scopes, and a smattering of other minor improvements.
Done separately to make it easier to review patches with actual
functional changes.

Author: Andres Freund
Discussion: https://postgr.es/m/20191023163849.sosqbfs5yenocez3@alap3.anarazel.de
parent 5ac4e9a1
......@@ -2779,12 +2779,7 @@ static void
ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
ExprState *state, Datum *resv, bool *resnull)
{
ExprEvalStep scratch2 = {0};
DomainConstraintRef *constraint_ref;
Datum *domainval = NULL;
bool *domainnull = NULL;
Datum *save_innermost_domainval;
bool *save_innermost_domainnull;
ListCell *l;
scratch->d.domaincheck.resulttype = ctest->resulttype;
......@@ -2831,6 +2826,10 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
foreach(l, constraint_ref->constraints)
{
DomainConstraintState *con = (DomainConstraintState *) lfirst(l);
Datum *domainval = NULL;
bool *domainnull = NULL;
Datum *save_innermost_domainval;
bool *save_innermost_domainnull;
scratch->d.domaincheck.constraintname = con->name;
......@@ -2862,6 +2861,8 @@ ExecInitCoerceToDomain(ExprEvalStep *scratch, CoerceToDomain *ctest,
*/
if (get_typlen(ctest->resulttype) == -1)
{
ExprEvalStep scratch2 = {0};
/* Yes, so make output workspace for MAKE_READONLY */
domainval = (Datum *) palloc(sizeof(Datum));
domainnull = (bool *) palloc(sizeof(bool));
......@@ -2932,8 +2933,6 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
ExprState *state = makeNode(ExprState);
PlanState *parent = &aggstate->ss.ps;
ExprEvalStep scratch = {0};
int transno = 0;
int setoff = 0;
bool isCombine = DO_AGGSPLIT_COMBINE(aggstate->aggsplit);
LastAttnumInfo deform = {0, 0, 0};
......@@ -2947,7 +2946,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
* First figure out which slots, and how many columns from each, we're
* going to need.
*/
for (transno = 0; transno < aggstate->numtrans; transno++)
for (int transno = 0; transno < aggstate->numtrans; transno++)
{
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
......@@ -2967,17 +2966,15 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
/*
* Emit instructions for each transition value / grouping set combination.
*/
for (transno = 0; transno < aggstate->numtrans; transno++)
for (int transno = 0; transno < aggstate->numtrans; transno++)
{
AggStatePerTrans pertrans = &aggstate->pertrans[transno];
int argno;
int setno;
FunctionCallInfo trans_fcinfo = pertrans->transfn_fcinfo;
ListCell *arg;
ListCell *bail;
List *adjust_bailout = NIL;
NullableDatum *strictargs = NULL;
bool *strictnulls = NULL;
int argno;
ListCell *bail;
/*
* If filter present, emit. Do so before evaluating the input, to
......@@ -3071,6 +3068,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
}
else if (pertrans->numSortCols == 0)
{
ListCell *arg;
/*
* Normal transition function without ORDER BY / DISTINCT.
*/
......@@ -3113,6 +3112,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
*/
Datum *values = pertrans->sortslot->tts_values;
bool *nulls = pertrans->sortslot->tts_isnull;
ListCell *arg;
strictnulls = nulls;
......@@ -3152,12 +3152,12 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
* grouping set). Do so for both sort and hash based computations, as
* applicable.
*/
setoff = 0;
if (doSort)
{
int processGroupingSets = Max(phase->numsets, 1);
int setoff = 0;
for (setno = 0; setno < processGroupingSets; setno++)
for (int setno = 0; setno < processGroupingSets; setno++)
{
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
pertrans, transno, setno, setoff, false);
......@@ -3168,6 +3168,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
if (doHash)
{
int numHashes = aggstate->num_hashes;
int setoff;
/* in MIXED mode, there'll be preceding transition values */
if (aggstate->aggstrategy != AGG_HASHED)
......@@ -3175,7 +3176,7 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
else
setoff = 0;
for (setno = 0; setno < numHashes; setno++)
for (int setno = 0; setno < numHashes; setno++)
{
ExecBuildAggTransCall(state, aggstate, &scratch, trans_fcinfo,
pertrans, transno, setno, setoff, true);
......@@ -3204,6 +3205,8 @@ ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase,
Assert(as->d.agg_deserialize.jumpnull == -1);
as->d.agg_deserialize.jumpnull = state->steps_len;
}
else
Assert(false);
}
}
......@@ -3338,7 +3341,6 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
{
ExprState *state = makeNode(ExprState);
ExprEvalStep scratch = {0};
int natt;
int maxatt = -1;
List *adjust_jumps = NIL;
ListCell *lc;
......@@ -3358,7 +3360,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
scratch.resnull = &state->resnull;
/* compute max needed attribute */
for (natt = 0; natt < numCols; natt++)
for (int natt = 0; natt < numCols; natt++)
{
int attno = keyColIdx[natt];
......@@ -3388,7 +3390,7 @@ ExecBuildGroupingEqual(TupleDesc ldesc, TupleDesc rdesc,
* Start comparing at the last field (least significant sort key). That's
* the most likely to be different if we are dealing with sorted input.
*/
for (natt = numCols; --natt >= 0;)
for (int natt = numCols; --natt >= 0;)
{
int attno = keyColIdx[natt];
Form_pg_attribute latt = TupleDescAttr(ldesc, attno - 1);
......
......@@ -307,18 +307,14 @@ ExecReadyInterpretedExpr(ExprState *state)
* In the direct-threaded implementation, replace each opcode with the
* address to jump to. (Use ExecEvalStepOp() to get back the opcode.)
*/
for (int off = 0; off < state->steps_len; off++)
{
int off;
ExprEvalStep *op = &state->steps[off];
for (off = 0; off < state->steps_len; off++)
{
ExprEvalStep *op = &state->steps[off];
op->opcode = EEO_OPCODE(op->opcode);
}
state->flags |= EEO_FLAG_DIRECT_THREADED;
op->opcode = EEO_OPCODE(op->opcode);
}
state->flags |= EEO_FLAG_DIRECT_THREADED;
#endif /* EEO_USE_COMPUTED_GOTO */
state->evalfunc_private = (void *) ExecInterpExpr;
......@@ -673,11 +669,11 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
{
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
NullableDatum *args = fcinfo->args;
int argno;
int nargs = op->d.func.nargs;
Datum d;
/* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
if (args[argno].isnull)
{
......@@ -1568,29 +1564,28 @@ ExecInterpExpr(ExprState *state, ExprContext *econtext, bool *isnull)
* Check that a strict aggregate transition / combination function's
* input is not NULL.
*/
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS)
{
int argno;
bool *nulls = op->d.agg_strict_input_check.nulls;
NullableDatum *args = op->d.agg_strict_input_check.args;
int nargs = op->d.agg_strict_input_check.nargs;
for (argno = 0; argno < nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
if (nulls[argno])
if (args[argno].isnull)
EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
}
EEO_NEXT();
}
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_ARGS)
EEO_CASE(EEOP_AGG_STRICT_INPUT_CHECK_NULLS)
{
int argno;
NullableDatum *args = op->d.agg_strict_input_check.args;
bool *nulls = op->d.agg_strict_input_check.nulls;
int nargs = op->d.agg_strict_input_check.nargs;
for (argno = 0; argno < nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
if (args[argno].isnull)
if (nulls[argno])
EEO_JUMP(op->d.agg_strict_input_check.jumpnull);
}
EEO_NEXT();
......@@ -1825,7 +1820,6 @@ ExecInterpExprStillValid(ExprState *state, ExprContext *econtext, bool *isNull)
void
CheckExprStillValid(ExprState *state, ExprContext *econtext)
{
int i = 0;
TupleTableSlot *innerslot;
TupleTableSlot *outerslot;
TupleTableSlot *scanslot;
......@@ -1834,7 +1828,7 @@ CheckExprStillValid(ExprState *state, ExprContext *econtext)
outerslot = econtext->ecxt_outertuple;
scanslot = econtext->ecxt_scantuple;
for (i = 0; i < state->steps_len; i++)
for (int i = 0; i < state->steps_len; i++)
{
ExprEvalStep *op = &state->steps[i];
......@@ -2104,7 +2098,7 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
ExprEvalStep *op = &state->steps[0];
FunctionCallInfo fcinfo;
NullableDatum *args;
int argno;
int nargs;
Datum d;
/*
......@@ -2116,11 +2110,12 @@ ExecJustApplyFuncToCase(ExprState *state, ExprContext *econtext, bool *isnull)
op++;
nargs = op->d.func.nargs;
fcinfo = op->d.func.fcinfo_data;
args = fcinfo->args;
/* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
if (args[argno].isnull)
{
......@@ -2258,13 +2253,11 @@ ExecInitInterpreter(void)
/* Set up externally-visible pointer to dispatch table */
if (dispatch_table == NULL)
{
int i;
dispatch_table = (const void **)
DatumGetPointer(ExecInterpExpr(NULL, NULL, NULL));
/* build reverse lookup table */
for (i = 0; i < EEOP_LAST; i++)
for (int i = 0; i < EEOP_LAST; i++)
{
reverse_dispatch_table[i].opcode = dispatch_table[i];
reverse_dispatch_table[i].op = (ExprEvalOp) i;
......@@ -2344,11 +2337,11 @@ ExecEvalFuncExprStrictFusage(ExprState *state, ExprEvalStep *op,
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
PgStat_FunctionCallUsage fcusage;
NullableDatum *args = fcinfo->args;
int argno;
int nargs = op->d.func.nargs;
Datum d;
/* strict function, so check for NULL args */
for (argno = 0; argno < op->d.func.nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
if (args[argno].isnull)
{
......@@ -2568,7 +2561,6 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op,
int32 tupTypmod;
TupleDesc tupDesc;
HeapTupleData tmptup;
int att;
*op->resnull = false;
......@@ -2611,7 +2603,7 @@ ExecEvalRowNullInt(ExprState *state, ExprEvalStep *op,
tmptup.t_len = HeapTupleHeaderGetDatumLength(tuple);
tmptup.t_data = tuple;
for (att = 1; att <= tupDesc->natts; att++)
for (int att = 1; att <= tupDesc->natts; att++)
{
/* ignore dropped columns */
if (TupleDescAttr(tupDesc, att - 1)->attisdropped)
......@@ -2694,8 +2686,6 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
int32 dataoffset;
char *dat;
int iitem;
int elemoff;
int i;
subdata = (char **) palloc(nelems * sizeof(char *));
subbitmaps = (bits8 **) palloc(nelems * sizeof(bits8 *));
......@@ -2703,7 +2693,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
subnitems = (int *) palloc(nelems * sizeof(int));
/* loop through and get data area from each element */
for (elemoff = 0; elemoff < nelems; elemoff++)
for (int elemoff = 0; elemoff < nelems; elemoff++)
{
Datum arraydatum;
bool eisnull;
......@@ -2805,7 +2795,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
/* setup for multi-D array */
dims[0] = outer_nelems;
lbs[0] = 1;
for (i = 1; i < ndims; i++)
for (int i = 1; i < ndims; i++)
{
dims[i] = elem_dims[i - 1];
lbs[i] = elem_lbs[i - 1];
......@@ -2832,7 +2822,7 @@ ExecEvalArrayExpr(ExprState *state, ExprEvalStep *op)
dat = ARR_DATA_PTR(result);
iitem = 0;
for (i = 0; i < outer_nelems; i++)
for (int i = 0; i < outer_nelems; i++)
{
memcpy(dat, subdata[i], subbytes[i]);
dat += subbytes[i];
......@@ -2920,7 +2910,6 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
bool *nulls = op->d.minmax.nulls;
FunctionCallInfo fcinfo = op->d.minmax.fcinfo_data;
MinMaxOp operator = op->d.minmax.op;
int off;
/* set at initialization */
Assert(fcinfo->args[0].isnull == false);
......@@ -2929,7 +2918,7 @@ ExecEvalMinMax(ExprState *state, ExprEvalStep *op)
/* default to null result */
*op->resnull = true;
for (off = 0; off < op->d.minmax.nelems; off++)
for (int off = 0; off < op->d.minmax.nelems; off++)
{
/* ignore NULL inputs */
if (nulls[off])
......@@ -3461,7 +3450,6 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
int nitems;
Datum result;
bool resultnull;
int i;
int16 typlen;
bool typbyval;
char typalign;
......@@ -3529,7 +3517,7 @@ ExecEvalScalarArrayOp(ExprState *state, ExprEvalStep *op)
bitmap = ARR_NULLBITMAP(arr);
bitmask = 1;
for (i = 0; i < nitems; i++)
for (int i = 0; i < nitems; i++)
{
Datum elt;
Datum thisresult;
......@@ -3641,7 +3629,6 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
{
XmlExpr *xexpr = op->d.xmlexpr.xexpr;
Datum value;
int i;
*op->resnull = true; /* until we get a result */
*op->resvalue = (Datum) 0;
......@@ -3654,7 +3641,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
bool *argnull = op->d.xmlexpr.argnull;
List *values = NIL;
for (i = 0; i < list_length(xexpr->args); i++)
for (int i = 0; i < list_length(xexpr->args); i++)
{
if (!argnull[i])
values = lappend(values, DatumGetPointer(argvalue[i]));
......@@ -3675,6 +3662,7 @@ ExecEvalXmlExpr(ExprState *state, ExprEvalStep *op)
StringInfoData buf;
ListCell *lc;
ListCell *lc2;
int i;
initStringInfo(&buf);
......@@ -3968,7 +3956,6 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
{
TupleDesc var_tupdesc;
TupleDesc slot_tupdesc;
int i;
/*
* We really only care about numbers of attributes and data types.
......@@ -4000,7 +3987,7 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
slot_tupdesc->natts,
var_tupdesc->natts)));
for (i = 0; i < var_tupdesc->natts; i++)
for (int i = 0; i < var_tupdesc->natts; i++)
{
Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
Form_pg_attribute sattr = TupleDescAttr(slot_tupdesc, i);
......@@ -4095,11 +4082,10 @@ ExecEvalWholeRowVar(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
/* Check to see if any dropped attributes are non-null */
TupleDesc tupleDesc = slot->tts_tupleDescriptor;
TupleDesc var_tupdesc = op->d.wholerow.tupdesc;
int i;
Assert(var_tupdesc->natts == tupleDesc->natts);
for (i = 0; i < var_tupdesc->natts; i++)
for (int i = 0; i < var_tupdesc->natts; i++)
{
Form_pg_attribute vattr = TupleDescAttr(var_tupdesc, i);
Form_pg_attribute sattr = TupleDescAttr(tupleDesc, i);
......
......@@ -71,7 +71,6 @@ bool
llvm_compile_expr(ExprState *state)
{
PlanState *parent = state->parent;
int i;
char *funcname;
LLVMJitContext *context = NULL;
......@@ -119,20 +118,19 @@ llvm_compile_expr(ExprState *state)
llvm_enter_fatal_on_oom();
/*
* Right now we don't support compiling expressions without a parent, as
* we need access to the EState.
*/
Assert(parent);
/* get or create JIT context */
if (parent && parent->state->es_jit)
{
if (parent->state->es_jit)
context = (LLVMJitContext *) parent->state->es_jit;
}
else
{
context = llvm_create_context(parent->state->es_jit_flags);
if (parent)
{
parent->state->es_jit = &context->base;
}
parent->state->es_jit = &context->base;
}
INSTR_TIME_SET_CURRENT(starttime);
......@@ -226,22 +224,22 @@ llvm_compile_expr(ExprState *state)
/* allocate blocks for each op upfront, so we can do jumps easily */
opblocks = palloc(sizeof(LLVMBasicBlockRef) * state->steps_len);
for (i = 0; i < state->steps_len; i++)
opblocks[i] = l_bb_append_v(eval_fn, "b.op.%d.start", i);
for (int opno = 0; opno < state->steps_len; opno++)
opblocks[opno] = l_bb_append_v(eval_fn, "b.op.%d.start", opno);
/* jump from entry to first block */
LLVMBuildBr(b, opblocks[0]);
for (i = 0; i < state->steps_len; i++)
for (int opno = 0; opno < state->steps_len; opno++)
{
ExprEvalStep *op;
ExprEvalOp opcode;
LLVMValueRef v_resvaluep;
LLVMValueRef v_resnullp;
LLVMPositionBuilderAtEnd(b, opblocks[i]);
LLVMPositionBuilderAtEnd(b, opblocks[opno]);
op = &state->steps[i];
op = &state->steps[opno];
opcode = ExecEvalStepOp(state, op);
v_resvaluep = l_ptr_const(op->resvalue, l_ptr(TypeSizeT));
......@@ -251,8 +249,8 @@ llvm_compile_expr(ExprState *state)
{
case EEOP_DONE:
{
LLVMValueRef v_tmpisnull,
v_tmpvalue;
LLVMValueRef v_tmpisnull;
LLVMValueRef v_tmpvalue;
v_tmpvalue = LLVMBuildLoad(b, v_tmpvaluep, "");
v_tmpisnull = LLVMBuildLoad(b, v_tmpisnullp, "");
......@@ -276,8 +274,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef l_jit_deform = NULL;
const TupleTableSlotOps *tts_ops = NULL;
b_fetch = l_bb_before_v(opblocks[i + 1],
"op.%d.fetch", i);
b_fetch = l_bb_before_v(opblocks[opno + 1],
"op.%d.fetch", opno);
if (op->d.fetch.known_desc)
desc = op->d.fetch.known_desc;
......@@ -307,7 +305,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildICmp(b, LLVMIntUGE, v_nvalid,
l_int16_const(op->d.fetch.last_var),
""),
opblocks[i + 1], b_fetch);
opblocks[opno + 1], b_fetch);
LLVMPositionBuilderAtEnd(b, b_fetch);
......@@ -346,7 +344,7 @@ llvm_compile_expr(ExprState *state)
params, lengthof(params), "");
}
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -382,7 +380,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, value, v_resvaluep);
LLVMBuildStore(b, isnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -409,26 +407,26 @@ llvm_compile_expr(ExprState *state)
llvm_get_decl(mod, FuncExecEvalSysVar),
v_params, lengthof(v_params), "");
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_WHOLEROW:
build_EvalXFunc(b, mod, "ExecEvalWholeRowVar",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ASSIGN_INNER_VAR:
case EEOP_ASSIGN_OUTER_VAR:
case EEOP_ASSIGN_SCAN_VAR:
{
LLVMValueRef v_value,
v_isnull;
LLVMValueRef v_rvaluep,
v_risnullp;
LLVMValueRef v_attnum,
v_resultnum;
LLVMValueRef v_value;
LLVMValueRef v_isnull;
LLVMValueRef v_rvaluep;
LLVMValueRef v_risnullp;
LLVMValueRef v_attnum;
LLVMValueRef v_resultnum;
LLVMValueRef v_values;
LLVMValueRef v_nulls;
......@@ -464,7 +462,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_value, v_rvaluep);
LLVMBuildStore(b, v_isnull, v_risnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -492,7 +490,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_value, v_rvaluep);
LLVMBuildStore(b, v_isnull, v_risnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -508,8 +506,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_resultnum;
size_t resultnum = op->d.assign_tmp.resultnum;
b_notnull = l_bb_before_v(opblocks[i + 1],
"op.%d.assign_tmp.notnull", i);
b_notnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.assign_tmp.notnull", opno);
/* load data */
v_value = LLVMBuildLoad(b, v_tmpvaluep, "");
......@@ -529,7 +527,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_isnull,
l_sbool_const(0), ""),
b_notnull, opblocks[i + 1]);
b_notnull, opblocks[opno + 1]);
/* if value is not null, convert to RO datum */
LLVMPositionBuilderAtEnd(b, b_notnull);
......@@ -542,7 +540,7 @@ llvm_compile_expr(ExprState *state)
/* store value */
LLVMBuildStore(b, v_ret, v_rvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -557,7 +555,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_constvalue, v_resvaluep);
LLVMBuildStore(b, v_constnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -565,7 +563,6 @@ llvm_compile_expr(ExprState *state)
{
FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
LLVMBasicBlockRef b_nonull;
int argno;
LLVMValueRef v_fcinfo;
LLVMBasicBlockRef *b_checkargnulls;
......@@ -573,8 +570,8 @@ llvm_compile_expr(ExprState *state)
* Block for the actual function call, if args are
* non-NULL.
*/
b_nonull = l_bb_before_v(opblocks[i + 1],
"b.%d.no-null-args", i);
b_nonull = l_bb_before_v(opblocks[opno + 1],
"b.%d.no-null-args", opno);
/* should make sure they're optimized beforehand */
if (op->d.func.nargs == 0)
......@@ -592,15 +589,15 @@ llvm_compile_expr(ExprState *state)
/* create blocks for checking args, one for each */
b_checkargnulls =
palloc(sizeof(LLVMBasicBlockRef *) * op->d.func.nargs);
for (argno = 0; argno < op->d.func.nargs; argno++)
for (int argno = 0; argno < op->d.func.nargs; argno++)
b_checkargnulls[argno] =
l_bb_before_v(b_nonull, "b.%d.isnull.%d", i, argno);
l_bb_before_v(b_nonull, "b.%d.isnull.%d", opno, argno);
/* jump to check of first argument */
LLVMBuildBr(b, b_checkargnulls[0]);
/* check each arg for NULLness */
for (argno = 0; argno < op->d.func.nargs; argno++)
for (int argno = 0; argno < op->d.func.nargs; argno++)
{
LLVMValueRef v_argisnull;
LLVMBasicBlockRef b_argnotnull;
......@@ -620,7 +617,7 @@ llvm_compile_expr(ExprState *state)
v_argisnull,
l_sbool_const(1),
""),
opblocks[i + 1],
opblocks[opno + 1],
b_argnotnull);
}
......@@ -639,21 +636,21 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_retval, v_resvaluep);
LLVMBuildStore(b, v_fcinfo_isnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_FUNCEXPR_FUSAGE:
build_EvalXFunc(b, mod, "ExecEvalFuncExprFusage",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_FUNCEXPR_STRICT_FUSAGE:
build_EvalXFunc(b, mod, "ExecEvalFuncExprStrictFusage",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_BOOL_AND_STEP_FIRST:
......@@ -685,16 +682,16 @@ llvm_compile_expr(ExprState *state)
LLVMBasicBlockRef b_boolcont;
LLVMBasicBlockRef b_boolisanynull;
b_boolisnull = l_bb_before_v(opblocks[i + 1],
"b.%d.boolisnull", i);
b_boolcheckfalse = l_bb_before_v(opblocks[i + 1],
"b.%d.boolcheckfalse", i);
b_boolisfalse = l_bb_before_v(opblocks[i + 1],
"b.%d.boolisfalse", i);
b_boolisanynull = l_bb_before_v(opblocks[i + 1],
"b.%d.boolisanynull", i);
b_boolcont = l_bb_before_v(opblocks[i + 1],
"b.%d.boolcont", i);
b_boolisnull = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolisnull", opno);
b_boolcheckfalse = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolcheckfalse", opno);
b_boolisfalse = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolisfalse", opno);
b_boolisanynull = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolisanynull", opno);
b_boolcont = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolcont", opno);
v_boolanynullp = l_ptr_const(op->d.boolexpr.anynull,
l_ptr(TypeStorageBool));
......@@ -747,7 +744,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_boolanynull,
l_sbool_const(0), ""),
opblocks[i + 1], b_boolisanynull);
opblocks[opno + 1], b_boolisanynull);
LLVMPositionBuilderAtEnd(b, b_boolisanynull);
/* set resnull to true */
......@@ -755,7 +752,7 @@ llvm_compile_expr(ExprState *state)
/* reset resvalue */
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_BOOL_OR_STEP_FIRST:
......@@ -787,16 +784,16 @@ llvm_compile_expr(ExprState *state)
LLVMBasicBlockRef b_boolcont;
LLVMBasicBlockRef b_boolisanynull;
b_boolisnull = l_bb_before_v(opblocks[i + 1],
"b.%d.boolisnull", i);
b_boolchecktrue = l_bb_before_v(opblocks[i + 1],
"b.%d.boolchecktrue", i);
b_boolistrue = l_bb_before_v(opblocks[i + 1],
"b.%d.boolistrue", i);
b_boolisanynull = l_bb_before_v(opblocks[i + 1],
"b.%d.boolisanynull", i);
b_boolcont = l_bb_before_v(opblocks[i + 1],
"b.%d.boolcont", i);
b_boolisnull = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolisnull", opno);
b_boolchecktrue = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolchecktrue", opno);
b_boolistrue = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolistrue", opno);
b_boolisanynull = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolisanynull", opno);
b_boolcont = l_bb_before_v(opblocks[opno + 1],
"b.%d.boolcont", opno);
v_boolanynullp = l_ptr_const(op->d.boolexpr.anynull,
l_ptr(TypeStorageBool));
......@@ -848,7 +845,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_boolanynull,
l_sbool_const(0), ""),
opblocks[i + 1], b_boolisanynull);
opblocks[opno + 1], b_boolisanynull);
LLVMPositionBuilderAtEnd(b, b_boolisanynull);
/* set resnull to true */
......@@ -856,7 +853,7 @@ llvm_compile_expr(ExprState *state)
/* reset resvalue */
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -880,7 +877,7 @@ llvm_compile_expr(ExprState *state)
/* set revalue to !boolvalue */
LLVMBuildStore(b, v_negbool, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -891,8 +888,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_nullorfalse;
LLVMBasicBlockRef b_qualfail;
b_qualfail = l_bb_before_v(opblocks[i + 1],
"op.%d.qualfail", i);
b_qualfail = l_bb_before_v(opblocks[opno + 1],
"op.%d.qualfail", opno);
v_resvalue = LLVMBuildLoad(b, v_resvaluep, "");
v_resnull = LLVMBuildLoad(b, v_resnullp, "");
......@@ -908,7 +905,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
v_nullorfalse,
b_qualfail,
opblocks[i + 1]);
opblocks[opno + 1]);
/* build block handling NULL or false */
LLVMPositionBuilderAtEnd(b, b_qualfail);
......@@ -939,7 +936,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildICmp(b, LLVMIntEQ, v_resnull,
l_sbool_const(1), ""),
opblocks[op->d.jump.jumpdone],
opblocks[i + 1]);
opblocks[opno + 1]);
break;
}
......@@ -955,7 +952,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildICmp(b, LLVMIntEQ, v_resnull,
l_sbool_const(0), ""),
opblocks[op->d.jump.jumpdone],
opblocks[i + 1]);
opblocks[opno + 1]);
break;
}
......@@ -982,7 +979,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
v_nullorfalse,
opblocks[op->d.jump.jumpdone],
opblocks[i + 1]);
opblocks[opno + 1]);
break;
}
......@@ -1001,7 +998,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_resvalue, v_resvaluep);
LLVMBuildStore(b, l_sbool_const(0), v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -1020,20 +1017,20 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_resvalue, v_resvaluep);
LLVMBuildStore(b, l_sbool_const(0), v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_NULLTEST_ROWISNULL:
build_EvalXFunc(b, mod, "ExecEvalRowNull",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_NULLTEST_ROWISNOTNULL:
build_EvalXFunc(b, mod, "ExecEvalRowNotNull",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_BOOLTEST_IS_TRUE:
......@@ -1045,10 +1042,10 @@ llvm_compile_expr(ExprState *state)
b_notnull;
LLVMValueRef v_resnull = LLVMBuildLoad(b, v_resnullp, "");
b_isnull = l_bb_before_v(opblocks[i + 1],
"op.%d.isnull", i);
b_notnull = l_bb_before_v(opblocks[i + 1],
"op.%d.isnotnull", i);
b_isnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.isnull", opno);
b_notnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.isnotnull", opno);
/* check if value is NULL */
LLVMBuildCondBr(b,
......@@ -1072,7 +1069,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, l_sizet_const(1), v_resvaluep);
}
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
LLVMPositionBuilderAtEnd(b, b_notnull);
......@@ -1097,20 +1094,20 @@ llvm_compile_expr(ExprState *state)
TypeSizeT, "");
LLVMBuildStore(b, v_value, v_resvaluep);
}
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_PARAM_EXEC:
build_EvalXFunc(b, mod, "ExecEvalParamExec",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_PARAM_EXTERN:
build_EvalXFunc(b, mod, "ExecEvalParamExtern",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_PARAM_CALLBACK:
......@@ -1138,26 +1135,26 @@ llvm_compile_expr(ExprState *state)
v_func,
v_params, lengthof(v_params), "");
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_SBSREF_OLD:
build_EvalXFunc(b, mod, "ExecEvalSubscriptingRefOld",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_SBSREF_ASSIGN:
build_EvalXFunc(b, mod, "ExecEvalSubscriptingRefAssign",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_SBSREF_FETCH:
build_EvalXFunc(b, mod, "ExecEvalSubscriptingRefFetch",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_CASE_TESTVAL:
......@@ -1170,10 +1167,10 @@ llvm_compile_expr(ExprState *state)
v_casenull;
LLVMValueRef v_casevaluenull;
b_avail = l_bb_before_v(opblocks[i + 1],
"op.%d.avail", i);
b_notavail = l_bb_before_v(opblocks[i + 1],
"op.%d.notavail", i);
b_avail = l_bb_before_v(opblocks[opno + 1],
"op.%d.avail", opno);
b_notavail = l_bb_before_v(opblocks[opno + 1],
"op.%d.notavail", opno);
v_casevaluep = l_ptr_const(op->d.casetest.value,
l_ptr(TypeSizeT));
......@@ -1193,7 +1190,7 @@ llvm_compile_expr(ExprState *state)
v_casenull = LLVMBuildLoad(b, v_casenullp, "");
LLVMBuildStore(b, v_casevalue, v_resvaluep);
LLVMBuildStore(b, v_casenull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* if casetest == NULL */
LLVMPositionBuilderAtEnd(b, b_notavail);
......@@ -1206,7 +1203,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_casevalue, v_resvaluep);
LLVMBuildStore(b, v_casenull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -1220,8 +1217,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_null;
LLVMValueRef v_value;
b_notnull = l_bb_before_v(opblocks[i + 1],
"op.%d.readonly.notnull", i);
b_notnull = l_bb_before_v(opblocks[opno + 1],
"op.%d.readonly.notnull", opno);
v_nullp = l_ptr_const(op->d.make_readonly.isnull,
l_ptr(TypeStorageBool));
......@@ -1235,7 +1232,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_null,
l_sbool_const(1), ""),
opblocks[i + 1], b_notnull);
opblocks[opno + 1], b_notnull);
/* if value is not null, convert to RO datum */
LLVMPositionBuilderAtEnd(b, b_notnull);
......@@ -1252,7 +1249,7 @@ llvm_compile_expr(ExprState *state)
v_params, lengthof(v_params), "");
LLVMBuildStore(b, v_ret, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -1280,14 +1277,14 @@ llvm_compile_expr(ExprState *state)
fcinfo_out = op->d.iocoerce.fcinfo_data_out;
fcinfo_in = op->d.iocoerce.fcinfo_data_in;
b_skipoutput = l_bb_before_v(opblocks[i + 1],
"op.%d.skipoutputnull", i);
b_calloutput = l_bb_before_v(opblocks[i + 1],
"op.%d.calloutput", i);
b_input = l_bb_before_v(opblocks[i + 1],
"op.%d.input", i);
b_inputcall = l_bb_before_v(opblocks[i + 1],
"op.%d.inputcall", i);
b_skipoutput = l_bb_before_v(opblocks[opno + 1],
"op.%d.skipoutputnull", opno);
b_calloutput = l_bb_before_v(opblocks[opno + 1],
"op.%d.calloutput", opno);
b_input = l_bb_before_v(opblocks[opno + 1],
"op.%d.input", opno);
b_inputcall = l_bb_before_v(opblocks[opno + 1],
"op.%d.inputcall", opno);
v_fcinfo_out = l_ptr_const(fcinfo_out, l_ptr(StructFunctionCallInfoData));
v_fcinfo_in = l_ptr_const(fcinfo_in, l_ptr(StructFunctionCallInfoData));
......@@ -1355,7 +1352,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_output,
l_sizet_const(0), ""),
opblocks[i + 1],
opblocks[opno + 1],
b_inputcall);
}
else
......@@ -1382,7 +1379,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_retval, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -1409,10 +1406,10 @@ llvm_compile_expr(ExprState *state)
LLVMBasicBlockRef b_bothargnull;
LLVMBasicBlockRef b_anyargnull;
b_noargnull = l_bb_before_v(opblocks[i + 1], "op.%d.noargnull", i);
b_checkbothargnull = l_bb_before_v(opblocks[i + 1], "op.%d.checkbothargnull", i);
b_bothargnull = l_bb_before_v(opblocks[i + 1], "op.%d.bothargnull", i);
b_anyargnull = l_bb_before_v(opblocks[i + 1], "op.%d.anyargnull", i);
b_noargnull = l_bb_before_v(opblocks[opno + 1], "op.%d.noargnull", opno);
b_checkbothargnull = l_bb_before_v(opblocks[opno + 1], "op.%d.checkbothargnull", opno);
b_bothargnull = l_bb_before_v(opblocks[opno + 1], "op.%d.bothargnull", opno);
b_anyargnull = l_bb_before_v(opblocks[opno + 1], "op.%d.anyargnull", opno);
v_fcinfo = l_ptr_const(fcinfo, l_ptr(StructFunctionCallInfoData));
......@@ -1451,7 +1448,7 @@ llvm_compile_expr(ExprState *state)
else
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* Only one is NULL? Then is distinct... */
LLVMPositionBuilderAtEnd(b, b_anyargnull);
......@@ -1460,7 +1457,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
else
LLVMBuildStore(b, l_sizet_const(1), v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* neither argument is null: compare */
LLVMPositionBuilderAtEnd(b, b_noargnull);
......@@ -1482,7 +1479,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_fcinfo_isnull, v_resnullp);
LLVMBuildStore(b, v_result, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
......@@ -1502,12 +1499,12 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_retval;
LLVMValueRef v_argsequal;
b_hasnull = l_bb_before_v(opblocks[i + 1],
"b.%d.null-args", i);
b_nonull = l_bb_before_v(opblocks[i + 1],
"b.%d.no-null-args", i);
b_argsequal = l_bb_before_v(opblocks[i + 1],
"b.%d.argsequal", i);
b_hasnull = l_bb_before_v(opblocks[opno + 1],
"b.%d.null-args", opno);
b_nonull = l_bb_before_v(opblocks[opno + 1],
"b.%d.no-null-args", opno);
b_argsequal = l_bb_before_v(opblocks[opno + 1],
"b.%d.argsequal", opno);
v_fcinfo = l_ptr_const(fcinfo, l_ptr(StructFunctionCallInfoData));
......@@ -1530,7 +1527,7 @@ llvm_compile_expr(ExprState *state)
v_arg0 = l_funcvalue(b, v_fcinfo, 0);
LLVMBuildStore(b, v_argnull0, v_resnullp);
LLVMBuildStore(b, v_arg0, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* build block to invoke function and check result */
LLVMPositionBuilderAtEnd(b, b_nonull);
......@@ -1560,44 +1557,44 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, l_sizet_const(0), v_resvaluep);
LLVMBuildStore(b, v_retval, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_SQLVALUEFUNCTION:
build_EvalXFunc(b, mod, "ExecEvalSQLValueFunction",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_CURRENTOFEXPR:
build_EvalXFunc(b, mod, "ExecEvalCurrentOfExpr",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_NEXTVALUEEXPR:
build_EvalXFunc(b, mod, "ExecEvalNextValueExpr",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ARRAYEXPR:
build_EvalXFunc(b, mod, "ExecEvalArrayExpr",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ARRAYCOERCE:
build_EvalXFunc(b, mod, "ExecEvalArrayCoerce",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ROW:
build_EvalXFunc(b, mod, "ExecEvalRow",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ROWCOMPARE_STEP:
......@@ -1610,14 +1607,14 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_retval;
b_null = l_bb_before_v(opblocks[i + 1],
"op.%d.row-null", i);
b_compare = l_bb_before_v(opblocks[i + 1],
"op.%d.row-compare", i);
b_null = l_bb_before_v(opblocks[opno + 1],
"op.%d.row-null", opno);
b_compare = l_bb_before_v(opblocks[opno + 1],
"op.%d.row-compare", opno);
b_compare_result =
l_bb_before_v(opblocks[i + 1],
l_bb_before_v(opblocks[opno + 1],
"op.%d.row-compare-result",
i);
opno);
/*
* If function is strict, and either arg is null, we're
......@@ -1682,7 +1679,7 @@ llvm_compile_expr(ExprState *state)
LLVMIntEQ,
v_retval,
l_sizet_const(0), ""),
opblocks[i + 1],
opblocks[opno + 1],
opblocks[op->d.rowcompare_step.jumpdone]);
/*
......@@ -1745,53 +1742,52 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, l_sbool_const(0), v_resnullp);
LLVMBuildStore(b, v_result, v_resvaluep);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_MINMAX:
build_EvalXFunc(b, mod, "ExecEvalMinMax",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_FIELDSELECT:
build_EvalXFunc(b, mod, "ExecEvalFieldSelect",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_FIELDSTORE_DEFORM:
build_EvalXFunc(b, mod, "ExecEvalFieldStoreDeForm",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_FIELDSTORE_FORM:
build_EvalXFunc(b, mod, "ExecEvalFieldStoreForm",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_SBSREF_SUBSCRIPT:
{
LLVMValueRef v_fn;
int jumpdone = op->d.sbsref_subscript.jumpdone;
LLVMValueRef v_params[2];
LLVMValueRef v_ret;
v_fn = llvm_get_decl(mod, FuncExecEvalSubscriptingRef);
v_params[0] = v_state;
v_params[1] = l_ptr_const(op, l_ptr(StructExprEvalStep));
v_ret = LLVMBuildCall(b, v_fn,
v_params, lengthof(v_params), "");
v_ret =
LLVMBuildCall(b,
llvm_get_decl(mod, FuncExecEvalSubscriptingRef),
v_params, lengthof(v_params), "");
v_ret = LLVMBuildZExt(b, v_ret, TypeStorageBool, "");
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_ret,
l_sbool_const(1), ""),
opblocks[i + 1],
opblocks[opno + 1],
opblocks[jumpdone]);
break;
}
......@@ -1806,10 +1802,10 @@ llvm_compile_expr(ExprState *state)
v_casenull;
LLVMValueRef v_casevaluenull;
b_avail = l_bb_before_v(opblocks[i + 1],
"op.%d.avail", i);
b_notavail = l_bb_before_v(opblocks[i + 1],
"op.%d.notavail", i);
b_avail = l_bb_before_v(opblocks[opno + 1],
"op.%d.avail", opno);
b_notavail = l_bb_before_v(opblocks[opno + 1],
"op.%d.notavail", opno);
v_casevaluep = l_ptr_const(op->d.casetest.value,
l_ptr(TypeSizeT));
......@@ -1831,7 +1827,7 @@ llvm_compile_expr(ExprState *state)
v_casenull = LLVMBuildLoad(b, v_casenullp, "");
LLVMBuildStore(b, v_casevalue, v_resvaluep);
LLVMBuildStore(b, v_casenull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* if casetest == NULL */
LLVMPositionBuilderAtEnd(b, b_notavail);
......@@ -1846,38 +1842,38 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_casevalue, v_resvaluep);
LLVMBuildStore(b, v_casenull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_DOMAIN_NOTNULL:
build_EvalXFunc(b, mod, "ExecEvalConstraintNotNull",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_DOMAIN_CHECK:
build_EvalXFunc(b, mod, "ExecEvalConstraintCheck",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_CONVERT_ROWTYPE:
build_EvalXFunc(b, mod, "ExecEvalConvertRowtype",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_SCALARARRAYOP:
build_EvalXFunc(b, mod, "ExecEvalScalarArrayOp",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_XMLEXPR:
build_EvalXFunc(b, mod, "ExecEvalXmlExpr",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_AGGREF:
......@@ -1905,14 +1901,14 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, value, v_resvaluep);
LLVMBuildStore(b, isnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_GROUPING_FUNC:
build_EvalXFunc(b, mod, "ExecEvalGroupingFunc",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_WINDOW_FUNC:
......@@ -1941,20 +1937,20 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, value, v_resvaluep);
LLVMBuildStore(b, isnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_SUBPLAN:
build_EvalXFunc(b, mod, "ExecEvalSubPlan",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_ALTERNATIVE_SUBPLAN:
build_EvalXFunc(b, mod, "ExecEvalAlternativeSubPlan",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_AGG_STRICT_DESERIALIZE:
......@@ -1964,8 +1960,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_argnull0;
LLVMBasicBlockRef b_deserialize;
b_deserialize = l_bb_before_v(opblocks[i + 1],
"op.%d.deserialize", i);
b_deserialize = l_bb_before_v(opblocks[opno + 1],
"op.%d.deserialize", opno);
v_fcinfo = l_ptr_const(fcinfo,
l_ptr(StructFunctionCallInfoData));
......@@ -2007,18 +2003,17 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_retval, v_resvaluep);
LLVMBuildStore(b, v_fcinfo_isnull, v_resnullp);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_AGG_STRICT_INPUT_CHECK_NULLS:
case EEOP_AGG_STRICT_INPUT_CHECK_ARGS:
case EEOP_AGG_STRICT_INPUT_CHECK_NULLS:
{
int nargs = op->d.agg_strict_input_check.nargs;
NullableDatum *args = op->d.agg_strict_input_check.args;
bool *nulls = op->d.agg_strict_input_check.nulls;
int jumpnull;
int argno;
LLVMValueRef v_argsp;
LLVMValueRef v_nullsp;
......@@ -2032,18 +2027,18 @@ llvm_compile_expr(ExprState *state)
/* create blocks for checking args */
b_checknulls = palloc(sizeof(LLVMBasicBlockRef *) * nargs);
for (argno = 0; argno < nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
b_checknulls[argno] =
l_bb_before_v(opblocks[i + 1],
l_bb_before_v(opblocks[opno + 1],
"op.%d.check-null.%d",
i, argno);
opno, argno);
}
LLVMBuildBr(b, b_checknulls[0]);
/* strict function, check for NULL args */
for (argno = 0; argno < nargs; argno++)
for (int argno = 0; argno < nargs; argno++)
{
LLVMValueRef v_argno = l_int32_const(argno);
LLVMValueRef v_argisnull;
......@@ -2052,7 +2047,7 @@ llvm_compile_expr(ExprState *state)
LLVMPositionBuilderAtEnd(b, b_checknulls[argno]);
if (argno + 1 == nargs)
b_argnotnull = opblocks[i + 1];
b_argnotnull = opblocks[opno + 1];
else
b_argnotnull = b_checknulls[argno + 1];
......@@ -2129,14 +2124,14 @@ llvm_compile_expr(ExprState *state)
FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE,
"notransvalue");
b_init = l_bb_before_v(opblocks[i + 1],
"op.%d.inittrans", i);
b_init = l_bb_before_v(opblocks[opno + 1],
"op.%d.inittrans", opno);
LLVMBuildCondBr(b,
LLVMBuildICmp(b, LLVMIntEQ, v_notransvalue,
l_sbool_const(1), ""),
b_init,
opblocks[i + 1]);
opblocks[opno + 1]);
LLVMPositionBuilderAtEnd(b, b_init);
......@@ -2223,7 +2218,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildICmp(b, LLVMIntEQ, v_transnull,
l_sbool_const(1), ""),
opblocks[jumpnull],
opblocks[i + 1]);
opblocks[opno + 1]);
break;
}
......@@ -2360,10 +2355,10 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_newval;
LLVMValueRef params[6];
b_call = l_bb_before_v(opblocks[i + 1],
"op.%d.transcall", i);
b_nocall = l_bb_before_v(opblocks[i + 1],
"op.%d.transnocall", i);
b_call = l_bb_before_v(opblocks[opno + 1],
"op.%d.transcall", opno);
b_nocall = l_bb_before_v(opblocks[opno + 1],
"op.%d.transnocall", opno);
v_transvalue = LLVMBuildLoad(b, v_transvaluep, "");
v_transnull = LLVMBuildLoad(b, v_transnullp, "");
......@@ -2401,7 +2396,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildStore(b, v_fcinfo_isnull, v_transnullp);
l_mcxt_switch(mod, b, v_oldcontext);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
/* returned datum passed datum, no need to reparent */
LLVMPositionBuilderAtEnd(b, b_nocall);
......@@ -2413,20 +2408,20 @@ llvm_compile_expr(ExprState *state)
l_mcxt_switch(mod, b, v_oldcontext);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
}
case EEOP_AGG_ORDERED_TRANS_DATUM:
build_EvalXFunc(b, mod, "ExecEvalAggOrderedTransDatum",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_AGG_ORDERED_TRANS_TUPLE:
build_EvalXFunc(b, mod, "ExecEvalAggOrderedTransTuple",
v_state, v_econtext, op);
LLVMBuildBr(b, opblocks[i + 1]);
LLVMBuildBr(b, opblocks[opno + 1]);
break;
case EEOP_LAST:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment