@ -154,7 +154,7 @@ llvm_compile_expr(ExprState *state)
/* create function */
eval_fn = LLVMAddFunction ( mod , funcname ,
llvm_pg_var_func_type ( " TypeExprStateEvalFunc " ) ) ;
llvm_pg_var_func_type ( " ExecInterpExprStillValid " ) ) ;
LLVMSetLinkage ( eval_fn , LLVMExternalLinkage ) ;
LLVMSetVisibility ( eval_fn , LLVMDefaultVisibility ) ;
llvm_copy_attributes ( AttributeTemplate , eval_fn ) ;
@ -168,61 +168,95 @@ llvm_compile_expr(ExprState *state)
LLVMPositionBuilderAtEnd ( b , entry ) ;
v_tmpvaluep = LLVMBuildStructGEP ( b , v_state ,
FIELDNO_EXPRSTATE_RESVALUE ,
" v.state.resvalue " ) ;
v_tmpisnullp = LLVMBuildStructGEP ( b , v_state ,
FIELDNO_EXPRSTATE_RESNULL ,
" v.state.resnull " ) ;
v_parent = l_load_struct_gep ( b , v_state ,
v_tmpvaluep = l_struct_gep ( b ,
StructExprState ,
v_state ,
FIELDNO_EXPRSTATE_RESVALUE ,
" v.state.resvalue " ) ;
v_tmpisnullp = l_struct_gep ( b ,
StructExprState ,
v_state ,
FIELDNO_EXPRSTATE_RESNULL ,
" v.state.resnull " ) ;
v_parent = l_load_struct_gep ( b ,
StructExprState ,
v_state ,
FIELDNO_EXPRSTATE_PARENT ,
" v.state.parent " ) ;
/* build global slots */
v_scanslot = l_load_struct_gep ( b , v_econtext ,
v_scanslot = l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_SCANTUPLE ,
" v_scanslot " ) ;
v_innerslot = l_load_struct_gep ( b , v_econtext ,
v_innerslot = l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_INNERTUPLE ,
" v_innerslot " ) ;
v_outerslot = l_load_struct_gep ( b , v_econtext ,
v_outerslot = l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_OUTERTUPLE ,
" v_outerslot " ) ;
v_resultslot = l_load_struct_gep ( b , v_state ,
v_resultslot = l_load_struct_gep ( b ,
StructExprState ,
v_state ,
FIELDNO_EXPRSTATE_RESULTSLOT ,
" v_resultslot " ) ;
/* build global values/isnull pointers */
v_scanvalues = l_load_struct_gep ( b , v_scanslot ,
v_scanvalues = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_scanslot ,
FIELDNO_TUPLETABLESLOT_VALUES ,
" v_scanvalues " ) ;
v_scannulls = l_load_struct_gep ( b , v_scanslot ,
v_scannulls = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_scanslot ,
FIELDNO_TUPLETABLESLOT_ISNULL ,
" v_scannulls " ) ;
v_innervalues = l_load_struct_gep ( b , v_innerslot ,
v_innervalues = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_innerslot ,
FIELDNO_TUPLETABLESLOT_VALUES ,
" v_innervalues " ) ;
v_innernulls = l_load_struct_gep ( b , v_innerslot ,
v_innernulls = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_innerslot ,
FIELDNO_TUPLETABLESLOT_ISNULL ,
" v_innernulls " ) ;
v_outervalues = l_load_struct_gep ( b , v_outerslot ,
v_outervalues = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_outerslot ,
FIELDNO_TUPLETABLESLOT_VALUES ,
" v_outervalues " ) ;
v_outernulls = l_load_struct_gep ( b , v_outerslot ,
v_outernulls = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_outerslot ,
FIELDNO_TUPLETABLESLOT_ISNULL ,
" v_outernulls " ) ;
v_resultvalues = l_load_struct_gep ( b , v_resultslot ,
v_resultvalues = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_resultslot ,
FIELDNO_TUPLETABLESLOT_VALUES ,
" v_resultvalues " ) ;
v_resultnulls = l_load_struct_gep ( b , v_resultslot ,
v_resultnulls = l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_resultslot ,
FIELDNO_TUPLETABLESLOT_ISNULL ,
" v_resultnulls " ) ;
/* aggvalues/aggnulls */
v_aggvalues = l_load_struct_gep ( b , v_econtext ,
v_aggvalues = l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_AGGVALUES ,
" v.econtext.aggvalues " ) ;
v_aggnulls = l_load_struct_gep ( b , v_econtext ,
v_aggnulls = l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_AGGNULLS ,
" v.econtext.aggnulls " ) ;
@ -256,8 +290,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_tmpisnull ;
LLVMValueRef v_tmpvalue ;
v_tmpvalue = LLVMBuildL oad( b , v_tmpvaluep , " " ) ;
v_tmpisnull = LLVMBuildL oad( b , v_tmpisnullp , " " ) ;
v_tmpvalue = l_l oad( b , TypeSizeT , v_tmpvaluep , " " ) ;
v_tmpisnull = l_l oad( b , TypeStorageBool , v_tmpisnullp , " " ) ;
LLVMBuildStore ( b , v_tmpisnull , v_isnullp ) ;
@ -300,7 +334,9 @@ llvm_compile_expr(ExprState *state)
* whether deforming is required .
*/
v_nvalid =
l_load_struct_gep ( b , v_slot ,
l_load_struct_gep ( b ,
StructTupleTableSlot ,
v_slot ,
FIELDNO_TUPLETABLESLOT_NVALID ,
" " ) ;
LLVMBuildCondBr ( b ,
@ -335,8 +371,10 @@ llvm_compile_expr(ExprState *state)
params [ 0 ] = v_slot ;
LLVMBuildCall ( b , l_jit_deform ,
params , lengthof ( params ) , " " ) ;
l_call ( b ,
LLVMGetFunctionType ( l_jit_deform ) ,
l_jit_deform ,
params , lengthof ( params ) , " " ) ;
}
else
{
@ -345,9 +383,10 @@ llvm_compile_expr(ExprState *state)
params [ 0 ] = v_slot ;
params [ 1 ] = l_int32_const ( lc , op - > d . fetch . last_var ) ;
LLVMBuildCall ( b ,
llvm_pg_func ( mod , " slot_getsomeattrs_int " ) ,
params , lengthof ( params ) , " " ) ;
l_call ( b ,
llvm_pg_var_func_type ( " slot_getsomeattrs_int " ) ,
llvm_pg_func ( mod , " slot_getsomeattrs_int " ) ,
params , lengthof ( params ) , " " ) ;
}
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
@ -381,8 +420,8 @@ llvm_compile_expr(ExprState *state)
}
v_attnum = l_int32_const ( lc , op - > d . var . attnum ) ;
value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
value = l_load_gep1 ( b , TypeSizeT , v_values , v_attnum , " " ) ;
isnull = l_load_gep1 ( b , TypeStorageBool , v_nulls , v_attnum , " " ) ;
LLVMBuildStore ( b , value , v_resvaluep ) ;
LLVMBuildStore ( b , isnull , v_resnullp ) ;
@ -447,15 +486,19 @@ llvm_compile_expr(ExprState *state)
/* load data */
v_attnum = l_int32_const ( lc , op - > d . assign_var . attnum ) ;
v_value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
v_isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
v_value = l_load_gep1 ( b , TypeSizeT , v_values , v_attnum , " " ) ;
v_isnull = l_load_gep1 ( b , TypeStorageBool , v_nulls , v_attnum , " " ) ;
/* compute addresses of targets */
v_resultnum = l_int32_const ( lc , op - > d . assign_var . resultnum ) ;
v_rvaluep = LLVMBuildGEP ( b , v_resultvalues ,
& v_resultnum , 1 , " " ) ;
v_risnullp = LLVMBuildGEP ( b , v_resultnulls ,
& v_resultnum , 1 , " " ) ;
v_rvaluep = l_gep ( b ,
TypeSizeT ,
v_resultvalues ,
& v_resultnum , 1 , " " ) ;
v_risnullp = l_gep ( b ,
TypeStorageBool ,
v_resultnulls ,
& v_resultnum , 1 , " " ) ;
/* and store */
LLVMBuildStore ( b , v_value , v_rvaluep ) ;
@ -476,15 +519,15 @@ llvm_compile_expr(ExprState *state)
size_t resultnum = op - > d . assign_tmp . resultnum ;
/* load data */
v_value = LLVMBuildL oad( b , v_tmpvaluep , " " ) ;
v_isnull = LLVMBuildL oad( b , v_tmpisnullp , " " ) ;
v_value = l_l oad( b , TypeSizeT , v_tmpvaluep , " " ) ;
v_isnull = l_l oad( b , TypeStorageBool , v_tmpisnullp , " " ) ;
/* compute addresses of targets */
v_resultnum = l_int32_const ( lc , resultnum ) ;
v_rvaluep =
LLVMBuildGEP ( b , v_resultvalues , & v_resultnum , 1 , " " ) ;
l_gep ( b , TypeSizeT , v_resultvalues , & v_resultnum , 1 , " " ) ;
v_risnullp =
LLVMBuildGEP ( b , v_resultnulls , & v_resultnum , 1 , " " ) ;
l_gep ( b , TypeStorageBool , v_resultnulls , & v_resultnum , 1 , " " ) ;
/* store nullness */
LLVMBuildStore ( b , v_isnull , v_risnullp ) ;
@ -508,9 +551,10 @@ llvm_compile_expr(ExprState *state)
LLVMPositionBuilderAtEnd ( b , b_notnull ) ;
v_params [ 0 ] = v_value ;
v_value =
LLVMBuildCall ( b ,
llvm_pg_func ( mod , " MakeExpandedObjectReadOnlyInternal " ) ,
v_params , lengthof ( v_params ) , " " ) ;
l_call ( b ,
llvm_pg_var_func_type ( " MakeExpandedObjectReadOnlyInternal " ) ,
llvm_pg_func ( mod , " MakeExpandedObjectReadOnlyInternal " ) ,
v_params , lengthof ( v_params ) , " " ) ;
/*
* Falling out of the if ( ) with builder in b_notnull ,
@ -673,8 +717,8 @@ llvm_compile_expr(ExprState *state)
if ( opcode = = EEOP_BOOL_AND_STEP_FIRST )
LLVMBuildStore ( b , l_sbool_const ( 0 ) , v_boolanynullp ) ;
v_boolnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_boolvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_boolnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
v_boolvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
/* set resnull to boolnull */
LLVMBuildStore ( b , v_boolnull , v_resnullp ) ;
@ -715,7 +759,7 @@ llvm_compile_expr(ExprState *state)
/* Build block that continues if bool is TRUE. */
LLVMPositionBuilderAtEnd ( b , b_boolcont ) ;
v_boolanynull = LLVMBuildL oad( b , v_boolanynullp , " " ) ;
v_boolanynull = l_l oad( b , TypeStorageBool , v_boolanynullp , " " ) ;
/* set value to NULL if any previous values were NULL */
LLVMBuildCondBr ( b ,
@ -769,8 +813,8 @@ llvm_compile_expr(ExprState *state)
if ( opcode = = EEOP_BOOL_OR_STEP_FIRST )
LLVMBuildStore ( b , l_sbool_const ( 0 ) , v_boolanynullp ) ;
v_boolnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_boolvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_boolnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
v_boolvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
/* set resnull to boolnull */
LLVMBuildStore ( b , v_boolnull , v_resnullp ) ;
@ -810,7 +854,7 @@ llvm_compile_expr(ExprState *state)
/* build block that continues if bool is FALSE */
LLVMPositionBuilderAtEnd ( b , b_boolcont ) ;
v_boolanynull = LLVMBuildL oad( b , v_boolanynullp , " " ) ;
v_boolanynull = l_l oad( b , TypeStorageBool , v_boolanynullp , " " ) ;
/* set value to NULL if any previous values were NULL */
LLVMBuildCondBr ( b ,
@ -834,8 +878,8 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef v_boolnull ;
LLVMValueRef v_negbool ;
v_boolnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_boolvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_boolnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
v_boolvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
v_negbool = LLVMBuildZExt ( b ,
LLVMBuildICmp ( b , LLVMIntEQ ,
@ -862,8 +906,8 @@ llvm_compile_expr(ExprState *state)
b_qualfail = l_bb_before_v ( opblocks [ opno + 1 ] ,
" op.%d.qualfail " , opno ) ;
v_resvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_resvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
v_nullorfalse =
LLVMBuildOr ( b ,
@ -901,7 +945,7 @@ llvm_compile_expr(ExprState *state)
/* Transfer control if current result is null */
v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
LLVMBuildCondBr ( b ,
LLVMBuildICmp ( b , LLVMIntEQ , v_resnull ,
@ -917,7 +961,7 @@ llvm_compile_expr(ExprState *state)
/* Transfer control if current result is non-null */
v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
LLVMBuildCondBr ( b ,
LLVMBuildICmp ( b , LLVMIntEQ , v_resnull ,
@ -936,8 +980,8 @@ llvm_compile_expr(ExprState *state)
/* Transfer control if current result is null or false */
v_resvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_resvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
v_nullorfalse =
LLVMBuildOr ( b ,
@ -956,7 +1000,7 @@ llvm_compile_expr(ExprState *state)
case EEOP_NULLTEST_ISNULL :
{
LLVMValueRef v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
LLVMValueRef v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
LLVMValueRef v_resvalue ;
v_resvalue =
@ -975,7 +1019,7 @@ llvm_compile_expr(ExprState *state)
case EEOP_NULLTEST_ISNOTNULL :
{
LLVMValueRef v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
LLVMValueRef v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
LLVMValueRef v_resvalue ;
v_resvalue =
@ -1011,7 +1055,7 @@ llvm_compile_expr(ExprState *state)
{
LLVMBasicBlockRef b_isnull ,
b_notnull ;
LLVMValueRef v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
LLVMValueRef v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
b_isnull = l_bb_before_v ( opblocks [ opno + 1 ] ,
" op.%d.isnull " , opno ) ;
@ -1055,7 +1099,7 @@ llvm_compile_expr(ExprState *state)
else
{
LLVMValueRef v_value =
LLVMBuildL oad( b , v_resvaluep , " " ) ;
l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
v_value = LLVMBuildZExt ( b ,
LLVMBuildICmp ( b , LLVMIntEQ ,
@ -1083,20 +1127,19 @@ llvm_compile_expr(ExprState *state)
case EEOP_PARAM_CALLBACK :
{
LLVMTypeRef v_functype ;
LLVMValueRef v_func ;
LLVMValueRef v_params [ 3 ] ;
v_functype = llvm_pg_var_func_type ( " TypeExecEvalSubroutine " ) ;
v_func = l_ptr_const ( op - > d . cparam . paramfunc ,
LLVMPointerType ( v_functype , 0 ) ) ;
llvm_pg_var_type ( " TypeExecEvalSubroutine " ) ) ;
v_params [ 0 ] = v_state ;
v_params [ 1 ] = l_ptr_const ( op , l_ptr ( StructExprEvalStep ) ) ;
v_params [ 2 ] = v_econtext ;
LLVMBuildCall ( b ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
l_call ( b ,
LLVMGetFunctionType ( ExecEvalSubroutineTemplate ) ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
break ;
@ -1105,21 +1148,20 @@ llvm_compile_expr(ExprState *state)
case EEOP_SBSREF_SUBSCRIPTS :
{
int jumpdone = op - > d . sbsref_subscript . jumpdone ;
LLVMTypeRef v_functype ;
LLVMValueRef v_func ;
LLVMValueRef v_params [ 3 ] ;
LLVMValueRef v_ret ;
v_functype = llvm_pg_var_func_type ( " TypeExecEvalBoolSubroutine " ) ;
v_func = l_ptr_const ( op - > d . sbsref_subscript . subscriptfunc ,
LLVMPointerType ( v_functype , 0 ) ) ;
llvm_pg_var_type ( " TypeExecEvalBoolSubroutine " ) ) ;
v_params [ 0 ] = v_state ;
v_params [ 1 ] = l_ptr_const ( op , l_ptr ( StructExprEvalStep ) ) ;
v_params [ 2 ] = v_econtext ;
v_ret = LLVMBuildCall ( b ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
v_ret = l_call ( b ,
LLVMGetFunctionType ( ExecEvalBoolSubroutineTemplate ) ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
v_ret = LLVMBuildZExt ( b , v_ret , TypeStorageBool , " " ) ;
LLVMBuildCondBr ( b ,
@ -1134,20 +1176,19 @@ llvm_compile_expr(ExprState *state)
case EEOP_SBSREF_ASSIGN :
case EEOP_SBSREF_FETCH :
{
LLVMTypeRef v_functype ;
LLVMValueRef v_func ;
LLVMValueRef v_params [ 3 ] ;
v_functype = llvm_pg_var_func_type ( " TypeExecEvalSubroutine " ) ;
v_func = l_ptr_const ( op - > d . sbsref . subscriptfunc ,
LLVMPointerType ( v_functype , 0 ) ) ;
llvm_pg_var_type ( " TypeExecEvalSubroutine " ) ) ;
v_params [ 0 ] = v_state ;
v_params [ 1 ] = l_ptr_const ( op , l_ptr ( StructExprEvalStep ) ) ;
v_params [ 2 ] = v_econtext ;
LLVMBuildCall ( b ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
l_call ( b ,
LLVMGetFunctionType ( ExecEvalSubroutineTemplate ) ,
v_func ,
v_params , lengthof ( v_params ) , " " ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
break ;
@ -1182,8 +1223,8 @@ llvm_compile_expr(ExprState *state)
/* if casetest != NULL */
LLVMPositionBuilderAtEnd ( b , b_avail ) ;
v_casevalue = LLVMBuildL oad( b , v_casevaluep , " " ) ;
v_casenull = LLVMBuildL oad( b , v_casenullp , " " ) ;
v_casevalue = l_l oad( b , TypeSizeT , v_casevaluep , " " ) ;
v_casenull = l_l oad( b , TypeStorageBool , v_casenullp , " " ) ;
LLVMBuildStore ( b , v_casevalue , v_resvaluep ) ;
LLVMBuildStore ( b , v_casenull , v_resnullp ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
@ -1191,10 +1232,14 @@ llvm_compile_expr(ExprState *state)
/* if casetest == NULL */
LLVMPositionBuilderAtEnd ( b , b_notavail ) ;
v_casevalue =
l_load_struct_gep ( b , v_econtext ,
l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_CASEDATUM , " " ) ;
v_casenull =
l_load_struct_gep ( b , v_econtext ,
l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_CASENULL , " " ) ;
LLVMBuildStore ( b , v_casevalue , v_resvaluep ) ;
LLVMBuildStore ( b , v_casenull , v_resnullp ) ;
@ -1219,7 +1264,7 @@ llvm_compile_expr(ExprState *state)
v_nullp = l_ptr_const ( op - > d . make_readonly . isnull ,
l_ptr ( TypeStorageBool ) ) ;
v_null = LLVMBuildL oad( b , v_nullp , " " ) ;
v_null = l_l oad( b , TypeStorageBool , v_nullp , " " ) ;
/* store null isnull value in result */
LLVMBuildStore ( b , v_null , v_resnullp ) ;
@ -1236,13 +1281,14 @@ llvm_compile_expr(ExprState *state)
v_valuep = l_ptr_const ( op - > d . make_readonly . value ,
l_ptr ( TypeSizeT ) ) ;
v_value = LLVMBuildL oad( b , v_valuep , " " ) ;
v_value = l_l oad( b , TypeSizeT , v_valuep , " " ) ;
v_params [ 0 ] = v_value ;
v_ret =
LLVMBuildCall ( b ,
llvm_pg_func ( mod , " MakeExpandedObjectReadOnlyInternal " ) ,
v_params , lengthof ( v_params ) , " " ) ;
l_call ( b ,
llvm_pg_var_func_type ( " MakeExpandedObjectReadOnlyInternal " ) ,
llvm_pg_func ( mod , " MakeExpandedObjectReadOnlyInternal " ) ,
v_params , lengthof ( v_params ) , " " ) ;
LLVMBuildStore ( b , v_ret , v_resvaluep ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
@ -1288,12 +1334,14 @@ llvm_compile_expr(ExprState *state)
v_fcinfo_in = l_ptr_const ( fcinfo_in , l_ptr ( StructFunctionCallInfoData ) ) ;
v_fcinfo_in_isnullp =
LLVMBuildStructGEP ( b , v_fcinfo_in ,
FIELDNO_FUNCTIONCALLINFODATA_ISNULL ,
" v_fcinfo_in_isnull " ) ;
l_struct_gep ( b ,
StructFunctionCallInfoData ,
v_fcinfo_in ,
FIELDNO_FUNCTIONCALLINFODATA_ISNULL ,
" v_fcinfo_in_isnull " ) ;
/* output functions are not called on nulls */
v_resnull = LLVMBuildL oad( b , v_resnullp , " " ) ;
v_resnull = l_l oad( b , TypeStorageBool , v_resnullp , " " ) ;
LLVMBuildCondBr ( b ,
LLVMBuildICmp ( b , LLVMIntEQ , v_resnull ,
l_sbool_const ( 1 ) , " " ) ,
@ -1305,7 +1353,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuildBr ( b , b_input ) ;
LLVMPositionBuilderAtEnd ( b , b_calloutput ) ;
v_resvalue = LLVMBuildL oad( b , v_resvaluep , " " ) ;
v_resvalue = l_l oad( b , TypeSizeT , v_resvaluep , " " ) ;
/* set arg[0] */
LLVMBuildStore ( b ,
@ -1315,8 +1363,10 @@ llvm_compile_expr(ExprState *state)
l_sbool_const ( 0 ) ,
l_funcnullp ( b , v_fcinfo_out , 0 ) ) ;
/* and call output function (can never return NULL) */
v_output = LLVMBuildCall ( b , v_fn_out , & v_fcinfo_out ,
1 , " funccall_coerce_out " ) ;
v_output = l_call ( b ,
LLVMGetFunctionType ( v_fn_out ) ,
v_fn_out , & v_fcinfo_out ,
1 , " funccall_coerce_out " ) ;
LLVMBuildBr ( b , b_input ) ;
/* build block handling input function call */
@ -1370,8 +1420,10 @@ llvm_compile_expr(ExprState *state)
/* reset fcinfo_in->isnull */
LLVMBuildStore ( b , l_sbool_const ( 0 ) , v_fcinfo_in_isnullp ) ;
/* and call function */
v_retval = LLVMBuildCall ( b , v_fn_in , & v_fcinfo_in , 1 ,
" funccall_iocoerce_in " ) ;
v_retval = l_call ( b ,
LLVMGetFunctionType ( v_fn_in ) ,
v_fn_in , & v_fcinfo_in , 1 ,
" funccall_iocoerce_in " ) ;
LLVMBuildStore ( b , v_retval , v_resvaluep ) ;
@ -1704,7 +1756,7 @@ llvm_compile_expr(ExprState *state)
*/
v_cmpresult =
LLVMBuildTrunc ( b ,
LLVMBuildL oad( b , v_resvaluep , " " ) ,
l_l oad( b , TypeSizeT , v_resvaluep , " " ) ,
LLVMInt32TypeInContext ( lc ) , " " ) ;
switch ( rctype )
@ -1797,8 +1849,8 @@ llvm_compile_expr(ExprState *state)
/* if casetest != NULL */
LLVMPositionBuilderAtEnd ( b , b_avail ) ;
v_casevalue = LLVMBuildL oad( b , v_casevaluep , " " ) ;
v_casenull = LLVMBuildL oad( b , v_casenullp , " " ) ;
v_casevalue = l_l oad( b , TypeSizeT , v_casevaluep , " " ) ;
v_casenull = l_l oad( b , TypeStorageBool , v_casenullp , " " ) ;
LLVMBuildStore ( b , v_casevalue , v_resvaluep ) ;
LLVMBuildStore ( b , v_casenull , v_resnullp ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
@ -1806,11 +1858,15 @@ llvm_compile_expr(ExprState *state)
/* if casetest == NULL */
LLVMPositionBuilderAtEnd ( b , b_notavail ) ;
v_casevalue =
l_load_struct_gep ( b , v_econtext ,
l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_DOMAINDATUM ,
" " ) ;
v_casenull =
l_load_struct_gep ( b , v_econtext ,
l_load_struct_gep ( b ,
StructExprContext ,
v_econtext ,
FIELDNO_EXPRCONTEXT_DOMAINNULL ,
" " ) ;
LLVMBuildStore ( b , v_casevalue , v_resvaluep ) ;
@ -1877,8 +1933,8 @@ llvm_compile_expr(ExprState *state)
v_aggno = l_int32_const ( lc , op - > d . aggref . aggno ) ;
/* load agg value / null */
value = l_load_gep1 ( b , v_aggvalues , v_aggno , " aggvalue " ) ;
isnull = l_load_gep1 ( b , v_aggnulls , v_aggno , " aggnull " ) ;
value = l_load_gep1 ( b , TypeSizeT , v_aggvalues , v_aggno , " aggvalue " ) ;
isnull = l_load_gep1 ( b , TypeStorageBool , v_aggnulls , v_aggno , " aggnull " ) ;
/* and store result */
LLVMBuildStore ( b , value , v_resvaluep ) ;
@ -1909,12 +1965,12 @@ llvm_compile_expr(ExprState *state)
*/
v_wfuncnop = l_ptr_const ( & wfunc - > wfuncno ,
l_ptr ( LLVMInt32TypeInContext ( lc ) ) ) ;
v_wfuncno = LLVMBuildL oad( b , v_wfuncnop , " v_wfuncno " ) ;
v_wfuncno = l_l oad( b , LLVMInt32TypeInContext ( lc ) , v_wfuncnop , " v_wfuncno " ) ;
/* load window func value / null */
value = l_load_gep1 ( b , v_aggvalues , v_wfuncno ,
value = l_load_gep1 ( b , TypeSizeT , v_aggvalues , v_wfuncno ,
" windowvalue " ) ;
isnull = l_load_gep1 ( b , v_aggnulls , v_wfuncno ,
isnull = l_load_gep1 ( b , TypeStorageBool , v_aggnulls , v_wfuncno ,
" windownull " ) ;
LLVMBuildStore ( b , value , v_resvaluep ) ;
@ -2028,14 +2084,14 @@ llvm_compile_expr(ExprState *state)
b_argnotnull = b_checknulls [ argno + 1 ] ;
if ( opcode = = EEOP_AGG_STRICT_INPUT_CHECK_NULLS )
v_argisnull = l_load_gep1 ( b , v_nullsp , v_argno , " " ) ;
v_argisnull = l_load_gep1 ( b , TypeStorageBool , v_nullsp , v_argno , " " ) ;
else
{
LLVMValueRef v_argn ;
v_argn = LLVMBuildGEP ( b , v_argsp , & v_argno , 1 , " " ) ;
v_argn = l_gep ( b , StructNullableDatum , v_argsp , & v_argno , 1 , " " ) ;
v_argisnull =
l_load_struct_gep ( b , v_argn ,
l_load_struct_gep ( b , StructNullableDatum , v_argn ,
FIELDNO_NULLABLE_DATUM_ISNULL ,
" " ) ;
}
@ -2069,13 +2125,16 @@ llvm_compile_expr(ExprState *state)
v_aggstatep = LLVMBuildBitCast ( b , v_parent ,
l_ptr ( StructAggState ) , " " ) ;
v_allpergroupsp = l_load_struct_gep ( b , v_aggstatep ,
v_allpergroupsp = l_load_struct_gep ( b ,
StructAggState ,
v_aggstatep ,
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
" aggstate.all_pergroups " ) ;
v_setoff = l_int32_const ( lc , op - > d . agg_plain_pergroup_nullcheck . setoff ) ;
v_pergroup_allaggs = l_load_gep1 ( b , v_allpergroupsp , v_setoff , " " ) ;
v_pergroup_allaggs = l_load_gep1 ( b , l_ptr ( StructAggStatePerGroupData ) ,
v_allpergroupsp , v_setoff , " " ) ;
LLVMBuildCondBr ( b ,
LLVMBuildICmp ( b , LLVMIntEQ ,
@ -2138,15 +2197,19 @@ llvm_compile_expr(ExprState *state)
* [ op - > d . agg_trans . setoff ] [ op - > d . agg_trans . transno ] ;
*/
v_allpergroupsp =
l_load_struct_gep ( b , v_aggstatep ,
l_load_struct_gep ( b ,
StructAggState ,
v_aggstatep ,
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
" aggstate.all_pergroups " ) ;
v_setoff = l_int32_const ( lc , op - > d . agg_trans . setoff ) ;
v_transno = l_int32_const ( lc , op - > d . agg_trans . transno ) ;
v_pergroupp =
LLVMBuildGEP ( b ,
l_load_gep1 ( b , v_allpergroupsp , v_setoff , " " ) ,
& v_transno , 1 , " " ) ;
l_gep ( b ,
StructAggStatePerGroupData ,
l_load_gep1 ( b , l_ptr ( StructAggStatePerGroupData ) ,
v_allpergroupsp , v_setoff , " " ) ,
& v_transno , 1 , " " ) ;
if ( opcode = = EEOP_AGG_PLAIN_TRANS_INIT_STRICT_BYVAL | |
@ -2157,7 +2220,9 @@ llvm_compile_expr(ExprState *state)
LLVMBasicBlockRef b_no_init ;
v_notransvalue =
l_load_struct_gep ( b , v_pergroupp ,
l_load_struct_gep ( b ,
StructAggStatePerGroupData ,
v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE ,
" notransvalue " ) ;
@ -2186,10 +2251,11 @@ llvm_compile_expr(ExprState *state)
params [ 2 ] = v_pergroupp ;
params [ 3 ] = v_aggcontext ;
LLVMBuildCall ( b ,
llvm_pg_func ( mod , " ExecAggInitGroup " ) ,
params , lengthof ( params ) ,
" " ) ;
l_call ( b ,
llvm_pg_var_func_type ( " ExecAggInitGroup " ) ,
llvm_pg_func ( mod , " ExecAggInitGroup " ) ,
params , lengthof ( params ) ,
" " ) ;
LLVMBuildBr ( b , opblocks [ opno + 1 ] ) ;
}
@ -2208,7 +2274,9 @@ llvm_compile_expr(ExprState *state)
b_strictpass = l_bb_before_v ( opblocks [ opno + 1 ] ,
" op.%d.strictpass " , opno ) ;
v_transnull =
l_load_struct_gep ( b , v_pergroupp ,
l_load_struct_gep ( b ,
StructAggStatePerGroupData ,
v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL ,
" transnull " ) ;
@ -2228,20 +2296,23 @@ llvm_compile_expr(ExprState *state)
l_ptr ( StructExprContext ) ) ;
v_current_setp =
LLVMBuildStructGEP ( b ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURRENT_SET ,
" aggstate.current_set " ) ;
l_struct_gep ( b ,
StructAggState ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURRENT_SET ,
" aggstate.current_set " ) ;
v_curaggcontext =
LLVMBuildStructGEP ( b ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURAGGCONTEXT ,
" aggstate.curaggcontext " ) ;
l_struct_gep ( b ,
StructAggState ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURAGGCONTEXT ,
" aggstate.curaggcontext " ) ;
v_current_pertransp =
LLVMBuildStructGEP ( b ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURPERTRANS ,
" aggstate.curpertrans " ) ;
l_struct_gep ( b ,
StructAggState ,
v_aggstatep ,
FIELDNO_AGGSTATE_CURPERTRANS ,
" aggstate.curpertrans " ) ;
/* set aggstate globals */
LLVMBuildStore ( b , v_aggcontext , v_curaggcontext ) ;
@ -2257,19 +2328,25 @@ llvm_compile_expr(ExprState *state)
/* store transvalue in fcinfo->args[0] */
v_transvaluep =
LLVMBuildStructGEP ( b , v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE ,
" transvalue " ) ;
l_struct_gep ( b ,
StructAggStatePerGroupData ,
v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE ,
" transvalue " ) ;
v_transnullp =
LLVMBuildStructGEP ( b , v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL ,
" transnullp " ) ;
l_struct_gep ( b ,
StructAggStatePerGroupData ,
v_pergroupp ,
FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL ,
" transnullp " ) ;
LLVMBuildStore ( b ,
LLVMBuildLoad ( b , v_transvaluep ,
" transvalue " ) ,
l_load ( b ,
TypeSizeT ,
v_transvaluep ,
" transvalue " ) ,
l_funcvaluep ( b , v_fcinfo , 0 ) ) ;
LLVMBuildStore ( b ,
LLVMBuildL oad( b , v_transnullp , " transnull " ) ,
l_l oad( b , TypeStorageBool , v_transnullp , " transnull " ) ,
l_funcnullp ( b , v_fcinfo , 0 ) ) ;
/* and invoke transition function */
@ -2302,8 +2379,8 @@ llvm_compile_expr(ExprState *state)
b_nocall = l_bb_before_v ( opblocks [ opno + 1 ] ,
" op.%d.transnocall " , opno ) ;
v_transvalue = LLVMBuildL oad( b , v_transvaluep , " " ) ;
v_transnull = LLVMBuildL oad( b , v_transnullp , " " ) ;
v_transvalue = l_l oad( b , TypeSizeT , v_transvaluep , " " ) ;
v_transnull = l_l oad( b , TypeStorageBool , v_transnullp , " " ) ;
/*
* DatumGetPointer ( newVal ) ! =
@ -2329,9 +2406,11 @@ llvm_compile_expr(ExprState *state)
v_fn = llvm_pg_func ( mod , " ExecAggCopyTransValue " ) ;
v_newval =
LLVMBuildCall ( b , v_fn ,
params , lengthof ( params ) ,
" " ) ;
l_call ( b ,
LLVMGetFunctionType ( v_fn ) ,
v_fn ,
params , lengthof ( params ) ,
" " ) ;
/* store trans value */
LLVMBuildStore ( b , v_newval , v_transvaluep ) ;
@ -2367,7 +2446,7 @@ llvm_compile_expr(ExprState *state)
v_args [ 0 ] = l_ptr_const ( aggstate , l_ptr ( StructAggState ) ) ;
v_args [ 1 ] = l_ptr_const ( pertrans , l_ptr ( StructAggStatePerTransData ) ) ;
v_ret = LLVMBuildCall ( b , v_fn , v_args , 2 , " " ) ;
v_ret = l_call ( b , LLVMGetFunctionType ( v_fn ) , v_fn , v_args , 2 , " " ) ;
v_ret = LLVMBuildZExt ( b , v_ret , TypeStorageBool , " " ) ;
LLVMBuildCondBr ( b ,
@ -2391,7 +2470,7 @@ llvm_compile_expr(ExprState *state)
v_args [ 0 ] = l_ptr_const ( aggstate , l_ptr ( StructAggState ) ) ;
v_args [ 1 ] = l_ptr_const ( pertrans , l_ptr ( StructAggStatePerTransData ) ) ;
v_ret = LLVMBuildCall ( b , v_fn , v_args , 2 , " " ) ;
v_ret = l_call ( b , LLVMGetFunctionType ( v_fn ) , v_fn , v_args , 2 , " " ) ;
v_ret = LLVMBuildZExt ( b , v_ret , TypeStorageBool , " " ) ;
LLVMBuildCondBr ( b ,
@ -2492,15 +2571,17 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
v_fn = llvm_function_reference ( context , b , mod , fcinfo ) ;
v_fcinfo = l_ptr_const ( fcinfo , l_ptr ( StructFunctionCallInfoData ) ) ;
v_fcinfo_isnullp = LLVMBuildStructGEP ( b , v_fcinfo ,
FIELDNO_FUNCTIONCALLINFODATA_ISNULL ,
" v_fcinfo_isnull " ) ;
v_fcinfo_isnullp = l_struct_gep ( b ,
StructFunctionCallInfoData ,
v_fcinfo ,
FIELDNO_FUNCTIONCALLINFODATA_ISNULL ,
" v_fcinfo_isnull " ) ;
LLVMBuildStore ( b , l_sbool_const ( 0 ) , v_fcinfo_isnullp ) ;
v_retval = LLVMBuildCall ( b , v_fn , & v_fcinfo , 1 , " funccall " ) ;
v_retval = l_call ( b , LLVMGetFunctionType ( AttributeTemplate ) , v_fn , & v_fcinfo , 1 , " funccall " ) ;
if ( v_fcinfo_isnull )
* v_fcinfo_isnull = LLVMBuildL oad( b , v_fcinfo_isnullp , " " ) ;
* v_fcinfo_isnull = l_l oad( b , TypeStorageBool , v_fcinfo_isnullp , " " ) ;
/*
* Add lifetime - end annotation , signaling that writes to memory don ' t have
@ -2512,11 +2593,11 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
params [ 0 ] = l_int64_const ( lc , sizeof ( NullableDatum ) * fcinfo - > nargs ) ;
params [ 1 ] = l_ptr_const ( fcinfo - > args , l_ptr ( LLVMInt8TypeInContext ( lc ) ) ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
l_call ( b , LLVMGetFunctionType ( v_lifetime ) , v_lifetime , params , lengthof ( params ) , " " ) ;
params [ 0 ] = l_int64_const ( lc , sizeof ( fcinfo - > isnull ) ) ;
params [ 1 ] = l_ptr_const ( & fcinfo - > isnull , l_ptr ( LLVMInt8TypeInContext ( lc ) ) ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
l_call ( b , LLVMGetFunctionType ( v_lifetime ) , v_lifetime , params , lengthof ( params ) , " " ) ;
}
return v_retval ;
@ -2548,7 +2629,7 @@ build_EvalXFuncInt(LLVMBuilderRef b, LLVMModuleRef mod, const char *funcname,
for ( int i = 0 ; i < nargs ; i + + )
params [ argno + + ] = v_args [ i ] ;
v_ret = LLVMBuildCall ( b , v_fn , params , argno , " " ) ;
v_ret = l_call ( b , LLVMGetFunctionType ( v_fn ) , v_fn , params , argno , " " ) ;
pfree ( params ) ;