mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Remove use of LLVMGetElementType() and provide the type of all pointers to LLVMBuildXXX() functions when emitting IR, as required by modern LLVM versions[1]. * For LLVM <= 14, we'll still use the old LLVMBuildXXX() functions. * For LLVM == 15, we'll continue to do the same, explicitly opting out of opaque pointer mode. * For LLVM >= 16, we'll use the new LLVMBuildXXX2() functions that take the extra type argument. The difference is hidden behind some new IR emitting wrapper functions l_load(), l_gep(), l_call() etc. The change is mostly mechanical, except that at each site the correct type had to be provided. In some places we needed to do some extra work to get functions types, including some new wrappers for C++ APIs that are not yet exposed by in LLVM's C API, and some new "example" functions in llvmjit_types.c because it's no longer possible to start from the function pointer type and ask for the function type. Back-patch to 12, because it's a little tricker in 11 and we agreed not to put the latest LLVM support into the upcoming final release of 11. [1] https://llvm.org/docs/OpaquePointers.html Reviewed-by: Dmitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Ronan Dunklau <ronan.dunklau@aiven.io> Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA%2BhUKGKNX_%3Df%2B1C4r06WETKTq0G4Z_7q4L4Fxn5WWpMycDj9Fw%40mail.gmail.com
150 lines
5.0 KiB
C
150 lines
5.0 KiB
C
/*-------------------------------------------------------------------------
|
|
* llvmjit.h
|
|
* LLVM JIT provider.
|
|
*
|
|
* Copyright (c) 2016-2022, PostgreSQL Global Development Group
|
|
*
|
|
* src/include/jit/llvmjit.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#ifndef LLVMJIT_H
|
|
#define LLVMJIT_H
|
|
|
|
/*
|
|
* To avoid breaking cpluspluscheck, allow including the file even when LLVM
|
|
* is not available.
|
|
*/
|
|
#ifdef USE_LLVM
|
|
|
|
#include <llvm-c/Types.h>
|
|
|
|
|
|
/*
|
|
* File needs to be includable by both C and C++ code, and include other
|
|
* headers doing the same. Therefore wrap C portion in our own extern "C" if
|
|
* in C++ mode.
|
|
*/
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#include "access/tupdesc.h"
|
|
#include "fmgr.h"
|
|
#include "jit/jit.h"
|
|
#include "nodes/pg_list.h"
|
|
|
|
typedef struct LLVMJitContext
|
|
{
|
|
JitContext base;
|
|
|
|
/* number of modules created */
|
|
size_t module_generation;
|
|
|
|
/* current, "open for write", module */
|
|
LLVMModuleRef module;
|
|
|
|
/* is there any pending code that needs to be emitted */
|
|
bool compiled;
|
|
|
|
/* # of objects emitted, used to generate non-conflicting names */
|
|
int counter;
|
|
|
|
/* list of handles for code emitted via Orc */
|
|
List *handles;
|
|
} LLVMJitContext;
|
|
|
|
/* llvm module containing information about types */
|
|
extern PGDLLIMPORT LLVMModuleRef llvm_types_module;
|
|
|
|
/* type and struct definitions */
|
|
extern PGDLLIMPORT LLVMTypeRef TypeParamBool;
|
|
extern PGDLLIMPORT LLVMTypeRef TypePGFunction;
|
|
extern PGDLLIMPORT LLVMTypeRef TypeSizeT;
|
|
extern PGDLLIMPORT LLVMTypeRef TypeStorageBool;
|
|
|
|
extern PGDLLIMPORT LLVMTypeRef StructNullableDatum;
|
|
extern PGDLLIMPORT LLVMTypeRef StructTupleDescData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructHeapTupleData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructHeapTupleHeaderData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructMinimalTupleData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructTupleTableSlot;
|
|
extern PGDLLIMPORT LLVMTypeRef StructHeapTupleTableSlot;
|
|
extern PGDLLIMPORT LLVMTypeRef StructMinimalTupleTableSlot;
|
|
extern PGDLLIMPORT LLVMTypeRef StructMemoryContextData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructFunctionCallInfoData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructExprContext;
|
|
extern PGDLLIMPORT LLVMTypeRef StructExprEvalStep;
|
|
extern PGDLLIMPORT LLVMTypeRef StructExprState;
|
|
extern PGDLLIMPORT LLVMTypeRef StructAggState;
|
|
extern PGDLLIMPORT LLVMTypeRef StructAggStatePerTransData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructAggStatePerGroupData;
|
|
extern PGDLLIMPORT LLVMTypeRef StructPlanState;
|
|
|
|
extern PGDLLIMPORT LLVMValueRef AttributeTemplate;
|
|
extern PGDLLIMPORT LLVMValueRef ExecEvalBoolSubroutineTemplate;
|
|
extern PGDLLIMPORT LLVMValueRef ExecEvalSubroutineTemplate;
|
|
|
|
|
|
extern void llvm_enter_fatal_on_oom(void);
|
|
extern void llvm_leave_fatal_on_oom(void);
|
|
extern bool llvm_in_fatal_on_oom(void);
|
|
extern void llvm_reset_after_error(void);
|
|
extern void llvm_assert_in_fatal_section(void);
|
|
|
|
extern LLVMJitContext *llvm_create_context(int jitFlags);
|
|
extern LLVMModuleRef llvm_mutable_module(LLVMJitContext *context);
|
|
extern char *llvm_expand_funcname(LLVMJitContext *context, const char *basename);
|
|
extern void *llvm_get_function(LLVMJitContext *context, const char *funcname);
|
|
extern void llvm_split_symbol_name(const char *name, char **modname, char **funcname);
|
|
extern LLVMTypeRef llvm_pg_var_type(const char *varname);
|
|
extern LLVMTypeRef llvm_pg_var_func_type(const char *varname);
|
|
extern LLVMValueRef llvm_pg_func(LLVMModuleRef mod, const char *funcname);
|
|
extern void llvm_copy_attributes(LLVMValueRef from, LLVMValueRef to);
|
|
extern LLVMValueRef llvm_function_reference(LLVMJitContext *context,
|
|
LLVMBuilderRef builder,
|
|
LLVMModuleRef mod,
|
|
FunctionCallInfo fcinfo);
|
|
|
|
extern void llvm_inline(LLVMModuleRef mod);
|
|
|
|
/*
|
|
****************************************************************************
|
|
* Code generation functions.
|
|
****************************************************************************
|
|
*/
|
|
extern bool llvm_compile_expr(struct ExprState *state);
|
|
struct TupleTableSlotOps;
|
|
extern LLVMValueRef slot_compile_deform(struct LLVMJitContext *context, TupleDesc desc,
|
|
const struct TupleTableSlotOps *ops, int natts);
|
|
|
|
/*
|
|
****************************************************************************
|
|
* Extensions / Backward compatibility section of the LLVM C API
|
|
* Error handling related functions.
|
|
****************************************************************************
|
|
*/
|
|
#if defined(HAVE_DECL_LLVMGETHOSTCPUNAME) && !HAVE_DECL_LLVMGETHOSTCPUNAME
|
|
/** Get the host CPU as a string. The result needs to be disposed with
|
|
LLVMDisposeMessage. */
|
|
extern char *LLVMGetHostCPUName(void);
|
|
#endif
|
|
|
|
#if defined(HAVE_DECL_LLVMGETHOSTCPUFEATURES) && !HAVE_DECL_LLVMGETHOSTCPUFEATURES
|
|
/** Get the host CPU features as a string. The result needs to be disposed
|
|
with LLVMDisposeMessage. */
|
|
extern char *LLVMGetHostCPUFeatures(void);
|
|
#endif
|
|
|
|
extern unsigned LLVMGetAttributeCountAtIndexPG(LLVMValueRef F, uint32 Idx);
|
|
extern LLVMTypeRef LLVMGetFunctionReturnType(LLVMValueRef r);
|
|
extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r);
|
|
|
|
#ifdef __cplusplus
|
|
} /* extern "C" */
|
|
#endif
|
|
|
|
#endif /* USE_LLVM */
|
|
#endif /* LLVMJIT_H */
|