From 32af96b2b118cd204ca809d7c48c7f8ea7f879cf Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 26 Mar 2018 12:57:19 -0700 Subject: 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 --- src/backend/jit/llvm/llvmjit_expr.c | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/backend/jit/llvm/llvmjit_expr.c') 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]; -- cgit v1.2.3