summaryrefslogtreecommitdiff
path: root/src/include/jit
diff options
context:
space:
mode:
authorAndres Freund2018-03-20 09:20:46 +0000
committerAndres Freund2018-03-22 21:45:59 +0000
commit2a0faed9d7028e3830998bd6ca900be651274e27 (patch)
tree0ab54ad8ac5c5d97d7a4dcee4c2d99c7959af2f6 /src/include/jit
parent7ced1d1247286399df53823eb76cacaf6d7fdb22 (diff)
Add expression compilation support to LLVM JIT provider.
In addition to the interpretation of expressions (which back evaluation of WHERE clauses, target list projection, aggregates transition values etc) support compiling expressions to native code, using the infrastructure added in earlier commits. To avoid duplicating a lot of code, only support emitting code for cases that are likely to be performance critical. For expression steps that aren't deemed that, use the existing interpreter. The generated code isn't great - some architectural changes are required to address that. But this already yields a significant speedup for some analytics queries, particularly with WHERE clauses filtering a lot, or computing multiple aggregates. Author: Andres Freund Tested-By: Thomas Munro Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de Disable JITing for VALUES() nodes. VALUES() nodes are only ever executed once. This is primarily helpful for debugging, when forcing JITing even for cheap queries. Author: Andres Freund Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
Diffstat (limited to 'src/include/jit')
-rw-r--r--src/include/jit/jit.h13
-rw-r--r--src/include/jit/llvmjit.h12
2 files changed, 25 insertions, 0 deletions
diff --git a/src/include/jit/jit.h b/src/include/jit/jit.h
index dac8d593eb0..703c5011dae 100644
--- a/src/include/jit/jit.h
+++ b/src/include/jit/jit.h
@@ -19,6 +19,8 @@
#define PGJIT_NONE 0
#define PGJIT_PERFORM 1 << 0
#define PGJIT_OPT3 1 << 1
+/* reserved for PGJIT_INLINE */
+#define PGJIT_EXPR 1 << 3
typedef struct JitContext
@@ -47,11 +49,14 @@ extern void _PG_jit_provider_init(JitProviderCallbacks *cb);
typedef void (*JitProviderInit) (JitProviderCallbacks *cb);
typedef void (*JitProviderResetAfterErrorCB) (void);
typedef void (*JitProviderReleaseContextCB) (JitContext *context);
+struct ExprState;
+typedef bool (*JitProviderCompileExprCB) (struct ExprState *state);
struct JitProviderCallbacks
{
JitProviderResetAfterErrorCB reset_after_error;
JitProviderReleaseContextCB release_context;
+ JitProviderCompileExprCB compile_expr;
};
@@ -60,6 +65,7 @@ extern bool jit_enabled;
extern char *jit_provider;
extern bool jit_debugging_support;
extern bool jit_dump_bitcode;
+extern bool jit_expressions;
extern bool jit_profiling_support;
extern double jit_above_cost;
extern double jit_optimize_above_cost;
@@ -68,4 +74,11 @@ extern double jit_optimize_above_cost;
extern void jit_reset_after_error(void);
extern void jit_release_context(JitContext *context);
+/*
+ * Functions for attempting to JIT code. Callers must accept that these might
+ * not be able to perform JIT (i.e. return false).
+ */
+extern bool jit_compile_expr(struct ExprState *state);
+
+
#endif /* JIT_H */
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 6327be1e3cf..0c97d231f1d 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -29,6 +29,7 @@ extern "C"
#endif
+#include "fmgr.h"
#include "jit/jit.h"
#include "nodes/pg_list.h"
@@ -91,10 +92,21 @@ extern void *llvm_get_function(LLVMJitContext *context, const char *funcname);
extern void llvm_split_symbol_name(const char *name, char **modname, char **funcname);
extern LLVMValueRef llvm_get_decl(LLVMModuleRef mod, LLVMValueRef f);
extern void llvm_copy_attributes(LLVMValueRef from, LLVMValueRef to);
+extern LLVMValueRef llvm_function_reference(LLVMJitContext *context,
+ LLVMBuilderRef builder,
+ LLVMModuleRef mod,
+ FunctionCallInfo fcinfo);
/*
****************************************************************************
+ * Code ceneration functions.
+ ****************************************************************************
+ */
+extern bool llvm_compile_expr(struct ExprState *state);
+
+/*
+ ****************************************************************************
* Extensions / Backward compatibility section of the LLVM C API
* Error handling related functions.
****************************************************************************