PostgreSQL Source Code  git master
llvmjit.c File Reference
#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/OrcBindings.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 "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_private.h"
Include dependency graph for llvmjit.c:

Go to the source code of this file.

Data Structures

struct  LLVMJitHandle
 

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 uint64_t llvm_resolve_symbol (const char *name, void *ctx)
 
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)
 
LLVMValueRef llvm_get_decl (LLVMModuleRef mod, LLVMValueRef v_src)
 
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_type (LLVMModuleRef mod, const char *name)
 
static LLVMTypeRef load_return_type (LLVMModuleRef mod, const char *name)
 
void llvm_split_symbol_name (const char *name, char **modname, char **funcname)
 

Variables

LLVMTypeRef TypeSizeT
 
LLVMTypeRef TypeParamBool
 
LLVMTypeRef TypeStorageBool
 
LLVMTypeRef TypePGFunction
 
LLVMTypeRef StructNullableDatum
 
LLVMTypeRef StructHeapTupleFieldsField3
 
LLVMTypeRef StructHeapTupleFields
 
LLVMTypeRef StructHeapTupleHeaderData
 
LLVMTypeRef StructHeapTupleDataChoice
 
LLVMTypeRef StructHeapTupleData
 
LLVMTypeRef StructMinimalTupleData
 
LLVMTypeRef StructItemPointerData
 
LLVMTypeRef StructBlockId
 
LLVMTypeRef StructFormPgAttribute
 
LLVMTypeRef StructTupleConstr
 
LLVMTypeRef StructTupleDescData
 
LLVMTypeRef StructTupleTableSlot
 
LLVMTypeRef StructHeapTupleTableSlot
 
LLVMTypeRef StructMinimalTupleTableSlot
 
LLVMTypeRef StructMemoryContextData
 
LLVMTypeRef StructPGFinfoRecord
 
LLVMTypeRef StructFmgrInfo
 
LLVMTypeRef StructFunctionCallInfoData
 
LLVMTypeRef StructExprContext
 
LLVMTypeRef StructExprEvalStep
 
LLVMTypeRef StructExprState
 
LLVMTypeRef StructAggState
 
LLVMTypeRef StructAggStatePerGroupData
 
LLVMTypeRef StructAggStatePerTransData
 
LLVMValueRef AttributeTemplate
 
LLVMValueRef FuncStrlen
 
LLVMValueRef FuncVarsizeAny
 
LLVMValueRef FuncSlotGetsomeattrsInt
 
LLVMValueRef FuncSlotGetmissingattrs
 
LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal
 
LLVMValueRef FuncExecEvalSubscriptingRef
 
LLVMValueRef FuncExecEvalSysVar
 
LLVMValueRef FuncExecAggTransReparent
 
LLVMValueRef FuncExecAggInitGroup
 
static bool llvm_session_initialized = false
 
static size_t llvm_generation = 0
 
static const char * llvm_triple = NULL
 
static const char * llvm_layout = NULL
 
static LLVMTargetMachineRef llvm_opt0_targetmachine
 
static LLVMTargetMachineRef llvm_opt3_targetmachine
 
static LLVMTargetRef llvm_targetref
 
static LLVMOrcJITStackRef llvm_opt0_orc
 
static LLVMOrcJITStackRef llvm_opt3_orc
 
 PG_MODULE_MAGIC
 

Typedef Documentation

◆ LLVMJitHandle

typedef struct LLVMJitHandle LLVMJitHandle

Function Documentation

◆ _PG_jit_provider_init()

void _PG_jit_provider_init ( JitProviderCallbacks cb)

Definition at line 121 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.

122 {
126 }
JitProviderResetAfterErrorCB reset_after_error
Definition: jit.h:75
JitProviderCompileExprCB compile_expr
Definition: jit.h:77
void llvm_reset_after_error(void)
static void llvm_release_context(JitContext *context)
Definition: llvmjit.c:161
bool llvm_compile_expr(ExprState *state)
Definition: llvmjit_expr.c:71
JitProviderReleaseContextCB release_context
Definition: jit.h:76

◆ llvm_compile_module()

static void llvm_compile_module ( LLVMJitContext *  context)
static

Definition at line 487 of file llvmjit.c.

References DEBUG1, elog, ereport, errhidecontext(), errhidestmt(), errmsg(), ERROR, filename, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_GET_DOUBLE, INSTR_TIME_SET_CURRENT, jit_dump_bitcode, lappend(), llvm_inline(), llvm_opt0_orc, llvm_opt3_orc, llvm_optimize_module(), llvm_resolve_symbol(), MemoryContextSwitchTo(), MyProcPid, LLVMJitHandle::orc_handle, palloc(), pfree(), PGJIT_INLINE, PGJIT_OPT3, psprintf(), LLVMJitHandle::stack, and TopMemoryContext.

Referenced by llvm_get_function().

