diff options
author | Andres Freund <andres@anarazel.de> | 2018-03-26 12:57:19 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-03-26 12:57:19 -0700 |
commit | 32af96b2b118cd204ca809d7c48c7f8ea7f879cf (patch) | |
tree | d9a09cc42afb193293a0b65cfa080d676763d776 /src/backend/jit/llvm/llvmjit_expr.c | |
parent | 64f85894ad2730fb1449a8e81dd8026604e9a546 (diff) | |
download | postgresql-32af96b2b118cd204ca809d7c48c7f8ea7f879cf.tar.gz postgresql-32af96b2b118cd204ca809d7c48c7f8ea7f879cf.zip |
JIT tuple deforming in LLVM JIT provider.
Performing JIT compilation for deforming gains performance benefits
over unJITed deforming from compile-time knowledge of the tuple
descriptor. Fixed column widths, NOT NULLness, etc can be taken
advantage of.
Right now the JITed deforming is only used when deforming tuples as
part of expression evaluation (and obviously only if the descriptor is
known). It's likely to be beneficial in other cases, too.
By default tuple deforming is JITed whenever an expression is JIT
compiled. There's a separate boolean GUC controlling it, but that's
expected to be primarily useful for development and benchmarking.
Docs will follow in a later commit containing docs for the whole JIT
feature.
Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
Diffstat (limited to 'src/backend/jit/llvm/llvmjit_expr.c')
-rw-r--r-- | src/backend/jit/llvm/llvmjit_expr.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/backend/jit/llvm/llvmjit_expr.c b/src/backend/jit/llvm/llvmjit_expr.c index 667fb01d3be..2074b067bab 100644 --- a/src/backend/jit/llvm/llvmjit_expr.c +++ b/src/backend/jit/llvm/llvmjit_expr.c @@ -152,7 +152,7 @@ llvm_compile_expr(ExprState *state) param_types[0] = l_ptr(StructExprState); /* state */ param_types[1] = l_ptr(StructExprContext); /* econtext */ - param_types[2] = l_ptr(TypeParamBool); /* isnull */ + param_types[2] = l_ptr(TypeParamBool); /* isnull */ eval_sig = LLVMFunctionType(TypeSizeT, param_types, lengthof(param_types), @@ -272,6 +272,7 @@ llvm_compile_expr(ExprState *state) case EEOP_OUTER_FETCHSOME: case EEOP_SCAN_FETCHSOME: { + TupleDesc desc = NULL; LLVMValueRef v_slot; LLVMBasicBlockRef b_fetch; LLVMValueRef v_nvalid; @@ -279,17 +280,38 @@ llvm_compile_expr(ExprState *state) b_fetch = l_bb_before_v(opblocks[i + 1], "op.%d.fetch", i); + if (op->d.fetch.known_desc) + desc = op->d.fetch.known_desc; + if (opcode == EEOP_INNER_FETCHSOME) { + PlanState *is = innerPlanState(parent); + v_slot = v_innerslot; + + if (!desc && + is && + is->ps_ResultTupleSlot && + is->ps_ResultTupleSlot->tts_fixedTupleDescriptor) + desc = is->ps_ResultTupleSlot->tts_tupleDescriptor; } else if (opcode == EEOP_OUTER_FETCHSOME) { + PlanState *os = outerPlanState(parent); + v_slot = v_outerslot; + + if (!desc && + os && + os->ps_ResultTupleSlot && + os->ps_ResultTupleSlot->tts_fixedTupleDescriptor) + desc = os->ps_ResultTupleSlot->tts_tupleDescriptor; } else { v_slot = v_scanslot; + if (!desc && parent) + desc = parent->scandesc; } /* @@ -308,6 +330,27 @@ llvm_compile_expr(ExprState *state) LLVMPositionBuilderAtEnd(b, b_fetch); + /* + * If the tupledesc of the to-be-deformed tuple is known, + * and JITing of deforming is enabled, build deform + * function specific to tupledesc and the exact number of + * to-be-extracted attributes. + */ + if (desc && (context->base.flags & PGJIT_DEFORM)) + { + LLVMValueRef params[1]; + LLVMValueRef l_jit_deform; + + l_jit_deform = + slot_compile_deform(context, desc, + op->d.fetch.last_var); + params[0] = v_slot; + + LLVMBuildCall(b, l_jit_deform, + params, lengthof(params), ""); + + } + else { LLVMValueRef params[2]; |