1 /*-------------------------------------------------------------------------
3 * Provider independent JIT infrastructure.
5 * Copyright (c) 2016-2023, PostgreSQL Global Development Group
7 * src/include/jit/jit.h
9 *-------------------------------------------------------------------------
14 #include "executor/instrument.h"
15 #include "utils/resowner.h"
18 /* Flags determining what kind of JIT operations to perform */
20 #define PGJIT_PERFORM (1 << 0)
21 #define PGJIT_OPT3 (1 << 1)
22 #define PGJIT_INLINE (1 << 2)
23 #define PGJIT_EXPR (1 << 3)
24 #define PGJIT_DEFORM (1 << 4)
27 typedef struct JitInstrumentation
29 /* number of emitted functions */
30 size_t created_functions
;
32 /* accumulated time to generate code */
33 instr_time generation_counter
;
35 /* accumulated time for inlining */
36 instr_time inlining_counter
;
38 /* accumulated time for optimization */
39 instr_time optimization_counter
;
41 /* accumulated time for code emission */
42 instr_time emission_counter
;
46 * DSM structure for accumulating jit instrumentation of all workers.
48 typedef struct SharedJitInstrumentation
51 JitInstrumentation jit_instr
[FLEXIBLE_ARRAY_MEMBER
];
52 } SharedJitInstrumentation
;
54 typedef struct JitContext
56 /* see PGJIT_* above */
59 ResourceOwner resowner
;
61 JitInstrumentation instr
;
64 typedef struct JitProviderCallbacks JitProviderCallbacks
;
66 extern PGDLLEXPORT
void _PG_jit_provider_init(JitProviderCallbacks
*cb
);
67 typedef void (*JitProviderInit
) (JitProviderCallbacks
*cb
);
68 typedef void (*JitProviderResetAfterErrorCB
) (void);
69 typedef void (*JitProviderReleaseContextCB
) (JitContext
*context
);
71 typedef bool (*JitProviderCompileExprCB
) (struct ExprState
*state
);
73 struct JitProviderCallbacks
75 JitProviderResetAfterErrorCB reset_after_error
;
76 JitProviderReleaseContextCB release_context
;
77 JitProviderCompileExprCB compile_expr
;
82 extern PGDLLIMPORT
bool jit_enabled
;
83 extern PGDLLIMPORT
char *jit_provider
;
84 extern PGDLLIMPORT
bool jit_debugging_support
;
85 extern PGDLLIMPORT
bool jit_dump_bitcode
;
86 extern PGDLLIMPORT
bool jit_expressions
;
87 extern PGDLLIMPORT
bool jit_profiling_support
;
88 extern PGDLLIMPORT
bool jit_tuple_deforming
;
89 extern PGDLLIMPORT
double jit_above_cost
;
90 extern PGDLLIMPORT
double jit_inline_above_cost
;
91 extern PGDLLIMPORT
double jit_optimize_above_cost
;
94 extern void jit_reset_after_error(void);
95 extern void jit_release_context(JitContext
*context
);
98 * Functions for attempting to JIT code. Callers must accept that these might
99 * not be able to perform JIT (i.e. return false).
101 extern bool jit_compile_expr(struct ExprState
*state
);
102 extern void InstrJitAgg(JitInstrumentation
*dst
, JitInstrumentation
*add
);