488 {
489  LLVMOrcModuleHandle orc_handle;
490  MemoryContext oldcontext;
491  static LLVMOrcJITStackRef compile_orc;
492  instr_time starttime;
493  instr_time endtime;
494 
495  if (context->base.flags & PGJIT_OPT3)
496  compile_orc = llvm_opt3_orc;
497  else
498  compile_orc = llvm_opt0_orc;
499 
500  /* perform inlining */
501  if (context->base.flags & PGJIT_INLINE)
502  {
503  INSTR_TIME_SET_CURRENT(starttime);
504  llvm_inline(context->module);
505  INSTR_TIME_SET_CURRENT(endtime);
506  INSTR_TIME_ACCUM_DIFF(context->base.instr.inlining_counter,
507  endtime, starttime);
508  }
509 
510  if (jit_dump_bitcode)
511  {
512  char *filename;
513 
514  filename = psprintf("%u.%zu.bc",
515  MyProcPid,
516  context->module_generation);
517  LLVMWriteBitcodeToFile(context->module, filename);
518  pfree(filename);
519  }
520 
521 
522  /* optimize according to the chosen optimization settings */
523  INSTR_TIME_SET_CURRENT(starttime);
524  llvm_optimize_module(context, context->module);
525  INSTR_TIME_SET_CURRENT(endtime);
526  INSTR_TIME_ACCUM_DIFF(context->base.instr.optimization_counter,
527  endtime, starttime);
528 
529  if (jit_dump_bitcode)
530  {
531  char *filename;
532 
533  filename = psprintf("%u.%zu.optimized.bc",
534  MyProcPid,
535  context->module_generation);
536  LLVMWriteBitcodeToFile(context->module, filename);
537  pfree(filename);
538  }
539 
540  /*
541  * Emit the code. Note that this can, depending on the optimization
542  * settings, take noticeable resources as code emission executes low-level
543  * instruction combining/selection passes etc. Without optimization a
544  * faster instruction selection mechanism is used.
545  */
546  INSTR_TIME_SET_CURRENT(starttime);
547 #if LLVM_VERSION_MAJOR > 6
548  {
549  if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &orc_handle, context->module,
550  llvm_resolve_symbol, NULL))
551  {
552  elog(ERROR, "failed to JIT module");
553  }
554 
555  /* LLVMOrcAddEagerlyCompiledIR takes ownership of the module */
556  }
557 #elif LLVM_VERSION_MAJOR > 4
558  {
559  LLVMSharedModuleRef smod;
560 
561  smod = LLVMOrcMakeSharedModule(context->module);
562  if (LLVMOrcAddEagerlyCompiledIR(compile_orc, &orc_handle, smod,
563  llvm_resolve_symbol, NULL))
564  {
565  elog(ERROR, "failed to JIT module");
566  }
567  LLVMOrcDisposeSharedModuleRef(smod);
568  }
569 #else /* LLVM 4.0 and 3.9 */
570  {
571  orc_handle = LLVMOrcAddEagerlyCompiledIR(compile_orc, context->module,
572  llvm_resolve_symbol, NULL);
573  LLVMDisposeModule(context->module);
574  }
575 #endif
576  INSTR_TIME_SET_CURRENT(endtime);
577  INSTR_TIME_ACCUM_DIFF(context->base.instr.emission_counter,
578  endtime, starttime);
579 
580  context->module = NULL;
581  context->compiled = true;
582 
583  /* remember emitted code for cleanup and lookups */
585  {
586  LLVMJitHandle *handle;
587 
588  handle = (LLVMJitHandle *) palloc(sizeof(LLVMJitHandle));
589  handle->stack = compile_orc;
590  handle->orc_handle = orc_handle;
591 
592  context->handles = lappend(context->handles, handle);
593  }
594  MemoryContextSwitchTo(oldcontext);
595 
596  ereport(DEBUG1,
597  (errmsg("time to inline: %.3fs, opt: %.3fs, emit: %.3fs",
598  INSTR_TIME_GET_DOUBLE(context->base.instr.inlining_counter),
599  INSTR_TIME_GET_DOUBLE(context->base.instr.optimization_counter),
600  INSTR_TIME_GET_DOUBLE(context->base.instr.emission_counter)),
601  errhidestmt(true),
602  errhidecontext(true)));
603 }
#define DEBUG1
Definition: elog.h:25
int MyProcPid
Definition: globals.c:40
LLVMOrcJITStackRef stack
Definition: llvmjit.c:42
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
struct timeval instr_time
Definition: instr_time.h:150
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
int errhidestmt(bool hide_stmt)
Definition: elog.c:1150
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition: instr_time.h:182
#define INSTR_TIME_GET_DOUBLE(t)
Definition: instr_time.h:199
#define PGJIT_OPT3
Definition: jit.h:21
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
static uint64_t llvm_resolve_symbol(const char *name, void *ctx)
Definition: llvmjit.c:878
LLVMOrcModuleHandle orc_handle
Definition: llvmjit.c:43
#define ereport(elevel, rest)
Definition: elog.h:141
MemoryContext TopMemoryContext
Definition: mcxt.c:44
static LLVMOrcJITStackRef llvm_opt3_orc
Definition: llvmjit.c:101
List * lappend(List *list, void *datum)
Definition: list.c:322
#define PGJIT_INLINE
Definition: jit.h:22
bool jit_dump_bitcode
Definition: jit.c:35
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
static char * filename
Definition: pg_dumpall.c:90
void llvm_inline(LLVMModuleRef M)
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:100
static void llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
Definition: llvmjit.c:416
int errhidecontext(bool hide_ctx)
Definition: elog.c:1169

◆ llvm_copy_attributes()

void llvm_copy_attributes ( LLVMValueRef  v_from,
LLVMValueRef  v_to 
)

Definition at line 332 of file llvmjit.c.

References palloc().

Referenced by llvm_compile_expr(), llvm_get_decl(), and slot_compile_deform().

333 {
334  int num_attributes;
335  int attno;
336  LLVMAttributeRef *attrs;
337 
338  num_attributes =
339  LLVMGetAttributeCountAtIndex(v_from, LLVMAttributeFunctionIndex);
340 
341  attrs = palloc(sizeof(LLVMAttributeRef) * num_attributes);
342  LLVMGetAttributesAtIndex(v_from, LLVMAttributeFunctionIndex, attrs);
343 
344  for (attno = 0; attno < num_attributes; attno++)
345  {
346  LLVMAddAttributeAtIndex(v_to, LLVMAttributeFunctionIndex,
347  attrs[attno]);
348  }
349 }
void * palloc(Size size)
Definition: mcxt.c:949

◆ llvm_create_context()

LLVMJitContext* llvm_create_context ( int  jitFlags)

Definition at line 136 of file llvmjit.c.

References CurrentResourceOwner, llvm_assert_in_fatal_section(), llvm_session_initialize(), MemoryContextAllocZero(), PointerGetDatum, ResourceOwnerEnlargeJIT(), ResourceOwnerRememberJIT(), and TopMemoryContext.

Referenced by llvm_compile_expr().

137 {
138  LLVMJitContext *context;
139 
141 
143 
145 
147  sizeof(LLVMJitContext));
148  context->base.flags = jitFlags;
149 
150  /* ensure cleanup */
151  context->base.resowner = CurrentResourceOwner;
153 
154  return context;
155 }
#define PointerGetDatum(X)
Definition: postgres.h:556
ResourceOwner CurrentResourceOwner
Definition: resowner.c:142
void llvm_assert_in_fatal_section(void)
MemoryContext TopMemoryContext
Definition: mcxt.c:44
void ResourceOwnerRememberJIT(ResourceOwner owner, Datum handle)
Definition: resowner.c:1334
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:839
static void llvm_session_initialize(void)
Definition: llvmjit.c:609
void ResourceOwnerEnlargeJIT(ResourceOwner owner)
Definition: resowner.c:1323

