2
0

jit.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*-------------------------------------------------------------------------
  2. * jit.h
  3. * Provider independent JIT infrastructure.
  4. *
  5. * Copyright (c) 2016-2022, PostgreSQL Global Development Group
  6. *
  7. * src/include/jit/jit.h
  8. *
  9. *-------------------------------------------------------------------------
  10. */
  11. #ifndef JIT_H
  12. #define JIT_H
  13. #include "executor/instrument.h"
  14. #include "utils/resowner.h"
  15. /* Flags determining what kind of JIT operations to perform */
  16. #define PGJIT_NONE 0
  17. #define PGJIT_PERFORM (1 << 0)
  18. #define PGJIT_OPT3 (1 << 1)
  19. #define PGJIT_INLINE (1 << 2)
  20. #define PGJIT_EXPR (1 << 3)
  21. #define PGJIT_DEFORM (1 << 4)
  22. typedef struct JitInstrumentation
  23. {
  24. /* number of emitted functions */
  25. size_t created_functions;
  26. /* accumulated time to generate code */
  27. instr_time generation_counter;
  28. /* accumulated time for inlining */
  29. instr_time inlining_counter;
  30. /* accumulated time for optimization */
  31. instr_time optimization_counter;
  32. /* accumulated time for code emission */
  33. instr_time emission_counter;
  34. } JitInstrumentation;
  35. /*
  36. * DSM structure for accumulating jit instrumentation of all workers.
  37. */
  38. typedef struct SharedJitInstrumentation
  39. {
  40. int num_workers;
  41. JitInstrumentation jit_instr[FLEXIBLE_ARRAY_MEMBER];
  42. } SharedJitInstrumentation;
  43. typedef struct JitContext
  44. {
  45. /* see PGJIT_* above */
  46. int flags;
  47. ResourceOwner resowner;
  48. JitInstrumentation instr;
  49. } JitContext;
  50. typedef struct JitProviderCallbacks JitProviderCallbacks;
  51. extern void _PG_jit_provider_init(JitProviderCallbacks *cb);
  52. typedef void (*JitProviderInit) (JitProviderCallbacks *cb);
  53. typedef void (*JitProviderResetAfterErrorCB) (void);
  54. typedef void (*JitProviderReleaseContextCB) (JitContext *context);
  55. struct ExprState;
  56. typedef bool (*JitProviderCompileExprCB) (struct ExprState *state);
  57. struct JitProviderCallbacks
  58. {
  59. JitProviderResetAfterErrorCB reset_after_error;
  60. JitProviderReleaseContextCB release_context;
  61. JitProviderCompileExprCB compile_expr;
  62. };
  63. /* GUCs */
  64. extern PGDLLIMPORT bool jit_enabled;
  65. extern PGDLLIMPORT char *jit_provider;
  66. extern PGDLLIMPORT bool jit_debugging_support;
  67. extern PGDLLIMPORT bool jit_dump_bitcode;
  68. extern PGDLLIMPORT bool jit_expressions;
  69. extern PGDLLIMPORT bool jit_profiling_support;
  70. extern PGDLLIMPORT bool jit_tuple_deforming;
  71. extern PGDLLIMPORT double jit_above_cost;
  72. extern PGDLLIMPORT double jit_inline_above_cost;
  73. extern PGDLLIMPORT double jit_optimize_above_cost;
  74. extern void jit_reset_after_error(void);
  75. extern void jit_release_context(JitContext *context);
  76. /*
  77. * Functions for attempting to JIT code. Callers must accept that these might
  78. * not be able to perform JIT (i.e. return false).
  79. */
  80. extern bool jit_compile_expr(struct ExprState *state);
  81. extern void InstrJitAgg(JitInstrumentation *dst, JitInstrumentation *add);
  82. #endif /* JIT_H */