PostgreSQL Source Code  git master
llvmjit.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * llvmjit.h
3  * LLVM JIT provider.
4  *
5  * Copyright (c) 2016-2020, PostgreSQL Global Development Group
6  *
7  * src/include/jit/llvmjit.h
8  *
9  *-------------------------------------------------------------------------
10  */
11 #ifndef LLVMJIT_H
12 #define LLVMJIT_H
13 
14 /*
15  * To avoid breaking cpluspluscheck, allow including the file even when LLVM
16  * is not available.
17  */
18 #ifdef USE_LLVM
19 
20 #include <llvm-c/Types.h>
21 
22 
23 /*
24  * File needs to be includable by both C and C++ code, and include other
25  * headers doing the same. Therefore wrap C portion in our own extern "C" if
26  * in C++ mode.
27  */
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32 
33 #include "access/tupdesc.h"
34 #include "fmgr.h"
35 #include "jit/jit.h"
36 #include "nodes/pg_list.h"
37 
38 typedef struct LLVMJitContext
39 {
40  JitContext base;
41 
42  /* number of modules created */
43  size_t module_generation;
44 
45  /* current, "open for write", module */
46  LLVMModuleRef module;
47 
48  /* is there any pending code that needs to be emitted */
49  bool compiled;
50 
51  /* # of objects emitted, used to generate non-conflicting names */
52  int counter;
53 
54  /* list of handles for code emitted via Orc */
55  List *handles;
56 } LLVMJitContext;
57 
58 /* llvm module containing information about types */
59 extern LLVMModuleRef llvm_types_module;
60 
61 /* type and struct definitions */
62 extern LLVMTypeRef TypeParamBool;
63 extern LLVMTypeRef TypePGFunction;
64 extern LLVMTypeRef TypeSizeT;
65 extern LLVMTypeRef TypeStorageBool;
66 
67 extern LLVMTypeRef StructNullableDatum;
68 extern LLVMTypeRef StructTupleDescData;
69 extern LLVMTypeRef StructHeapTupleData;
70 extern LLVMTypeRef StructTupleTableSlot;
71 extern LLVMTypeRef StructHeapTupleTableSlot;
72 extern LLVMTypeRef StructMinimalTupleTableSlot;
73 extern LLVMTypeRef StructMemoryContextData;
74 extern LLVMTypeRef StructFunctionCallInfoData;
75 extern LLVMTypeRef StructExprContext;
76 extern LLVMTypeRef StructExprEvalStep;
77 extern LLVMTypeRef StructExprState;
78 extern LLVMTypeRef StructAggState;
79 extern LLVMTypeRef StructAggStatePerTransData;
80 extern LLVMTypeRef StructAggStatePerGroupData;
81 
82 extern LLVMValueRef AttributeTemplate;
83 
84 
85 extern void llvm_enter_fatal_on_oom(void);
86 extern void llvm_leave_fatal_on_oom(void);
87 extern void llvm_reset_after_error(void);
88 extern void llvm_assert_in_fatal_section(void);
89 
90 extern LLVMJitContext *llvm_create_context(int jitFlags);
91 extern LLVMModuleRef llvm_mutable_module(LLVMJitContext *context);
92 extern char *llvm_expand_funcname(LLVMJitContext *context, const char *basename);
93 extern void *llvm_get_function(LLVMJitContext *context, const char *funcname);
94 extern void llvm_split_symbol_name(const char *name, char **modname, char **funcname);
95 extern LLVMValueRef llvm_pg_func(LLVMModuleRef mod, const char *funcname);
96 extern void llvm_copy_attributes(LLVMValueRef from, LLVMValueRef to);
97 extern LLVMValueRef llvm_function_reference(LLVMJitContext *context,
98  LLVMBuilderRef builder,
99  LLVMModuleRef mod,
100  FunctionCallInfo fcinfo);
101 
102 extern void llvm_inline(LLVMModuleRef mod);
103 
104 /*
105  ****************************************************************************
106  * Code generation functions.
107  ****************************************************************************
108  */
109 extern bool llvm_compile_expr(struct ExprState *state);
110 struct TupleTableSlotOps;
111 extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDesc desc,
112  const struct TupleTableSlotOps *ops, int natts);
113 
114 /*
115  ****************************************************************************
116  * Extensions / Backward compatibility section of the LLVM C API
117  * Error handling related functions.
118  ****************************************************************************
119  */
120 #if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
121 
123 extern char *LLVMGetHostCPUName(void);
124 #endif
125 
126 #if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
127 
129 extern char *LLVMGetHostCPUFeatures(void);
130 #endif
131 
132 #ifdef __cplusplus
133 } /* extern "C" */
134 #endif
135 
136 #endif /* USE_LLVM */
137 #endif /* LLVMJIT_H */
LLVMValueRef slot_compile_deform(LLVMJitContext *context, TupleDesc desc, const TupleTableSlotOps *ops, int natts)
LLVMTypeRef StructFunctionCallInfoData
Definition: llvmjit.c:70
LLVMTypeRef StructExprEvalStep
Definition: llvmjit.c:72
LLVMTypeRef TypeSizeT
Definition: llvmjit.c:48
LLVMTypeRef StructExprState
Definition: llvmjit.c:73
LLVMTypeRef StructNullableDatum
Definition: llvmjit.c:52
Definition: jit.h:54
LLVMValueRef llvm_function_reference(LLVMJitContext *context, LLVMBuilderRef builder, LLVMModuleRef mod, FunctionCallInfo fcinfo)
Definition: llvmjit.c:353
LLVMJitContext * llvm_create_context(int jitFlags)
Definition: llvmjit.c:128
LLVMTypeRef StructHeapTupleTableSlot
Definition: llvmjit.c:65
LLVMTypeRef StructAggState
Definition: llvmjit.c:74
LLVMTypeRef StructHeapTupleData
Definition: llvmjit.c:57
void llvm_split_symbol_name(const char *name, char **modname, char **funcname)
Definition: llvmjit.c:827
char * llvm_expand_funcname(struct LLVMJitContext *context, const char *basename)
Definition: llvmjit.c:214
void llvm_assert_in_fatal_section(void)
LLVMTypeRef TypeStorageBool
Definition: llvmjit.c:50
LLVMTypeRef StructMemoryContextData
Definition: llvmjit.c:67
LLVMTypeRef StructExprContext
Definition: llvmjit.c:71
LLVMTypeRef TypePGFunction
Definition: llvmjit.c:51
LLVMTypeRef StructAggStatePerTransData
Definition: llvmjit.c:76
void llvm_reset_after_error(void)
LLVMTypeRef StructMinimalTupleTableSlot
Definition: llvmjit.c:66
LLVMTypeRef StructTupleTableSlot
Definition: llvmjit.c:64
LLVMModuleRef llvm_mutable_module(LLVMJitContext *context)
Definition: llvmjit.c:189
Definition: regguts.h:298
bool llvm_compile_expr(ExprState *state)
Definition: llvmjit_expr.c:78
LLVMTypeRef StructTupleDescData
Definition: llvmjit.c:63
LLVMTypeRef TypeParamBool
Definition: llvmjit.c:49
void * llvm_get_function(LLVMJitContext *context, const char *funcname)
Definition: llvmjit.c:235
const char * name
Definition: encode.c:555
void llvm_inline(LLVMModuleRef M)
LLVMModuleRef llvm_types_module
Definition: llvmjit.c:80
void llvm_enter_fatal_on_oom(void)
LLVMValueRef AttributeTemplate
Definition: llvmjit.c:78
void llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
Definition: llvmjit.c:330
Definition: pg_list.h:50
LLVMValueRef llvm_pg_func(LLVMModuleRef mod, const char *funcname)
Definition: llvmjit.c:303
LLVMTypeRef StructAggStatePerGroupData
Definition: llvmjit.c:75
void llvm_leave_fatal_on_oom(void)