◆ llvm_create_types()

static void llvm_create_types ( void  )
static

Definition at line 773 of file llvmjit.c.

References AttributeTemplate, buf, elog, ERROR, FuncExecAggInitGroup, FuncExecAggTransReparent, FuncExecEvalSubscriptingRef, FuncExecEvalSysVar, FuncMakeExpandedObjectReadOnlyInternal, FuncSlotGetmissingattrs, FuncSlotGetsomeattrsInt, FuncStrlen, FuncVarsizeAny, llvm_layout, llvm_triple, load_return_type(), load_type(), MAXPGPATH, pkglib_path, pstrdup(), snprintf, StructAggState, StructAggStatePerGroupData, StructAggStatePerTransData, StructExprContext, StructExprEvalStep, StructExprState, StructFunctionCallInfoData, StructHeapTupleData, StructHeapTupleTableSlot, StructMemoryContextData, StructMinimalTupleTableSlot, StructNullableDatum, StructTupleDescData, StructTupleTableSlot, TypeParamBool, TypePGFunction, TypeSizeT, and TypeStorageBool.

Referenced by llvm_session_initialize().

774 {
775  char path[MAXPGPATH];
776  LLVMMemoryBufferRef buf;
777  char *msg;
778  LLVMModuleRef mod = NULL;
779 
780  snprintf(path, MAXPGPATH, "%s/%s", pkglib_path, "llvmjit_types.bc");
781 
782  /* open file */
783  if (LLVMCreateMemoryBufferWithContentsOfFile(path, &buf, &msg))
784  {
785  elog(ERROR, "LLVMCreateMemoryBufferWithContentsOfFile(%s) failed: %s",
786  path, msg);
787  }
788 
789  /* eagerly load contents, going to need it all */
790  if (LLVMParseBitcode2(buf, &mod))
791  {
792  elog(ERROR, "LLVMParseBitcode2 of %s failed", path);
793  }
794  LLVMDisposeMemoryBuffer(buf);
795 
796  /*
797  * Load triple & layout from clang emitted file so we're guaranteed to be
798  * compatible.
799  */
800  llvm_triple = pstrdup(LLVMGetTarget(mod));
801  llvm_layout = pstrdup(LLVMGetDataLayoutStr(mod));
802 
803  TypeSizeT = load_type(mod, "TypeSizeT");
804  TypeParamBool = load_return_type(mod, "FunctionReturningBool");
805  TypeStorageBool = load_type(mod, "TypeStorageBool");
806  TypePGFunction = load_type(mod, "TypePGFunction");
807  StructNullableDatum = load_type(mod, "StructNullableDatum");
808  StructExprContext = load_type(mod, "StructExprContext");
809  StructExprEvalStep = load_type(mod, "StructExprEvalStep");
810  StructExprState = load_type(mod, "StructExprState");
811  StructFunctionCallInfoData = load_type(mod, "StructFunctionCallInfoData");
812  StructMemoryContextData = load_type(mod, "StructMemoryContextData");
813  StructTupleTableSlot = load_type(mod, "StructTupleTableSlot");
814  StructHeapTupleTableSlot = load_type(mod, "StructHeapTupleTableSlot");
815  StructMinimalTupleTableSlot = load_type(mod, "StructMinimalTupleTableSlot");
816  StructHeapTupleData = load_type(mod, "StructHeapTupleData");
817  StructTupleDescData = load_type(mod, "StructTupleDescData");
818  StructAggState = load_type(mod, "StructAggState");
819  StructAggStatePerGroupData = load_type(mod, "StructAggStatePerGroupData");
820  StructAggStatePerTransData = load_type(mod, "StructAggStatePerTransData");
821 
822  AttributeTemplate = LLVMGetNamedFunction(mod, "AttributeTemplate");
823  FuncStrlen = LLVMGetNamedFunction(mod, "strlen");
824  FuncVarsizeAny = LLVMGetNamedFunction(mod, "varsize_any");
825  FuncSlotGetsomeattrsInt = LLVMGetNamedFunction(mod, "slot_getsomeattrs_int");
826  FuncSlotGetmissingattrs = LLVMGetNamedFunction(mod, "slot_getmissingattrs");
827  FuncMakeExpandedObjectReadOnlyInternal = LLVMGetNamedFunction(mod, "MakeExpandedObjectReadOnlyInternal");
828  FuncExecEvalSubscriptingRef = LLVMGetNamedFunction(mod, "ExecEvalSubscriptingRef");
829  FuncExecEvalSysVar = LLVMGetNamedFunction(mod, "ExecEvalSysVar");
830  FuncExecAggTransReparent = LLVMGetNamedFunction(mod, "ExecAggTransReparent");
831  FuncExecAggInitGroup = LLVMGetNamedFunction(mod, "ExecAggInitGroup");
832 
833  /*
834  * Leave the module alive, otherwise references to function would be
835  * dangling.
836  */
837 }
LLVMTypeRef StructFunctionCallInfoData
Definition: llvmjit.c:70
static LLVMTypeRef load_type(LLVMModuleRef mod, const char *name)
Definition: llvmjit.c:723
LLVMTypeRef StructExprEvalStep
Definition: llvmjit.c:72
LLVMTypeRef TypeSizeT
Definition: llvmjit.c:48
LLVMTypeRef StructExprState
Definition: llvmjit.c:73
char * pstrdup(const char *in)
Definition: mcxt.c:1186
LLVMValueRef FuncVarsizeAny
Definition: llvmjit.c:80
LLVMTypeRef StructNullableDatum
Definition: llvmjit.c:52
static const char * llvm_layout
Definition: llvmjit.c:93
LLVMTypeRef StructHeapTupleTableSlot
Definition: llvmjit.c:65
LLVMTypeRef StructAggState
Definition: llvmjit.c:74
static LLVMTypeRef load_return_type(LLVMModuleRef mod, const char *name)
Definition: llvmjit.c:743
static const char * llvm_triple
Definition: llvmjit.c:92
LLVMTypeRef StructHeapTupleData
Definition: llvmjit.c:57
#define ERROR
Definition: elog.h:43
#define MAXPGPATH
LLVMValueRef FuncExecAggInitGroup
Definition: llvmjit.c:87
static char * buf
Definition: pg_test_fsync.c:67
LLVMTypeRef TypeStorageBool
Definition: llvmjit.c:50
LLVMValueRef FuncExecEvalSubscriptingRef
Definition: llvmjit.c:84
LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal
Definition: llvmjit.c:83
LLVMValueRef FuncSlotGetsomeattrsInt
Definition: llvmjit.c:81
LLVMTypeRef StructMemoryContextData
Definition: llvmjit.c:67
LLVMTypeRef StructExprContext
Definition: llvmjit.c:71
LLVMTypeRef TypePGFunction
Definition: llvmjit.c:51
LLVMTypeRef StructAggStatePerTransData
Definition: llvmjit.c:76
LLVMValueRef FuncSlotGetmissingattrs
Definition: llvmjit.c:82
LLVMValueRef FuncStrlen
Definition: llvmjit.c:79
LLVMTypeRef StructMinimalTupleTableSlot
Definition: llvmjit.c:66
LLVMTypeRef StructTupleTableSlot
Definition: llvmjit.c:64
LLVMValueRef FuncExecEvalSysVar
Definition: llvmjit.c:85
LLVMTypeRef StructTupleDescData
Definition: llvmjit.c:63
LLVMTypeRef TypeParamBool
Definition: llvmjit.c:49
#define elog(elevel,...)
Definition: elog.h:228
LLVMValueRef AttributeTemplate
Definition: llvmjit.c:78
#define snprintf
Definition: port.h:192
char pkglib_path[MAXPGPATH]
Definition: globals.c:73
LLVMValueRef FuncExecAggTransReparent
Definition: llvmjit.c:86
LLVMTypeRef StructAggStatePerGroupData
Definition: llvmjit.c:75

