PostgreSQL Source Code  git master
jit.h File Reference
Include dependency graph for jit.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JitInstrumentation
 
struct  SharedJitInstrumentation
 
struct  JitContext
 
struct  JitProviderCallbacks
 

Macros

#define PGJIT_NONE   0
 
#define PGJIT_PERFORM   (1 << 0)
 
#define PGJIT_OPT3   (1 << 1)
 
#define PGJIT_INLINE   (1 << 2)
 
#define PGJIT_EXPR   (1 << 3)
 
#define PGJIT_DEFORM   (1 << 4)
 

Typedefs

typedef struct JitInstrumentation JitInstrumentation
 
typedef struct SharedJitInstrumentation SharedJitInstrumentation
 
typedef struct JitContext JitContext
 
typedef struct JitProviderCallbacks JitProviderCallbacks
 
typedef void(* JitProviderInit) (JitProviderCallbacks *cb)
 
typedef void(* JitProviderResetAfterErrorCB) (void)
 
typedef void(* JitProviderReleaseContextCB) (JitContext *context)
 
typedef bool(* JitProviderCompileExprCB) (struct ExprState *state)
 

Functions

void _PG_jit_provider_init (JitProviderCallbacks *cb)
 
void jit_reset_after_error (void)
 
void jit_release_context (JitContext *context)
 
bool jit_compile_expr (struct ExprState *state)
 
void InstrJitAgg (JitInstrumentation *dst, JitInstrumentation *add)
 

Variables

bool jit_enabled
 
char * jit_provider
 
bool jit_debugging_support
 
bool jit_dump_bitcode
 
bool jit_expressions
 
bool jit_profiling_support
 
bool jit_tuple_deforming
 
double jit_above_cost
 
double jit_inline_above_cost
 
double jit_optimize_above_cost
 

Macro Definition Documentation

◆ PGJIT_DEFORM

#define PGJIT_DEFORM   (1 << 4)

Definition at line 24 of file jit.h.

Referenced by ExplainPrintJIT(), llvm_compile_expr(), and standard_planner().

◆ PGJIT_EXPR

#define PGJIT_EXPR   (1 << 3)

Definition at line 23 of file jit.h.

Referenced by ExplainPrintJIT(), jit_compile_expr(), and standard_planner().

◆ PGJIT_INLINE

#define PGJIT_INLINE   (1 << 2)

Definition at line 22 of file jit.h.

Referenced by ExplainPrintJIT(), llvm_compile_module(), llvm_optimize_module(), and standard_planner().

◆ PGJIT_NONE

#define PGJIT_NONE   0

Definition at line 19 of file jit.h.

Referenced by ExecInitParallelPlan(), standard_planner(), and ValuesNext().

◆ PGJIT_OPT3

#define PGJIT_OPT3   (1 << 1)

Definition at line 21 of file jit.h.

Referenced by ExplainPrintJIT(), llvm_compile_module(), llvm_optimize_module(), and standard_planner().

◆ PGJIT_PERFORM

#define PGJIT_PERFORM   (1 << 0)

Definition at line 20 of file jit.h.

Referenced by ExplainPrintJITSummary(), jit_compile_expr(), and standard_planner().

Typedef Documentation

◆ JitContext

typedef struct JitContext JitContext

◆ JitInstrumentation

◆ JitProviderCallbacks

Definition at line 64 of file jit.h.

◆ JitProviderCompileExprCB

typedef bool(* JitProviderCompileExprCB) (struct ExprState *state)

Definition at line 71 of file jit.h.

◆ JitProviderInit

typedef void(* JitProviderInit) (JitProviderCallbacks *cb)

Definition at line 67 of file jit.h.

◆ JitProviderReleaseContextCB

typedef void(* JitProviderReleaseContextCB) (JitContext *context)

Definition at line 69 of file jit.h.

◆ JitProviderResetAfterErrorCB

typedef void(* JitProviderResetAfterErrorCB) (void)

Definition at line 68 of file jit.h.

◆ SharedJitInstrumentation

Function Documentation

◆ _PG_jit_provider_init()

void _PG_jit_provider_init ( JitProviderCallbacks cb)

Definition at line 125 of file llvmjit.c.

References JitProviderCallbacks::compile_expr, llvm_compile_expr(), llvm_release_context(), llvm_reset_after_error(), JitProviderCallbacks::release_context, and JitProviderCallbacks::reset_after_error.

126 {
130 }
JitProviderResetAfterErrorCB reset_after_error
Definition: jit.h:75
JitProviderCompileExprCB compile_expr
Definition: jit.h:77
void llvm_reset_after_error(void)
static void llvm_release_context(JitContext *context)
Definition: llvmjit.c:165
bool llvm_compile_expr(ExprState *state)
Definition: llvmjit_expr.c:73
JitProviderReleaseContextCB release_context
Definition: jit.h:76

