@ -84,6 +84,7 @@ llvm_compile_expr(ExprState *state)
LLVMBuilderRef b ;
LLVMBuilderRef b ;
LLVMModuleRef mod ;
LLVMModuleRef mod ;
LLVMContextRef lc ;
LLVMValueRef eval_fn ;
LLVMValueRef eval_fn ;
LLVMBasicBlockRef entry ;
LLVMBasicBlockRef entry ;
LLVMBasicBlockRef * opblocks ;
LLVMBasicBlockRef * opblocks ;
@ -145,8 +146,9 @@ llvm_compile_expr(ExprState *state)
INSTR_TIME_SET_CURRENT ( starttime ) ;
INSTR_TIME_SET_CURRENT ( starttime ) ;
mod = llvm_mutable_module ( context ) ;
mod = llvm_mutable_module ( context ) ;
lc = LLVMGetModuleContext ( mod ) ;
b = LLVMCreateBuilder ( ) ;
b = LLVMCreateBuilderInContext ( lc ) ;
funcname = llvm_expand_funcname ( context , " evalexpr " ) ;
funcname = llvm_expand_funcname ( context , " evalexpr " ) ;
@ -157,7 +159,7 @@ llvm_compile_expr(ExprState *state)
LLVMSetVisibility ( eval_fn , LLVMDefaultVisibility ) ;
LLVMSetVisibility ( eval_fn , LLVMDefaultVisibility ) ;
llvm_copy_attributes ( AttributeTemplate , eval_fn ) ;
llvm_copy_attributes ( AttributeTemplate , eval_fn ) ;
entry = LLVMAppendBasicBlock ( eval_fn , " entry " ) ;
entry = LLVMAppendBasicBlockInContext ( lc , eval_fn , " entry " ) ;
/* build state */
/* build state */
v_state = LLVMGetParam ( eval_fn , 0 ) ;
v_state = LLVMGetParam ( eval_fn , 0 ) ;
@ -303,7 +305,7 @@ llvm_compile_expr(ExprState *state)
" " ) ;
" " ) ;
LLVMBuildCondBr ( b ,
LLVMBuildCondBr ( b ,
LLVMBuildICmp ( b , LLVMIntUGE , v_nvalid ,
LLVMBuildICmp ( b , LLVMIntUGE , v_nvalid ,
l_int16_const ( op - > d . fetch . last_var ) ,
l_int16_const ( lc , op - > d . fetch . last_var ) ,
" " ) ,
" " ) ,
opblocks [ opno + 1 ] , b_fetch ) ;
opblocks [ opno + 1 ] , b_fetch ) ;
@ -341,7 +343,7 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef params [ 2 ] ;
LLVMValueRef params [ 2 ] ;
params [ 0 ] = v_slot ;
params [ 0 ] = v_slot ;
params [ 1 ] = l_int32_const ( op - > d . fetch . last_var ) ;
params [ 1 ] = l_int32_const ( lc , op - > d . fetch . last_var ) ;
LLVMBuildCall ( b ,
LLVMBuildCall ( b ,
llvm_pg_func ( mod , " slot_getsomeattrs_int " ) ,
llvm_pg_func ( mod , " slot_getsomeattrs_int " ) ,
@ -378,7 +380,7 @@ llvm_compile_expr(ExprState *state)
v_nulls = v_scannulls ;
v_nulls = v_scannulls ;
}
}
v_attnum = l_int32_const ( op - > d . var . attnum ) ;
v_attnum = l_int32_const ( lc , op - > d . var . attnum ) ;
value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
LLVMBuildStore ( b , value , v_resvaluep ) ;
LLVMBuildStore ( b , value , v_resvaluep ) ;
@ -444,12 +446,12 @@ llvm_compile_expr(ExprState *state)
}
}
/* load data */
/* load data */
v_attnum = l_int32_const ( op - > d . assign_var . attnum ) ;
v_attnum = l_int32_const ( lc , op - > d . assign_var . attnum ) ;
v_value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
v_value = l_load_gep1 ( b , v_values , v_attnum , " " ) ;
v_isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
v_isnull = l_load_gep1 ( b , v_nulls , v_attnum , " " ) ;
/* compute addresses of targets */
/* compute addresses of targets */
v_resultnum = l_int32_const ( op - > d . assign_var . resultnum ) ;
v_resultnum = l_int32_const ( lc , op - > d . assign_var . resultnum ) ;
v_rvaluep = LLVMBuildGEP ( b , v_resultvalues ,
v_rvaluep = LLVMBuildGEP ( b , v_resultvalues ,
& v_resultnum , 1 , " " ) ;
& v_resultnum , 1 , " " ) ;
v_risnullp = LLVMBuildGEP ( b , v_resultnulls ,
v_risnullp = LLVMBuildGEP ( b , v_resultnulls ,
@ -478,7 +480,7 @@ llvm_compile_expr(ExprState *state)
v_isnull = LLVMBuildLoad ( b , v_tmpisnullp , " " ) ;
v_isnull = LLVMBuildLoad ( b , v_tmpisnullp , " " ) ;
/* compute addresses of targets */
/* compute addresses of targets */
v_resultnum = l_int32_const ( resultnum ) ;
v_resultnum = l_int32_const ( lc , resultnum ) ;
v_rvaluep =
v_rvaluep =
LLVMBuildGEP ( b , v_resultvalues , & v_resultnum , 1 , " " ) ;
LLVMBuildGEP ( b , v_resultvalues , & v_resultnum , 1 , " " ) ;
v_risnullp =
v_risnullp =
@ -1703,7 +1705,7 @@ llvm_compile_expr(ExprState *state)
v_cmpresult =
v_cmpresult =
LLVMBuildTrunc ( b ,
LLVMBuildTrunc ( b ,
LLVMBuildLoad ( b , v_resvaluep , " " ) ,
LLVMBuildLoad ( b , v_resvaluep , " " ) ,
LLVMInt32Type ( ) , " " ) ;
LLVMInt32TypeInContext ( lc ) , " " ) ;
switch ( rctype )
switch ( rctype )
{
{
@ -1729,7 +1731,7 @@ llvm_compile_expr(ExprState *state)
v_result = LLVMBuildICmp ( b ,
v_result = LLVMBuildICmp ( b ,
predicate ,
predicate ,
v_cmpresult ,
v_cmpresult ,
l_int32_const ( 0 ) ,
l_int32_const ( lc , 0 ) ,
" " ) ;
" " ) ;
v_result = LLVMBuildZExt ( b , v_result , TypeSizeT , " " ) ;
v_result = LLVMBuildZExt ( b , v_result , TypeSizeT , " " ) ;
@ -1872,7 +1874,7 @@ llvm_compile_expr(ExprState *state)
LLVMValueRef value ,
LLVMValueRef value ,
isnull ;
isnull ;
v_aggno = l_int32_const ( op - > d . aggref . aggno ) ;
v_aggno = l_int32_const ( lc , op - > d . aggref . aggno ) ;
/* load agg value / null */
/* load agg value / null */
value = l_load_gep1 ( b , v_aggvalues , v_aggno , " aggvalue " ) ;
value = l_load_gep1 ( b , v_aggvalues , v_aggno , " aggvalue " ) ;
@ -1906,7 +1908,7 @@ llvm_compile_expr(ExprState *state)
* expression ) . So load it from memory each time round .
* expression ) . So load it from memory each time round .
*/
*/
v_wfuncnop = l_ptr_const ( & wfunc - > wfuncno ,
v_wfuncnop = l_ptr_const ( & wfunc - > wfuncno ,
l_ptr ( LLVMInt32Type ( ) ) ) ;
l_ptr ( LLVMInt32TypeInContext ( lc ) ) ) ;
v_wfuncno = LLVMBuildLoad ( b , v_wfuncnop , " v_wfuncno " ) ;
v_wfuncno = LLVMBuildLoad ( b , v_wfuncnop , " v_wfuncno " ) ;
/* load window func value / null */
/* load window func value / null */
@ -2014,7 +2016,7 @@ llvm_compile_expr(ExprState *state)
/* strict function, check for NULL args */
/* strict function, check for NULL args */
for ( int argno = 0 ; argno < nargs ; argno + + )
for ( int argno = 0 ; argno < nargs ; argno + + )
{
{
LLVMValueRef v_argno = l_int32_const ( argno ) ;
LLVMValueRef v_argno = l_int32_const ( lc , argno ) ;
LLVMValueRef v_argisnull ;
LLVMValueRef v_argisnull ;
LLVMBasicBlockRef b_argnotnull ;
LLVMBasicBlockRef b_argnotnull ;
@ -2071,7 +2073,7 @@ llvm_compile_expr(ExprState *state)
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
" aggstate.all_pergroups " ) ;
" aggstate.all_pergroups " ) ;
v_setoff = l_int32_const ( op - > d . agg_plain_pergroup_nullcheck . setoff ) ;
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 , v_allpergroupsp , v_setoff , " " ) ;
@ -2139,8 +2141,8 @@ llvm_compile_expr(ExprState *state)
l_load_struct_gep ( b , v_aggstatep ,
l_load_struct_gep ( b , v_aggstatep ,
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
FIELDNO_AGGSTATE_ALL_PERGROUPS ,
" aggstate.all_pergroups " ) ;
" aggstate.all_pergroups " ) ;
v_setoff = l_int32_const ( op - > d . agg_trans . setoff ) ;
v_setoff = l_int32_const ( lc , op - > d . agg_trans . setoff ) ;
v_transno = l_int32_const ( op - > d . agg_trans . transno ) ;
v_transno = l_int32_const ( lc , op - > d . agg_trans . transno ) ;
v_pergroupp =
v_pergroupp =
LLVMBuildGEP ( b ,
LLVMBuildGEP ( b ,
l_load_gep1 ( b , v_allpergroupsp , v_setoff , " " ) ,
l_load_gep1 ( b , v_allpergroupsp , v_setoff , " " ) ,
@ -2243,7 +2245,7 @@ llvm_compile_expr(ExprState *state)
/* set aggstate globals */
/* set aggstate globals */
LLVMBuildStore ( b , v_aggcontext , v_curaggcontext ) ;
LLVMBuildStore ( b , v_aggcontext , v_curaggcontext ) ;
LLVMBuildStore ( b , l_int32_const ( op - > d . agg_trans . setno ) ,
LLVMBuildStore ( b , l_int32_const ( lc , op - > d . agg_trans . setno ) ,
v_current_setp ) ;
v_current_setp ) ;
LLVMBuildStore ( b , v_pertransp , v_current_pertransp ) ;
LLVMBuildStore ( b , v_pertransp , v_current_pertransp ) ;
@ -2479,11 +2481,14 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
LLVMModuleRef mod , FunctionCallInfo fcinfo ,
LLVMModuleRef mod , FunctionCallInfo fcinfo ,
LLVMValueRef * v_fcinfo_isnull )
LLVMValueRef * v_fcinfo_isnull )
{
{
LLVMContextRef lc ;
LLVMValueRef v_fn ;
LLVMValueRef v_fn ;
LLVMValueRef v_fcinfo_isnullp ;
LLVMValueRef v_fcinfo_isnullp ;
LLVMValueRef v_retval ;
LLVMValueRef v_retval ;
LLVMValueRef v_fcinfo ;
LLVMValueRef v_fcinfo ;
lc = LLVMGetModuleContext ( mod ) ;
v_fn = llvm_function_reference ( context , b , mod , fcinfo ) ;
v_fn = llvm_function_reference ( context , b , mod , fcinfo ) ;
v_fcinfo = l_ptr_const ( fcinfo , l_ptr ( StructFunctionCallInfoData ) ) ;
v_fcinfo = l_ptr_const ( fcinfo , l_ptr ( StructFunctionCallInfoData ) ) ;
@ -2505,12 +2510,12 @@ BuildV1Call(LLVMJitContext *context, LLVMBuilderRef b,
LLVMValueRef v_lifetime = create_LifetimeEnd ( mod ) ;
LLVMValueRef v_lifetime = create_LifetimeEnd ( mod ) ;
LLVMValueRef params [ 2 ] ;
LLVMValueRef params [ 2 ] ;
params [ 0 ] = l_int64_const ( sizeof ( NullableDatum ) * fcinfo - > nargs ) ;
params [ 0 ] = l_int64_const ( lc , sizeof ( NullableDatum ) * fcinfo - > nargs ) ;
params [ 1 ] = l_ptr_const ( fcinfo - > args , l_ptr ( LLVMInt8Type ( ) ) ) ;
params [ 1 ] = l_ptr_const ( fcinfo - > args , l_ptr ( LLVMInt8TypeInContext ( lc ) ) ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
params [ 0 ] = l_int64_const ( sizeof ( fcinfo - > isnull ) ) ;
params [ 0 ] = l_int64_const ( lc , sizeof ( fcinfo - > isnull ) ) ;
params [ 1 ] = l_ptr_const ( & fcinfo - > isnull , l_ptr ( LLVMInt8Type ( ) ) ) ;
params [ 1 ] = l_ptr_const ( & fcinfo - > isnull , l_ptr ( LLVMInt8TypeInContext ( lc ) ) ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
LLVMBuildCall ( b , v_lifetime , params , lengthof ( params ) , " " ) ;
}
}
@ -2556,6 +2561,7 @@ create_LifetimeEnd(LLVMModuleRef mod)
LLVMTypeRef sig ;
LLVMTypeRef sig ;
LLVMValueRef fn ;
LLVMValueRef fn ;
LLVMTypeRef param_types [ 2 ] ;
LLVMTypeRef param_types [ 2 ] ;
LLVMContextRef lc ;
/* LLVM 5+ has a variadic pointer argument */
/* LLVM 5+ has a variadic pointer argument */
# if LLVM_VERSION_MAJOR < 5
# if LLVM_VERSION_MAJOR < 5
@ -2568,12 +2574,12 @@ create_LifetimeEnd(LLVMModuleRef mod)
if ( fn )
if ( fn )
return fn ;
return fn ;
param_types [ 0 ] = LLVMInt64Type ( ) ;
lc = LLVMGetModuleContext ( mod ) ;
param_types [ 1 ] = l_ptr ( LLVMInt8Type ( ) ) ;
param_types [ 0 ] = LLVMInt64TypeInContext ( lc ) ;
param_types [ 1 ] = l_ptr ( LLVMInt8TypeInContext ( lc ) ) ;
sig = LLVMFunctionType ( LLVMVoidType ( ) ,
sig = LLVMFunctionType ( LLVMVoidTypeInContext ( lc ) , param_types ,
param_types , lengthof ( param_types ) ,
lengthof ( param_types ) , false ) ;
false ) ;
fn = LLVMAddFunction ( mod , nm , sig ) ;
fn = LLVMAddFunction ( mod , nm , sig ) ;
LLVMSetFunctionCallConv ( fn , LLVMCCallConv ) ;
LLVMSetFunctionCallConv ( fn , LLVMCCallConv ) ;