◆ llvm_expand_funcname()

char* llvm_expand_funcname ( struct LLVMJitContext *  context,
const char *  basename 
)

Definition at line 222 of file llvmjit.c.

References Assert, and psprintf().

Referenced by llvm_compile_expr(), and slot_compile_deform().

223 {
224  Assert(context->module != NULL);
225 
226  context->base.instr.created_functions++;
227 
228  /*
229  * Previously we used dots to separate, but turns out some tools, e.g.
230  * GDB, don't like that and truncate name.
231  */
232  return psprintf("%s_%zu_%d",
233  basename,
234  context->module_generation,
235  context->counter++);
236 }
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
#define Assert(condition)
Definition: c.h:739

◆ llvm_function_reference()

LLVMValueRef llvm_function_reference ( LLVMJitContext *  context,
LLVMBuilderRef  builder,
LLVMModuleRef  mod,
FunctionCallInfo  fcinfo 
)

Definition at line 355 of file llvmjit.c.

References FunctionCallInfoBaseData::flinfo, fmgr_symbol(), FmgrInfo::fn_addr, FmgrInfo::fn_oid, psprintf(), and TypePGFunction.

Referenced by BuildV1Call().

359 {
360  char *modname;
361  char *basename;
362  char *funcname;
363 
364  LLVMValueRef v_fn;
365 
366  fmgr_symbol(fcinfo->flinfo->fn_oid, &modname, &basename);
367 
368  if (modname != NULL && basename != NULL)
369  {
370  /* external function in loadable library */
371  funcname = psprintf("pgextern.%s.%s", modname, basename);
372  }
373  else if (basename != NULL)
374  {
375  /* internal function */
376  funcname = psprintf("%s", basename);
377  }
378  else
379  {
380  /*
381  * Function we don't know to handle, return pointer. We do so by
382  * creating a global constant containing a pointer to the function.
383  * Makes IR more readable.
384  */
385  LLVMValueRef v_fn_addr;
386 
387  funcname = psprintf("pgoidextern.%u",
388  fcinfo->flinfo->fn_oid);
389  v_fn = LLVMGetNamedGlobal(mod, funcname);
390  if (v_fn != 0)
391  return LLVMBuildLoad(builder, v_fn, "");
392 
393  v_fn_addr = l_ptr_const(fcinfo->flinfo->fn_addr, TypePGFunction);
394 
395  v_fn = LLVMAddGlobal(mod, TypePGFunction, funcname);
396  LLVMSetInitializer(v_fn, v_fn_addr);
397  LLVMSetGlobalConstant(v_fn, true);
398 
399  return LLVMBuildLoad(builder, v_fn, "");
400  }
401 
402  /* check if function already has been added */
403  v_fn = LLVMGetNamedFunction(mod, funcname);
404  if (v_fn != 0)
405  return v_fn;
406 
407  v_fn = LLVMAddFunction(mod, funcname, LLVMGetElementType(TypePGFunction));
408 
409  return v_fn;
410 }
PGFunction fn_addr
Definition: fmgr.h:58
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void fmgr_symbol(Oid functionId, char **mod, char **fn)
Definition: fmgr.c:281
LLVMTypeRef TypePGFunction
Definition: llvmjit.c:51
FmgrInfo * flinfo
Definition: fmgr.h:87
Oid fn_oid
Definition: fmgr.h:59

◆ llvm_get_decl()

LLVMValueRef llvm_get_decl ( LLVMModuleRef  mod,
LLVMValueRef  v_src 
)

Definition at line 311 of file llvmjit.c.

References llvm_copy_attributes().

Referenced by llvm_compile_expr(), and slot_compile_deform().

312 {
313  LLVMValueRef v_fn;
314 
315  /* don't repeatedly add function */
316  v_fn = LLVMGetNamedFunction(mod, LLVMGetValueName(v_src));
317  if (v_fn)
318  return v_fn;
319 
320  v_fn = LLVMAddFunction(mod,
321  LLVMGetValueName(v_src),
322  LLVMGetElementType(LLVMTypeOf(v_src)));
323  llvm_copy_attributes(v_src, v_fn);
324 
325  return v_fn;
326 }
void llvm_copy_attributes(LLVMValueRef v_from, LLVMValueRef v_to)
Definition: llvmjit.c:332

◆ llvm_get_function()

void* llvm_get_function ( LLVMJitContext *  context,
const char *  funcname 
)

Definition at line 243 of file llvmjit.c.