◆ InstrJitAgg()

◆ jit_compile_expr()

bool jit_compile_expr ( struct ExprState state)

Definition at line 156 of file jit.c.

References JitProviderCallbacks::compile_expr, EState::es_jit_flags, ExprState::parent, PGJIT_EXPR, PGJIT_PERFORM, provider_init(), and PlanState::state.

Referenced by ExecReadyExpr().

157 {
158  /*
159  * We can easily create a one-off context for functions without an
160  * associated PlanState (and thus EState). But because there's no executor
161  * shutdown callback that could deallocate the created function, they'd
162  * live to the end of the transactions, where they'd be cleaned up by the
163  * resowner machinery. That can lead to a noticeable amount of memory
164  * usage, and worse, trigger some quadratic behaviour in gdb. Therefore,
165  * at least for now, don't create a JITed function in those circumstances.
166  */
167  if (!state->parent)
168  return false;
169 
170  /* if no jitting should be performed at all */
171  if (!(state->parent->state->es_jit_flags & PGJIT_PERFORM))
172  return false;
173 
174  /* or if expressions aren't JITed */
175  if (!(state->parent->state->es_jit_flags & PGJIT_EXPR))
176  return false;
177 
178  /* this also takes !jit_enabled into account */
179  if (provider_init())
180  return provider.compile_expr(state);
181 
182  return false;
183 }
#define PGJIT_EXPR
Definition: jit.h:23
struct PlanState * parent
Definition: execnodes.h:108
EState * state
Definition: execnodes.h:942
static bool provider_init(void)
Definition: jit.c:71
static JitProviderCallbacks provider
Definition: jit.c:46
int es_jit_flags
Definition: execnodes.h:595
JitProviderCompileExprCB compile_expr
Definition: jit.h:77
#define PGJIT_PERFORM
Definition: jit.h:20

◆ jit_release_context()

void jit_release_context ( JitContext context)

Definition at line 141 of file jit.c.

References pfree(), PointerGetDatum, provider_successfully_loaded, JitProviderCallbacks::release_context, ResourceOwnerForgetJIT(), and JitContext::resowner.

Referenced by FreeExecutorState(), and ResourceOwnerReleaseInternal().

142 {
144  provider.release_context(context);
145 
146  ResourceOwnerForgetJIT(context->resowner, PointerGetDatum(context));
147  pfree(context);
148 }
#define PointerGetDatum(X)
Definition: postgres.h:556
void pfree(void *pointer)
Definition: mcxt.c:1031
static JitProviderCallbacks provider
Definition: jit.c:46
ResourceOwner resowner
Definition: jit.h:59
static bool provider_successfully_loaded
Definition: jit.c:47
void ResourceOwnerForgetJIT(ResourceOwner owner, Datum handle)
Definition: resowner.c:1343
JitProviderReleaseContextCB release_context
Definition: jit.h:76

◆ jit_reset_after_error()

void jit_reset_after_error ( void  )

Definition at line 131 of file jit.c.

References provider_successfully_loaded, and JitProviderCallbacks::reset_after_error.

Referenced by PostgresMain().

132 {
135 }
JitProviderResetAfterErrorCB reset_after_error
Definition: jit.h:75
static JitProviderCallbacks provider
Definition: jit.c:46
static bool provider_successfully_loaded
Definition: jit.c:47

Variable Documentation

◆ jit_above_cost

double jit_above_cost

Definition at line 42 of file jit.c.

Referenced by standard_planner().

◆ jit_debugging_support

bool jit_debugging_support

Definition at line 37 of file jit.c.

Referenced by llvm_session_initialize().

◆ jit_dump_bitcode

bool jit_dump_bitcode

Definition at line 38 of file jit.c.

Referenced by llvm_compile_module().

◆ jit_enabled

bool jit_enabled

Definition at line 35 of file jit.c.

Referenced by provider_init(), and standard_planner().

◆ jit_expressions

bool jit_expressions

Definition at line 39 of file jit.c.

Referenced by standard_planner().

◆ jit_inline_above_cost

double jit_inline_above_cost

Definition at line 43 of file jit.c.

Referenced by standard_planner().

◆ jit_optimize_above_cost

double jit_optimize_above_cost

Definition at line 44 of file jit.c.

Referenced by standard_planner().

◆ jit_profiling_support

bool jit_profiling_support

Definition at line 40 of file jit.c.

Referenced by llvm_session_initialize(), and llvm_shutdown().

◆ jit_provider

char* jit_provider

Definition at line 36 of file jit.c.

Referenced by provider_init().

◆ jit_tuple_deforming

bool jit_tuple_deforming

Definition at line 41 of file jit.c.

Referenced by standard_planner().