PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <llvm-c/Analysis.h>
#include <llvm-c/BitReader.h>
#include <llvm-c/BitWriter.h>
#include <llvm-c/Core.h>
#include <llvm-c/ExecutionEngine.h>
#include <llvm-c/Orc.h>
#include <llvm-c/OrcEE.h>
#include <llvm-c/LLJIT.h>
#include <llvm-c/Support.h>
#include <llvm-c/Target.h>
#include <llvm-c/Transforms/IPO.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/Scalar.h>
#include <llvm-c/Transforms/Utils.h>
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
#include "miscadmin.h"
#include "portability/instr_time.h"
#include "storage/ipc.h"
#include "utils/memutils.h"
#include "utils/resowner.h"
Go to the source code of this file.
Data Structures | |
struct | LLVMJitHandle |
Macros | |
#define | LLVMJIT_LLVM_CONTEXT_REUSE_MAX 100 |
Typedefs | |
typedef struct LLVMJitHandle | LLVMJitHandle |
Functions | |
static void | llvm_release_context (JitContext *context) |
static void | llvm_session_initialize (void) |
static void | llvm_shutdown (int code, Datum arg) |
static void | llvm_compile_module (LLVMJitContext *context) |
static void | llvm_optimize_module (LLVMJitContext *context, LLVMModuleRef module) |
static void | llvm_create_types (void) |
static void | llvm_set_target (void) |
static void | llvm_recreate_llvm_context (void) |
static uint64_t | llvm_resolve_symbol (const char *name, void *ctx) |
static LLVMOrcLLJITRef | llvm_create_jit_instance (LLVMTargetMachineRef tm) |
static char * | llvm_error_message (LLVMErrorRef error) |
static void | ResOwnerReleaseJitContext (Datum res) |
static void | ResourceOwnerRememberJIT (ResourceOwner owner, LLVMJitContext *handle) |
static void | ResourceOwnerForgetJIT (ResourceOwner owner, LLVMJitContext *handle) |
void | _PG_jit_provider_init (JitProviderCallbacks *cb) |
LLVMJitContext * | llvm_create_context (int jitFlags) |
LLVMModuleRef | llvm_mutable_module (LLVMJitContext *context) |
char * | llvm_expand_funcname (struct LLVMJitContext *context, const char *basename) |
void * | llvm_get_function (LLVMJitContext *context, const char *funcname) |
LLVMTypeRef | llvm_pg_var_type (const char *varname) |
LLVMTypeRef | llvm_pg_var_func_type (const char *varname) |
LLVMValueRef | llvm_pg_func (LLVMModuleRef mod, const char *funcname) |
static void | llvm_copy_attributes_at_index (LLVMValueRef v_from, LLVMValueRef v_to, uint32 index) |
void | llvm_copy_attributes (LLVMValueRef v_from, LLVMValueRef v_to) |
LLVMValueRef | llvm_function_reference (LLVMJitContext *context, LLVMBuilderRef builder, LLVMModuleRef mod, FunctionCallInfo fcinfo) |
static LLVMTypeRef | load_return_type (LLVMModuleRef mod, const char *name) |
void | llvm_split_symbol_name (const char *name, char **modname, char **funcname) |
static LLVMErrorRef | llvm_resolve_symbols (LLVMOrcDefinitionGeneratorRef GeneratorObj, void *Ctx, LLVMOrcLookupStateRef *LookupState, LLVMOrcLookupKind Kind, LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags JDLookupFlags, LLVMOrcCLookupSet LookupSet, size_t LookupSetSize) |
static void | llvm_log_jit_error (void *ctx, LLVMErrorRef error) |
static LLVMOrcObjectLayerRef | llvm_create_object_layer (void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple) |
typedef struct LLVMJitHandle LLVMJitHandle |
void _PG_jit_provider_init | ( | JitProviderCallbacks * | cb | ) |
Definition at line 147 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.
|
static |
Definition at line 701 of file llvmjit.c.
References context, DEBUG1, elog, ereport, errhidecontext(), errhidestmt(), errmsg_internal(), ERROR, error(), filename, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_GET_DOUBLE, INSTR_TIME_SET_CURRENT, jit_dump_bitcode, lappend(), LLVMJitHandle::lljit, llvm_error_message(), llvm_inline(), llvm_opt0_orc, llvm_opt3_orc, llvm_optimize_module(), llvm_ts_context, MemoryContextAlloc(), MemoryContextSwitchTo(), MyProcPid, pfree(), PGJIT_INLINE, PGJIT_OPT3, psprintf(), LLVMJitHandle::resource_tracker, and TopMemoryContext.
Referenced by llvm_get_function().
void llvm_copy_attributes | ( | LLVMValueRef | v_from, |
LLVMValueRef | v_to | ||
) |
Definition at line 512 of file llvmjit.c.
References llvm_copy_attributes_at_index(), and LLVMGetFunctionReturnType().
Referenced by llvm_pg_func(), and slot_compile_deform().
|
static |
Definition at line 488 of file llvmjit.c.
References palloc(), and pfree().
Referenced by llvm_copy_attributes().
LLVMJitContext* llvm_create_context | ( | int | jitFlags | ) |
Definition at line 219 of file llvmjit.c.
References context, CurrentResourceOwner, llvm_assert_in_fatal_section(), llvm_jit_context_in_use_count, llvm_recreate_llvm_context(), llvm_session_initialize(), MemoryContextAllocZero(), ResourceOwnerEnlarge(), ResourceOwnerRememberJIT(), and TopMemoryContext.
Referenced by llvm_compile_expr().
|
static |
Definition at line 1198 of file llvmjit.c.
References elog, ERROR, error(), llvm_create_object_layer(), llvm_error_message(), llvm_log_jit_error(), llvm_resolve_symbols(), and tm.
Referenced by llvm_session_initialize().
|
static |
Definition at line 1167 of file llvmjit.c.
References jit_debugging_support, and jit_profiling_support.
Referenced by llvm_create_jit_instance().
|
static |
Definition at line 987 of file llvmjit.c.
References AttributeTemplate, buf, elog, ERROR, ExecEvalBoolSubroutineTemplate, ExecEvalSubroutineTemplate, llvm_context, llvm_pg_var_type(), llvm_types_module, load_return_type(), MAXPGPATH, pkglib_path, snprintf, StructAggState, StructAggStatePerGroupData, StructAggStatePerTransData, StructExprContext, StructExprEvalStep, StructExprState, StructFunctionCallInfoData, StructHeapTupleData, StructHeapTupleHeaderData, StructHeapTupleTableSlot, StructMemoryContextData, StructMinimalTupleData, StructMinimalTupleTableSlot, StructNullableDatum, StructPlanState, StructTupleDescData, StructTupleTableSlot, TypeParamBool, TypePGFunction, TypeSizeT, and TypeStorageBool.
Referenced by llvm_recreate_llvm_context(), and llvm_session_initialize().
|
static |
Definition at line 1250 of file llvmjit.c.
References error(), and pstrdup().
Referenced by llvm_compile_module(), llvm_create_jit_instance(), llvm_get_function(), llvm_log_jit_error(), and llvm_optimize_module().
char* llvm_expand_funcname | ( | struct LLVMJitContext * | context, |
const char * | basename | ||
) |
Definition at line 337 of file llvmjit.c.
References Assert, context, and psprintf().
Referenced by slot_compile_deform().
LLVMValueRef llvm_function_reference | ( | LLVMJitContext * | context, |
LLVMBuilderRef | builder, | ||
LLVMModuleRef | mod, | ||
FunctionCallInfo | fcinfo | ||
) |
Definition at line 536 of file llvmjit.c.
References AttributeTemplate, FunctionCallInfoBaseData::flinfo, fmgr_symbol(), FmgrInfo::fn_addr, FmgrInfo::fn_oid, funcname, LLVMGetFunctionType(), psprintf(), pstrdup(), and TypePGFunction.
Referenced by BuildV1Call().
void* llvm_get_function | ( | LLVMJitContext * | context, |
const char * | funcname | ||
) |
Definition at line 358 of file llvmjit.c.
References context, elog, ERROR, error(), funcname, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_SET_CURRENT, lfirst, LLVMJitHandle::lljit, llvm_assert_in_fatal_section(), llvm_compile_module(), and llvm_error_message().
Referenced by ExecRunCompiledExpr().
|
static |
Definition at line 1157 of file llvmjit.c.
References elog, error(), llvm_error_message(), and WARNING.
Referenced by llvm_create_jit_instance().
LLVMModuleRef llvm_mutable_module | ( | LLVMJitContext * | context | ) |
Definition at line 312 of file llvmjit.c.
References context, llvm_assert_in_fatal_section(), llvm_context, llvm_generation, llvm_layout, and llvm_triple.
Referenced by slot_compile_deform().
|
static |
Definition at line 599 of file llvmjit.c.
References context, elog, err(), ERROR, llvm_error_message(), options, PGJIT_INLINE, and PGJIT_OPT3.
Referenced by llvm_compile_module().
LLVMValueRef llvm_pg_func | ( | LLVMModuleRef | mod, |
const char * | funcname | ||
) |
Definition at line 460 of file llvmjit.c.
References elog, ERROR, funcname, llvm_copy_attributes(), llvm_types_module, and LLVMGetFunctionType().
Referenced by build_EvalXFuncInt(), and slot_compile_deform().
LLVMTypeRef llvm_pg_var_func_type | ( | const char * | varname | ) |
Definition at line 438 of file llvmjit.c.
References elog, ERROR, llvm_types_module, and LLVMGetFunctionType().
Referenced by slot_compile_deform().
LLVMTypeRef llvm_pg_var_type | ( | const char * | varname | ) |
Definition at line 418 of file llvmjit.c.
References elog, ERROR, and llvm_types_module.
Referenced by llvm_create_types().
|
static |
Definition at line 169 of file llvmjit.c.
References elog, ERROR, llvm_context, llvm_create_types(), llvm_inline_reset_caches(), llvm_jit_context_in_use_count, llvm_llvm_context_reuse_count, and LLVMJIT_LLVM_CONTEXT_REUSE_MAX.
Referenced by llvm_create_context().
|
static |
Definition at line 248 of file llvmjit.c.
References context, lfirst, list_free(), LLVMJitHandle::lljit, llvm_enter_fatal_on_oom(), llvm_jit_context_in_use_count, llvm_leave_fatal_on_oom(), NIL, pfree(), proc_exit_inprogress, LLVMJitHandle::resource_tracker, and ResourceOwnerForgetJIT().
Referenced by _PG_jit_provider_init().
|
static |
Definition at line 1075 of file llvmjit.c.
References Assert, elog, ERROR, funcname, llvm_split_symbol_name(), load_external_function(), pfree(), and WARNING.
Referenced by llvm_resolve_symbols().
|
static |
Definition at line 1114 of file llvmjit.c.
References error(), i, llvm_resolve_symbol(), name, palloc0(), and pfree().
Referenced by llvm_create_jit_instance().
|
static |
Definition at line 817 of file llvmjit.c.
References DEBUG2, elog, error(), FATAL, llvm_context, llvm_create_jit_instance(), llvm_create_types(), llvm_jit_context_in_use_count, llvm_llvm_context_reuse_count, llvm_opt0_orc, llvm_opt3_orc, llvm_session_initialized, llvm_set_target(), llvm_shutdown(), llvm_targetref, llvm_triple, llvm_ts_context, MemoryContextSwitchTo(), on_proc_exit(), and TopMemoryContext.
Referenced by llvm_create_context().
|
static |
Definition at line 968 of file llvmjit.c.
References elog, ERROR, llvm_layout, llvm_triple, llvm_types_module, and pstrdup().
Referenced by llvm_session_initialize().
|
static |
Definition at line 907 of file llvmjit.c.
References Assert, elog, llvm_in_fatal_on_oom(), llvm_jit_context_in_use_count, llvm_opt0_orc, llvm_opt3_orc, llvm_ts_context, PANIC, and proc_exit_inprogress.
Referenced by llvm_session_initialize().
void llvm_split_symbol_name | ( | const char * | name, |
char ** | modname, | ||
char ** | funcname | ||
) |
Definition at line 1041 of file llvmjit.c.
References Assert, funcname, name, pnstrdup(), and pstrdup().
Referenced by llvm_build_inline_plan(), llvm_execute_inline_plan(), and llvm_resolve_symbol().
|
static |
Definition at line 948 of file llvmjit.c.
References elog, ERROR, LLVMGetFunctionReturnType(), name, and value.
Referenced by llvm_create_types().
|
inlinestatic |
Definition at line 135 of file llvmjit.c.
References jit_resowner_desc, PointerGetDatum(), and ResourceOwnerForget().
Referenced by llvm_release_context().
|
inlinestatic |
Definition at line 130 of file llvmjit.c.
References jit_resowner_desc, PointerGetDatum(), and ResourceOwnerRemember().
Referenced by llvm_create_context().
|
static |
Definition at line 1264 of file llvmjit.c.
References context, DatumGetPointer(), jit_release_context(), and res.
Datum AttributeTemplate |
Definition at line 77 of file llvmjit.c.
Referenced by BuildV1Call(), llvm_create_types(), llvm_function_reference(), and slot_compile_deform().
bool ExecEvalBoolSubroutineTemplate |
Definition at line 79 of file llvmjit.c.
Referenced by llvm_create_types().
void ExecEvalSubroutineTemplate |
Definition at line 78 of file llvmjit.c.
Referenced by llvm_create_types().
|
static |
Definition at line 119 of file llvmjit.c.
Referenced by ResourceOwnerForgetJIT(), and ResourceOwnerRememberJIT().
|
static |
Definition at line 93 of file llvmjit.c.
Referenced by llvm_create_types(), llvm_mutable_module(), llvm_recreate_llvm_context(), and llvm_session_initialize().
|
static |
Definition at line 84 of file llvmjit.c.
Referenced by llvm_mutable_module().
|
static |
Definition at line 87 of file llvmjit.c.
Referenced by llvm_create_context(), llvm_recreate_llvm_context(), llvm_release_context(), llvm_session_initialize(), and llvm_shutdown().
|
static |
Definition at line 92 of file llvmjit.c.
Referenced by llvm_mutable_module(), and llvm_set_target().
|
static |
Definition at line 90 of file llvmjit.c.
Referenced by llvm_recreate_llvm_context(), and llvm_session_initialize().
|
static |
Definition at line 98 of file llvmjit.c.
Referenced by llvm_compile_module(), llvm_session_initialize(), and llvm_shutdown().
|
static |
Definition at line 99 of file llvmjit.c.
Referenced by llvm_compile_module(), llvm_session_initialize(), and llvm_shutdown().
Definition at line 83 of file llvmjit.c.
Referenced by llvm_session_initialize().
|
static |
Definition at line 96 of file llvmjit.c.
Referenced by llvm_session_initialize().
|
static |
Definition at line 91 of file llvmjit.c.
Referenced by llvm_mutable_module(), llvm_session_initialize(), and llvm_set_target().
|
static |
Definition at line 97 of file llvmjit.c.
Referenced by llvm_compile_module(), llvm_session_initialize(), and llvm_shutdown().
|
static |
Definition at line 81 of file llvmjit.c.
Referenced by llvm_create_types(), llvm_pg_func(), llvm_pg_var_func_type(), llvm_pg_var_type(), and llvm_set_target().
LLVMTypeRef StructAggState |
Definition at line 72 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructAggStatePerGroupData |
Definition at line 73 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructAggStatePerTransData |
Definition at line 74 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructExprContext |
Definition at line 69 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructExprEvalStep |
Definition at line 70 of file llvmjit.c.
Referenced by build_EvalXFuncInt(), and llvm_create_types().
LLVMTypeRef StructExprState |
Definition at line 71 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructFunctionCallInfoData |
Definition at line 68 of file llvmjit.c.
Referenced by BuildV1Call(), and llvm_create_types().
LLVMTypeRef StructHeapTupleData |
Definition at line 60 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef StructHeapTupleHeaderData |
Definition at line 64 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef StructHeapTupleTableSlot |
Definition at line 65 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef StructMemoryContextData |
Definition at line 67 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructMinimalTupleData |
Definition at line 61 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructMinimalTupleTableSlot |
Definition at line 66 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef StructNullableDatum |
Definition at line 59 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructPlanState |
Definition at line 75 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructTupleDescData |
Definition at line 62 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef StructTupleTableSlot |
Definition at line 63 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef TypeParamBool |
Definition at line 56 of file llvmjit.c.
Referenced by llvm_create_types().
LLVMTypeRef TypePGFunction |
Definition at line 58 of file llvmjit.c.
Referenced by llvm_create_types(), and llvm_function_reference().
LLVMTypeRef TypeSizeT |
Definition at line 55 of file llvmjit.c.
Referenced by llvm_create_types(), and slot_compile_deform().
LLVMTypeRef TypeStorageBool |
Definition at line 57 of file llvmjit.c.
Referenced by BuildV1Call(), llvm_create_types(), and slot_compile_deform().