References elog, ERROR, lfirst, llvm_assert_in_fatal_section(), llvm_compile_module(), llvm_opt0_orc, llvm_opt3_orc, LLVMJitHandle::orc_handle, and LLVMJitHandle::stack.

Referenced by ExecRunCompiledExpr().

244 {
245  LLVMOrcTargetAddress addr = 0;
246 #if defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
247  ListCell *lc;
248 #endif
249 
251 
252  /*
253  * If there is a pending / not emitted module, compile and emit now.
254  * Otherwise we might not find the [correct] function.
255  */
256  if (!context->compiled)
257  {
258  llvm_compile_module(context);
259  }
260 
261  /*
262  * ORC's symbol table is of *unmangled* symbols. Therefore we don't need
263  * to mangle here.
264  */
265 
266 #if defined(HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN) && HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN
267  foreach(lc, context->handles)
268  {
269  LLVMJitHandle *handle = (LLVMJitHandle *) lfirst(lc);
270 
271  addr = 0;
272  if (LLVMOrcGetSymbolAddressIn(handle->stack, &addr, handle->orc_handle, funcname))
273  elog(ERROR, "failed to look up symbol \"%s\"", funcname);
274  if (addr)
275  return (void *) (uintptr_t) addr;
276  }
277 
278 #else
279 
280 #if LLVM_VERSION_MAJOR < 5
281  if ((addr = LLVMOrcGetSymbolAddress(llvm_opt0_orc, funcname)))
282  return (void *) (uintptr_t) addr;
283  if ((addr = LLVMOrcGetSymbolAddress(llvm_opt3_orc, funcname)))
284  return (void *) (uintptr_t) addr;
285 #else
286  if (LLVMOrcGetSymbolAddress(llvm_opt0_orc, &addr, funcname))
287  elog(ERROR, "failed to look up symbol \"%s\"", funcname);
288  if (addr)
289  return (void *) (uintptr_t) addr;
290  if (LLVMOrcGetSymbolAddress(llvm_opt3_orc, &addr, funcname))
291  elog(ERROR, "failed to look up symbol \"%s\"", funcname);
292  if (addr)
293  return (void *) (uintptr_t) addr;
294 #endif /* LLVM_VERSION_MAJOR */
295 
296 #endif /* HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN */
297 
298  elog(ERROR, "failed to JIT: %s", funcname);
299 
300  return NULL;
301 }
static void llvm_compile_module(LLVMJitContext *context)
Definition: llvmjit.c:487
LLVMOrcJITStackRef stack
Definition: llvmjit.c:42
#define ERROR
Definition: elog.h:43
LLVMOrcModuleHandle orc_handle
Definition: llvmjit.c:43
void llvm_assert_in_fatal_section(void)
static LLVMOrcJITStackRef llvm_opt3_orc
Definition: llvmjit.c:101
#define lfirst(lc)
Definition: pg_list.h:190
#define elog(elevel,...)
Definition: elog.h:228
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:100

◆ llvm_mutable_module()

LLVMModuleRef llvm_mutable_module ( LLVMJitContext *  context)

Definition at line 197 of file llvmjit.c.

References llvm_assert_in_fatal_section(), llvm_generation, llvm_layout, and llvm_triple.

Referenced by llvm_compile_expr(), and slot_compile_deform().

198 {
200 
201  /*
202  * If there's no in-progress module, create a new one.
203  */
204  if (!context->module)
205  {
206  context->compiled = false;
207  context->module_generation = llvm_generation++;
208  context->module = LLVMModuleCreateWithName("pg");
209  LLVMSetTarget(context->module, llvm_triple);
210  LLVMSetDataLayout(context->module, llvm_layout);
211  }
212 
213  return context->module;
214 }
static const char * llvm_layout
Definition: llvmjit.c:93
static const char * llvm_triple
Definition: llvmjit.c:92
void llvm_assert_in_fatal_section(void)
static size_t llvm_generation
Definition: llvmjit.c:91

◆ llvm_optimize_module()

static void llvm_optimize_module ( LLVMJitContext *  context,
LLVMModuleRef  module 
)
static

Definition at line 416 of file llvmjit.c.

References PGJIT_INLINE, and PGJIT_OPT3.

Referenced by llvm_compile_module().

417 {
418  LLVMPassManagerBuilderRef llvm_pmb;
419  LLVMPassManagerRef llvm_mpm;
420  LLVMPassManagerRef llvm_fpm;
421  LLVMValueRef func;
422  int compile_optlevel;
423 
424  if (context->base.flags & PGJIT_OPT3)
425  compile_optlevel = 3;
426  else
427  compile_optlevel = 0;
428 
429  /*
430  * Have to create a new pass manager builder every pass through, as the
431  * inliner has some per-builder state. Otherwise one ends up only inlining
432  * a function the first time though.
433  */
434  llvm_pmb = LLVMPassManagerBuilderCreate();
435  LLVMPassManagerBuilderSetOptLevel(llvm_pmb, compile_optlevel);
436  llvm_fpm = LLVMCreateFunctionPassManagerForModule(module);
437 
438  if (context->base.flags & PGJIT_OPT3)
439  {
440  /* TODO: Unscientifically determined threshold */
441  LLVMPassManagerBuilderUseInlinerWithThreshold(llvm_pmb, 512);
442  }
443  else
444  {
445  /* we rely on mem2reg heavily, so emit even in the O0 case */
446  LLVMAddPromoteMemoryToRegisterPass(llvm_fpm);
447  }
448 
449  LLVMPassManagerBuilderPopulateFunctionPassManager(llvm_pmb, llvm_fpm);
450 
451  /*
452  * Do function level optimization. This could be moved to the point where
453  * functions are emitted, to reduce memory usage a bit.
454  */
455  LLVMInitializeFunctionPassManager(llvm_fpm);
456  for (func = LLVMGetFirstFunction(context->module);
457  func != NULL;
458  func = LLVMGetNextFunction(func))
459  LLVMRunFunctionPassManager(llvm_fpm, func);
460  LLVMFinalizeFunctionPassManager(llvm_fpm);
461  LLVMDisposePassManager(llvm_fpm);
462 
463  /*
464  * Perform module level optimization. We do so even in the non-optimized
465  * case, so always-inline functions etc get inlined. It's cheap enough.
466  */
467  llvm_mpm = LLVMCreatePassManager();
468  LLVMPassManagerBuilderPopulateModulePassManager(llvm_pmb,
469  llvm_mpm);
470  /* always use always-inliner pass */
471  if (!(context->base.flags & PGJIT_OPT3))
472  LLVMAddAlwaysInlinerPass(llvm_mpm);
473  /* if doing inlining, but no expensive optimization, add inlining pass */
474  if (context->base.flags & PGJIT_INLINE
475  && !(context->base.flags & PGJIT_OPT3))
476  LLVMAddFunctionInliningPass(llvm_mpm);
477  LLVMRunPassManager(llvm_mpm, context->module);
478  LLVMDisposePassManager(llvm_mpm);
479 
480  LLVMPassManagerBuilderDispose(llvm_pmb);
481 }
#define PGJIT_OPT3
Definition: jit.h:21
#define PGJIT_INLINE
Definition: jit.h:22

