codekingpro/portable-devtools
115k
1/*-------------------------------------------------------------------------2 * jit.h3 * Provider independent JIT infrastructure.4 *5 * Copyright (c) 2016-2023, PostgreSQL Global Development Group6 *7 * src/include/jit/jit.h8 *9 *-------------------------------------------------------------------------10 */11#ifndef JIT_H12#define JIT_H13 14#include "executor/instrument.h"15#include "utils/resowner.h"16 17 18/* Flags determining what kind of JIT operations to perform */19#define PGJIT_NONE 020#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)25 26 27typedef struct JitInstrumentation28{29 /* number of emitted functions */30 size_t created_functions;31 32 /* accumulated time to generate code */33 instr_time generation_counter;34 35 /* accumulated time for inlining */36 instr_time inlining_counter;37 38 /* accumulated time for optimization */39 instr_time optimization_counter;40 41 /* accumulated time for code emission */42 instr_time emission_counter;43} JitInstrumentation;44 45/*46 * DSM structure for accumulating jit instrumentation of all workers.47 */48typedef struct SharedJitInstrumentation49{50 int num_workers;51 JitInstrumentation jit_instr[FLEXIBLE_ARRAY_MEMBER];52} SharedJitInstrumentation;53 54typedef struct JitContext55{56 /* see PGJIT_* above */57 int flags;58 59 ResourceOwner resowner;60 61 JitInstrumentation instr;62} JitContext;63 64typedef struct JitProviderCallbacks JitProviderCallbacks;65 66extern PGDLLEXPORT void _PG_jit_provider_init(JitProviderCallbacks *cb);67typedef void (*JitProviderInit) (JitProviderCallbacks *cb);68typedef void (*JitProviderResetAfterErrorCB) (void);69typedef void (*JitProviderReleaseContextCB) (JitContext *context);70struct ExprState;71typedef bool (*JitProviderCompileExprCB) (struct ExprState *state);72 73struct JitProviderCallbacks74{75 JitProviderResetAfterErrorCB reset_after_error;76 JitProviderReleaseContextCB release_context;77 JitProviderCompileExprCB compile_expr;78};79 80 81/* GUCs */82extern PGDLLIMPORT bool jit_enabled;83extern PGDLLIMPORT char *jit_provider;84extern PGDLLIMPORT bool jit_debugging_support;85extern PGDLLIMPORT bool jit_dump_bitcode;86extern PGDLLIMPORT bool jit_expressions;87extern PGDLLIMPORT bool jit_profiling_support;88extern PGDLLIMPORT bool jit_tuple_deforming;89extern PGDLLIMPORT double jit_above_cost;90extern PGDLLIMPORT double jit_inline_above_cost;91extern PGDLLIMPORT double jit_optimize_above_cost;92 93 94extern void jit_reset_after_error(void);95extern void jit_release_context(JitContext *context);96 97/*98 * Functions for attempting to JIT code. Callers must accept that these might99 * not be able to perform JIT (i.e. return false).100 */101extern bool jit_compile_expr(struct ExprState *state);102extern void InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add);103 104 105#endif /* JIT_H */106 