◆ llvm_release_context()

static void llvm_release_context ( JitContext context)
static

Definition at line 161 of file llvmjit.c.

References linitial, list_delete_first(), llvm_enter_fatal_on_oom(), NIL, LLVMJitHandle::orc_handle, pfree(), proc_exit_inprogress, and LLVMJitHandle::stack.

Referenced by _PG_jit_provider_init().

162 {
163  LLVMJitContext *llvm_context = (LLVMJitContext *) context;
164 
166 
167  /*
168  * When this backend is exiting, don't clean up LLVM. As an error might
169  * have occurred from within LLVM, we do not want to risk reentering. All
170  * resource cleanup is going to happen through process exit.
171  */
173  {
174  if (llvm_context->module)
175  {
176  LLVMDisposeModule(llvm_context->module);
177  llvm_context->module = NULL;
178  }
179 
180  while (llvm_context->handles != NIL)
181  {
182  LLVMJitHandle *jit_handle;
183 
184  jit_handle = (LLVMJitHandle *) linitial(llvm_context->handles);
185  llvm_context->handles = list_delete_first(llvm_context->handles);
186 
187  LLVMOrcRemoveModule(jit_handle->stack, jit_handle->orc_handle);
188  pfree(jit_handle);
189  }
190  }
191 }
#define NIL
Definition: pg_list.h:65
LLVMOrcJITStackRef stack
Definition: llvmjit.c:42
void pfree(void *pointer)
Definition: mcxt.c:1056
#define linitial(l)
Definition: pg_list.h:195
LLVMOrcModuleHandle orc_handle
Definition: llvmjit.c:43
bool proc_exit_inprogress
Definition: ipc.c:40
void llvm_enter_fatal_on_oom(void)
List * list_delete_first(List *list)
Definition: list.c:861

◆ llvm_resolve_symbol()

static uint64_t llvm_resolve_symbol ( const char *  name,
void *  ctx 
)
static

Definition at line 878 of file llvmjit.c.

References Assert, elog, ERROR, llvm_split_symbol_name(), load_external_function(), pfree(), and WARNING.

Referenced by llvm_compile_module().

879 {
880  uintptr_t addr;
881  char *funcname;
882  char *modname;
883 
884  /*
885  * macOS prefixes all object level symbols with an underscore. But neither
886  * dlsym() nor PG's inliner expect that. So undo.
887  */
888 #if defined(__darwin__)
889  if (symname[0] != '_')
890  elog(ERROR, "expected prefixed symbol name, but got \"%s\"", symname);
891  symname++;
892 #endif
893 
894  llvm_split_symbol_name(symname, &modname, &funcname);
895 
896  /* functions that aren't resolved to names shouldn't ever get here */
897  Assert(funcname);
898 
899  if (modname)
900  addr = (uintptr_t) load_external_function(modname, funcname,
901  true, NULL);
902  else
903  addr = (uintptr_t) LLVMSearchForAddressOfSymbol(symname);
904 
905  pfree(funcname);
906  if (modname)
907  pfree(modname);
908 
909  /* let LLVM will error out - should never happen */
910  if (!addr)
911  elog(WARNING, "failed to resolve name %s", symname);
912 
913  return (uint64_t) addr;
914 }
void llvm_split_symbol_name(const char *name, char **modname, char **funcname)
Definition: llvmjit.c:844
void pfree(void *pointer)
Definition: mcxt.c:1056
#define ERROR
Definition: elog.h:43
PGFunction load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:107
#define WARNING
Definition: elog.h:40
#define Assert(condition)
Definition: c.h:739
#define elog(elevel,...)
Definition: elog.h:228

◆ llvm_session_initialize()

static void llvm_session_initialize ( void  )
static

Definition at line 609 of file llvmjit.c.

References before_shmem_exit(), DEBUG2, elog, error(), FATAL, jit_debugging_support, jit_profiling_support, llvm_create_types(), llvm_opt0_orc, llvm_opt0_targetmachine, llvm_opt3_orc, llvm_opt3_targetmachine, llvm_session_initialized, llvm_shutdown(), llvm_targetref, llvm_triple, MemoryContextSwitchTo(), and TopMemoryContext.

Referenced by llvm_create_context().

610 {
611  MemoryContext oldcontext;
612  char *error = NULL;
613  char *cpu = NULL;
614  char *features = NULL;
615 
617  return;
618 
620 
621  LLVMInitializeNativeTarget();
622  LLVMInitializeNativeAsmPrinter();
623  LLVMInitializeNativeAsmParser();
624 
625  /*
626  * Synchronize types early, as that also includes inferring the target
627  * triple.
628  */
630 
631  if (LLVMGetTargetFromTriple(llvm_triple, &llvm_targetref, &error) != 0)
632  {
633  elog(FATAL, "failed to query triple %s\n", error);
634  }
635 
636  /*
637  * We want the generated code to use all available features. Therefore
638  * grab the host CPU string and detect features of the current CPU. The
639  * latter is needed because some CPU architectures default to enabling
640  * features not all CPUs have (weird, huh).
641  */
642  cpu = LLVMGetHostCPUName();
643  features = LLVMGetHostCPUFeatures();
644  elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
645  cpu, features);
646 
648  LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
649  LLVMCodeGenLevelNone,
650  LLVMRelocDefault,
651  LLVMCodeModelJITDefault);
653  LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
654  LLVMCodeGenLevelAggressive,
655  LLVMRelocDefault,
656  LLVMCodeModelJITDefault);
657 
658  LLVMDisposeMessage(cpu);
659  cpu = NULL;
660  LLVMDisposeMessage(features);
661  features = NULL;
662 
663  /* force symbols in main binary to be loaded */
664  LLVMLoadLibraryPermanently(NULL);
665 
666  llvm_opt0_orc = LLVMOrcCreateInstance(llvm_opt0_targetmachine);
667  llvm_opt3_orc = LLVMOrcCreateInstance(llvm_opt3_targetmachine);
668 
669 #if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
671  {
672  LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
673 
674  LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
675  LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
676  }
677 #endif
678 #if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
680  {
681  LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
682 
683  LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
684  LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
685  }
686 #endif
687 
689 
691 
692  MemoryContextSwitchTo(oldcontext);
693 }
static void error(void)
Definition: sql-dyntest.c:147
static LLVMTargetMachineRef llvm_opt3_targetmachine
Definition: llvmjit.c:97
bool jit_debugging_support
Definition: jit.c:34
static void llvm_shutdown(int code, Datum arg)
Definition: llvmjit.c:696
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static const char * llvm_triple
Definition: llvmjit.c:92
#define FATAL
Definition: elog.h:52
#define DEBUG2
Definition: elog.h:24
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
MemoryContext TopMemoryContext
Definition: mcxt.c:44
static LLVMOrcJITStackRef llvm_opt3_orc
Definition: llvmjit.c:101
static bool llvm_session_initialized
Definition: llvmjit.c:90
static LLVMTargetRef llvm_targetref
Definition: llvmjit.c:99
bool jit_profiling_support
Definition: jit.c:37
static void llvm_create_types(void)
Definition: llvmjit.c:773
static LLVMTargetMachineRef llvm_opt0_targetmachine
Definition: llvmjit.c:96
#define elog(elevel,...)
Definition: elog.h:228
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:100

◆ llvm_shutdown()

static void llvm_shutdown ( int  code,
Datum  arg 
)
static

Definition at line 696 of file llvmjit.c.

References jit_profiling_support, llvm_opt0_orc, and llvm_opt3_orc.

Referenced by llvm_session_initialize().

697 {
698  /* unregister profiling support, needs to be flushed to be useful */
699 
700  if (llvm_opt3_orc)
701  {
702 #if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
704  LLVMOrcUnregisterPerf(llvm_opt3_orc);
705 #endif
706  LLVMOrcDisposeInstance(llvm_opt3_orc);
707  llvm_opt3_orc = NULL;
708  }
709 
710  if (llvm_opt0_orc)
711  {
712 #if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
714  LLVMOrcUnregisterPerf(llvm_opt0_orc);
715 #endif
716  LLVMOrcDisposeInstance(llvm_opt0_orc);
717  llvm_opt0_orc = NULL;
718  }
719 }
static LLVMOrcJITStackRef llvm_opt3_orc
Definition: llvmjit.c:101
bool jit_profiling_support
Definition: jit.c:37
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:100

◆ llvm_split_symbol_name()

void llvm_split_symbol_name ( const char *  name,
char **  modname,
char **  funcname 
)

Definition at line 844 of file llvmjit.c.

References Assert, pnstrdup(), and pstrdup().

Referenced by llvm_build_inline_plan(), llvm_execute_inline_plan(), and llvm_resolve_symbol().

845 {
846  *modname = NULL;
847  *funcname = NULL;
848 
849  /*
850  * Module function names are pgextern.$module.$funcname
851  */
852  if (strncmp(name, "pgextern.", strlen("pgextern.")) == 0)
853  {
854  /*
855  * Symbol names cannot contain a ., therefore we can split based on
856  * first and last occurrence of one.
857  */
858  *funcname = rindex(name, '.');
859  (*funcname)++; /* jump over . */
860 
861  *modname = pnstrdup(name + strlen("pgextern."),
862  *funcname - name - strlen("pgextern.") - 1);
863  Assert(funcname);
864 
865  *funcname = pstrdup(*funcname);
866  }
867  else
868  {
869  *modname = NULL;
870  *funcname = pstrdup(name);
871  }
872 }
char * pnstrdup(const char *in, Size len)
Definition: mcxt.c:1197
char * pstrdup(const char *in)
Definition: mcxt.c:1186
#define Assert(condition)
Definition: c.h:739
const char * name
Definition: encode.c:521

◆ load_return_type()

static LLVMTypeRef load_return_type ( LLVMModuleRef  mod,
const char *  name 
)
static

Definition at line 743 of file llvmjit.c.

References Assert, elog, ERROR, and value.

Referenced by llvm_create_types().

744 {
745  LLVMValueRef value;
746  LLVMTypeRef typ;
747 
748  /* this'll return a *pointer* to the function */
749  value = LLVMGetNamedFunction(mod, name);
750  if (!value)
751  elog(ERROR, "function %s is unknown", name);
752 
753  /* get type of function pointer */
754  typ = LLVMTypeOf(value);
755  Assert(typ != NULL);
756  /* dereference pointer */
757  typ = LLVMGetElementType(typ);
758  Assert(typ != NULL);
759  /* and look at return type */
760  typ = LLVMGetReturnType(typ);
761  Assert(typ != NULL);
762 
763  return typ;
764 }
static struct @145 value
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:739
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:228

◆ load_type()

static LLVMTypeRef load_type ( LLVMModuleRef  mod,
const char *  name 
)
static

Definition at line 723 of file llvmjit.c.

References Assert, elog, ERROR, and value.

Referenced by llvm_create_types().

724 {
725  LLVMValueRef value;
726  LLVMTypeRef typ;
727 
728  /* this'll return a *pointer* to the global */
729  value = LLVMGetNamedGlobal(mod, name);
730  if (!value)
731  elog(ERROR, "type %s is unknown", name);
732 
733  /* therefore look at the contained type and return that */
734  typ = LLVMTypeOf(value);
735  Assert(typ != NULL);
736  typ = LLVMGetElementType(typ);
737  Assert(typ != NULL);
738  return typ;
739 }
static struct @145 value
#define ERROR
Definition: elog.h:43
#define Assert(condition)
Definition: c.h:739
const char * name
Definition: encode.c:521
#define elog(elevel,...)
Definition: elog.h:228

Variable Documentation

◆ AttributeTemplate

Datum AttributeTemplate

Definition at line 78 of file llvmjit.c.

Referenced by llvm_compile_expr(), llvm_create_types(), and slot_compile_deform().

◆ FuncExecAggInitGroup

LLVMValueRef FuncExecAggInitGroup

Definition at line 87 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecAggTransReparent

LLVMValueRef FuncExecAggTransReparent

Definition at line 86 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecEvalSubscriptingRef

LLVMValueRef FuncExecEvalSubscriptingRef

Definition at line 84 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecEvalSysVar

LLVMValueRef FuncExecEvalSysVar

Definition at line 85 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncMakeExpandedObjectReadOnlyInternal

LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal

Definition at line 83 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncSlotGetmissingattrs

LLVMValueRef FuncSlotGetmissingattrs

Definition at line 82 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ FuncSlotGetsomeattrsInt

LLVMValueRef FuncSlotGetsomeattrsInt

Definition at line 81 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncStrlen

LLVMValueRef FuncStrlen

Definition at line 79 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ FuncVarsizeAny

LLVMValueRef FuncVarsizeAny

Definition at line 80 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ llvm_generation

size_t llvm_generation = 0
static

Definition at line 91 of file llvmjit.c.

Referenced by llvm_mutable_module().

◆ llvm_layout

const char* llvm_layout = NULL
static

Definition at line 93 of file llvmjit.c.

Referenced by llvm_create_types(), and llvm_mutable_module().

◆ llvm_opt0_orc

LLVMOrcJITStackRef llvm_opt0_orc
static

◆ llvm_opt0_targetmachine

LLVMTargetMachineRef llvm_opt0_targetmachine
static

Definition at line 96 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_opt3_orc

LLVMOrcJITStackRef llvm_opt3_orc
static

◆ llvm_opt3_targetmachine

LLVMTargetMachineRef llvm_opt3_targetmachine
static

Definition at line 97 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_session_initialized

bool llvm_session_initialized = false
static

Definition at line 90 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_targetref

LLVMTargetRef llvm_targetref
static

Definition at line 99 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_triple

const char* llvm_triple = NULL
static

Definition at line 92 of file llvmjit.c.

Referenced by llvm_create_types(), llvm_mutable_module(), and llvm_session_initialize().

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 114 of file llvmjit.c.

◆ StructAggState

LLVMTypeRef StructAggState

Definition at line 74 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructAggStatePerGroupData

LLVMTypeRef StructAggStatePerGroupData

Definition at line 75 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructAggStatePerTransData

LLVMTypeRef StructAggStatePerTransData

Definition at line 76 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructBlockId

LLVMTypeRef StructBlockId

Definition at line 60 of file llvmjit.c.

◆ StructExprContext

LLVMTypeRef StructExprContext

Definition at line 71 of file llvmjit.c.

Referenced by build_EvalXFunc(), llvm_compile_expr(), and llvm_create_types().

◆ StructExprEvalStep

LLVMTypeRef StructExprEvalStep

Definition at line 72 of file llvmjit.c.

Referenced by build_EvalXFunc(), llvm_compile_expr(), and llvm_create_types().

◆ StructExprState

LLVMTypeRef StructExprState

Definition at line 73 of file llvmjit.c.

Referenced by build_EvalXFunc(), llvm_compile_expr(), and llvm_create_types().

◆ StructFmgrInfo

LLVMTypeRef StructFmgrInfo

Definition at line 69 of file llvmjit.c.

◆ StructFormPgAttribute

LLVMTypeRef StructFormPgAttribute

Definition at line 61 of file llvmjit.c.

◆ StructFunctionCallInfoData

LLVMTypeRef StructFunctionCallInfoData

Definition at line 70 of file llvmjit.c.

Referenced by BuildV1Call(), llvm_compile_expr(), and llvm_create_types().

◆ StructHeapTupleData

LLVMTypeRef StructHeapTupleData

Definition at line 57 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructHeapTupleDataChoice

LLVMTypeRef StructHeapTupleDataChoice

Definition at line 56 of file llvmjit.c.

◆ StructHeapTupleFields

LLVMTypeRef StructHeapTupleFields

Definition at line 54 of file llvmjit.c.

◆ StructHeapTupleFieldsField3

LLVMTypeRef StructHeapTupleFieldsField3

Definition at line 53 of file llvmjit.c.

◆ StructHeapTupleHeaderData

LLVMTypeRef StructHeapTupleHeaderData

Definition at line 55 of file llvmjit.c.

◆ StructHeapTupleTableSlot

LLVMTypeRef StructHeapTupleTableSlot

Definition at line 65 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ StructItemPointerData

LLVMTypeRef StructItemPointerData

Definition at line 59 of file llvmjit.c.

◆ StructMemoryContextData

LLVMTypeRef StructMemoryContextData

Definition at line 67 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructMinimalTupleData

LLVMTypeRef StructMinimalTupleData

Definition at line 58 of file llvmjit.c.

◆ StructMinimalTupleTableSlot

LLVMTypeRef StructMinimalTupleTableSlot

Definition at line 66 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ StructNullableDatum

LLVMTypeRef StructNullableDatum

Definition at line 52 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructPGFinfoRecord

LLVMTypeRef StructPGFinfoRecord

Definition at line 68 of file llvmjit.c.

◆ StructTupleConstr

LLVMTypeRef StructTupleConstr

Definition at line 62 of file llvmjit.c.

◆ StructTupleDescData

LLVMTypeRef StructTupleDescData

Definition at line 63 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructTupleTableSlot

LLVMTypeRef StructTupleTableSlot

Definition at line 64 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ TypeParamBool

LLVMTypeRef TypeParamBool

Definition at line 49 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ TypePGFunction

LLVMTypeRef TypePGFunction

Definition at line 51 of file llvmjit.c.

Referenced by llvm_compile_expr(), llvm_create_types(), and llvm_function_reference().

◆ TypeSizeT

LLVMTypeRef TypeSizeT

Definition at line 48 of file llvmjit.c.

Referenced by llvm_compile_expr(), llvm_create_types(), and slot_compile_deform().

◆ TypeStorageBool

LLVMTypeRef TypeStorageBool

Definition at line 50 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().