PostgreSQL Source Code  git master
llvmjit.c File Reference
#include "postgres.h"
#include "jit/llvmjit.h"
#include "jit/llvmjit_emit.h"
#include "miscadmin.h"
#include "utils/memutils.h"
#include "utils/resowner_private.h"
#include "portability/instr_time.h"
#include "storage/ipc.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 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

Function Documentation

◆ _PG_jit_provider_init()

void _PG_jit_provider_init ( JitProviderCallbacks cb)

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

126 {
130 }
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:165
bool llvm_compile_expr(ExprState *state)
Definition: llvmjit_expr.c:73
JitProviderReleaseContextCB release_context
Definition: jit.h:76

◆ llvm_compile_module()

static void llvm_compile_module ( LLVMJitContext *  context)
static

Definition at line 491 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().

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

◆ llvm_copy_attributes()

void llvm_copy_attributes ( LLVMValueRef  v_from,
LLVMValueRef  v_to 
)

Definition at line 336 of file llvmjit.c.

References palloc().

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

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

◆ llvm_create_context()

LLVMJitContext* llvm_create_context ( int  jitFlags)

Definition at line 140 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().

141 {
142  LLVMJitContext *context;
143 
145 
147 
149 
151  sizeof(LLVMJitContext));
152  context->base.flags = jitFlags;
153 
154  /* ensure cleanup */
155  context->base.resowner = CurrentResourceOwner;
157 
158  return context;
159 }
#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:814
static void llvm_session_initialize(void)
Definition: llvmjit.c:613
void ResourceOwnerEnlargeJIT(ResourceOwner owner)
Definition: resowner.c:1323

◆ llvm_create_types()

static void llvm_create_types ( void  )
static

Definition at line 777 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().

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

◆ llvm_expand_funcname()

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

Definition at line 226 of file llvmjit.c.

References Assert, and psprintf().

Referenced by llvm_compile_expr(), and slot_compile_deform().

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

◆ llvm_function_reference()

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

Definition at line 359 of file llvmjit.c.

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

Referenced by BuildV1Call().

363 {
364  char *modname;
365  char *basename;
366  char *funcname;
367 
368  LLVMValueRef v_fn;
369 
370  fmgr_symbol(fcinfo->flinfo->fn_oid, &modname, &basename);
371 
372  if (modname != NULL && basename != NULL)
373  {
374  /* external function in loadable library */
375  funcname = psprintf("pgextern.%s.%s", modname, basename);
376  }
377  else if (basename != NULL)
378  {
379  /* internal function */
380  funcname = psprintf("%s", basename);
381  }
382  else
383  {
384  /*
385  * Function we don't know to handle, return pointer. We do so by
386  * creating a global constant containing a pointer to the function.
387  * Makes IR more readable.
388  */
389  LLVMValueRef v_fn_addr;
390 
391  funcname = psprintf("pgoidextern.%u",
392  fcinfo->flinfo->fn_oid);
393  v_fn = LLVMGetNamedGlobal(mod, funcname);
394  if (v_fn != 0)
395  return LLVMBuildLoad(builder, v_fn, "");
396 
397  v_fn_addr = l_ptr_const(fcinfo->flinfo->fn_addr, TypePGFunction);
398 
399  v_fn = LLVMAddGlobal(mod, TypePGFunction, funcname);
400  LLVMSetInitializer(v_fn, v_fn_addr);
401  LLVMSetGlobalConstant(v_fn, true);
402 
403  return LLVMBuildLoad(builder, v_fn, "");
404  }
405 
406  /* check if function already has been added */
407  v_fn = LLVMGetNamedFunction(mod, funcname);
408  if (v_fn != 0)
409  return v_fn;
410 
411  v_fn = LLVMAddFunction(mod, funcname, LLVMGetElementType(TypePGFunction));
412 
413  return v_fn;
414 }
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:55
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 315 of file llvmjit.c.

References llvm_copy_attributes().

Referenced by llvm_compile_expr(), and slot_compile_deform().

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

◆ llvm_get_function()

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

Definition at line 247 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().

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

◆ llvm_mutable_module()

LLVMModuleRef llvm_mutable_module ( LLVMJitContext *  context)

Definition at line 201 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().

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

◆ llvm_optimize_module()

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

Definition at line 420 of file llvmjit.c.

References PGJIT_INLINE, and PGJIT_OPT3.

Referenced by llvm_compile_module().

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

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

◆ llvm_resolve_symbol()

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

Definition at line 884 of file llvmjit.c.

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

Referenced by llvm_compile_module().

885 {
886  uintptr_t addr;
887  char *funcname;
888  char *modname;
889 
890  /*
891  * macOS prefixes all object level symbols with an underscore. But neither
892  * dlsym() nor PG's inliner expect that. So undo.
893  */
894 #if defined(__darwin__)
895  if (symname[0] != '_')
896  elog(ERROR, "expected prefixed symbol name, but got \"%s\"", symname);
897  symname++;
898 #endif
899 
900  llvm_split_symbol_name(symname, &modname, &funcname);
901 
902  /* functions that aren't resolved to names shouldn't ever get here */
903  Assert(funcname);
904 
905  if (modname)
906  addr = (uintptr_t) load_external_function(modname, funcname,
907  true, NULL);
908  else
909  addr = (uintptr_t) LLVMSearchForAddressOfSymbol(symname);
910 
911  pfree(funcname);
912  if (modname)
913  pfree(modname);
914 
915  /* let LLVM will error out - should never happen */
916  if (!addr)
917  elog(WARNING, "failed to resolve name %s", symname);
918 
919  return (uint64_t) addr;
920 }
void llvm_split_symbol_name(const char *name, char **modname, char **funcname)
Definition: llvmjit.c:850
void pfree(void *pointer)
Definition: mcxt.c:1031
#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:732
#define elog(elevel,...)
Definition: elog.h:226

◆ llvm_session_initialize()

static void llvm_session_initialize ( void  )
static

Definition at line 613 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().

614 {
615  MemoryContext oldcontext;
616  char *error = NULL;
617  char *cpu = NULL;
618  char *features = NULL;
619 
621  return;
622 
624 
625  LLVMInitializeNativeTarget();
626  LLVMInitializeNativeAsmPrinter();
627  LLVMInitializeNativeAsmParser();
628 
629  /*
630  * Synchronize types early, as that also includes inferring the target
631  * triple.
632  */
634 
635  if (LLVMGetTargetFromTriple(llvm_triple, &llvm_targetref, &error) != 0)
636  {
637  elog(FATAL, "failed to query triple %s\n", error);
638  }
639 
640  /*
641  * We want the generated code to use all available features. Therefore
642  * grab the host CPU string and detect features of the current CPU. The
643  * latter is needed because some CPU architectures default to enabling
644  * features not all CPUs have (weird, huh).
645  */
646  cpu = LLVMGetHostCPUName();
647  features = LLVMGetHostCPUFeatures();
648  elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features \"%s\"",
649  cpu, features);
650 
652  LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
653  LLVMCodeGenLevelNone,
654  LLVMRelocDefault,
655  LLVMCodeModelJITDefault);
657  LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features,
658  LLVMCodeGenLevelAggressive,
659  LLVMRelocDefault,
660  LLVMCodeModelJITDefault);
661 
662  LLVMDisposeMessage(cpu);
663  cpu = NULL;
664  LLVMDisposeMessage(features);
665  features = NULL;
666 
667  /* force symbols in main binary to be loaded */
668  LLVMLoadLibraryPermanently(NULL);
669 
670  llvm_opt0_orc = LLVMOrcCreateInstance(llvm_opt0_targetmachine);
671  llvm_opt3_orc = LLVMOrcCreateInstance(llvm_opt3_targetmachine);
672 
673 #if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
675  {
676  LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
677 
678  LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
679  LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
680  }
681 #endif
682 #if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
684  {
685  LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
686 
687  LLVMOrcRegisterJITEventListener(llvm_opt0_orc, l);
688  LLVMOrcRegisterJITEventListener(llvm_opt3_orc, l);
689  }
690 #endif
691 
693 
695 
696  MemoryContextSwitchTo(oldcontext);
697 }
static void error(void)
Definition: sql-dyntest.c:147
static LLVMTargetMachineRef llvm_opt3_targetmachine
Definition: llvmjit.c:101
bool jit_debugging_support
Definition: jit.c:37
static void llvm_shutdown(int code, Datum arg)
Definition: llvmjit.c:700
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
static const char * llvm_triple
Definition: llvmjit.c:96
#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:105
static bool llvm_session_initialized
Definition: llvmjit.c:94
static LLVMTargetRef llvm_targetref
Definition: llvmjit.c:103
bool jit_profiling_support
Definition: jit.c:40
static void llvm_create_types(void)
Definition: llvmjit.c:777
static LLVMTargetMachineRef llvm_opt0_targetmachine
Definition: llvmjit.c:100
#define elog(elevel,...)
Definition: elog.h:226
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:104

◆ llvm_shutdown()

static void llvm_shutdown ( int  code,
Datum  arg 
)
static

Definition at line 700 of file llvmjit.c.

References jit_profiling_support, llvm_opt0_orc, and llvm_opt3_orc.

Referenced by llvm_session_initialize().

701 {
702  /* unregister profiling support, needs to be flushed to be useful */
703 
704  if (llvm_opt3_orc)
705  {
706 #if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
708  LLVMOrcUnregisterPerf(llvm_opt3_orc);
709 #endif
710  LLVMOrcDisposeInstance(llvm_opt3_orc);
711  llvm_opt3_orc = NULL;
712  }
713 
714  if (llvm_opt0_orc)
715  {
716 #if defined(HAVE_DECL_LLVMORCREGISTERPERF) && HAVE_DECL_LLVMORCREGISTERPERF
718  LLVMOrcUnregisterPerf(llvm_opt0_orc);
719 #endif
720  LLVMOrcDisposeInstance(llvm_opt0_orc);
721  llvm_opt0_orc = NULL;
722  }
723 }
static LLVMOrcJITStackRef llvm_opt3_orc
Definition: llvmjit.c:105
bool jit_profiling_support
Definition: jit.c:40
static LLVMOrcJITStackRef llvm_opt0_orc
Definition: llvmjit.c:104

◆ llvm_split_symbol_name()

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

Definition at line 850 of file llvmjit.c.

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

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

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

◆ load_return_type()

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

Definition at line 747 of file llvmjit.c.

References Assert, elog, ERROR, and value.

Referenced by llvm_create_types().

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

◆ load_type()

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

Definition at line 727 of file llvmjit.c.

References Assert, elog, ERROR, and value.

Referenced by llvm_create_types().

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

Variable Documentation

◆ AttributeTemplate

Datum AttributeTemplate

Definition at line 82 of file llvmjit.c.

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

◆ FuncExecAggInitGroup

LLVMValueRef FuncExecAggInitGroup

Definition at line 91 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecAggTransReparent

LLVMValueRef FuncExecAggTransReparent

Definition at line 90 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecEvalSubscriptingRef

LLVMValueRef FuncExecEvalSubscriptingRef

Definition at line 88 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncExecEvalSysVar

LLVMValueRef FuncExecEvalSysVar

Definition at line 89 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncMakeExpandedObjectReadOnlyInternal

LLVMValueRef FuncMakeExpandedObjectReadOnlyInternal

Definition at line 87 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncSlotGetmissingattrs

LLVMValueRef FuncSlotGetmissingattrs

Definition at line 86 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ FuncSlotGetsomeattrsInt

LLVMValueRef FuncSlotGetsomeattrsInt

Definition at line 85 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ FuncStrlen

LLVMValueRef FuncStrlen

Definition at line 83 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ FuncVarsizeAny

LLVMValueRef FuncVarsizeAny

Definition at line 84 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ llvm_generation

size_t llvm_generation = 0
static

Definition at line 95 of file llvmjit.c.

Referenced by llvm_mutable_module().

◆ llvm_layout

const char* llvm_layout = NULL
static

Definition at line 97 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 100 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 101 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_session_initialized

bool llvm_session_initialized = false
static

Definition at line 94 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_targetref

LLVMTargetRef llvm_targetref
static

Definition at line 103 of file llvmjit.c.

Referenced by llvm_session_initialize().

◆ llvm_triple

const char* llvm_triple = NULL
static

Definition at line 96 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 118 of file llvmjit.c.

◆ StructAggState

LLVMTypeRef StructAggState

Definition at line 78 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructAggStatePerGroupData

LLVMTypeRef StructAggStatePerGroupData

Definition at line 79 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructAggStatePerTransData

LLVMTypeRef StructAggStatePerTransData

Definition at line 80 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructBlockId

LLVMTypeRef StructBlockId

Definition at line 64 of file llvmjit.c.

◆ StructExprContext

LLVMTypeRef StructExprContext

Definition at line 75 of file llvmjit.c.

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

◆ StructExprEvalStep

LLVMTypeRef StructExprEvalStep

Definition at line 76 of file llvmjit.c.

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

◆ StructExprState

LLVMTypeRef StructExprState

Definition at line 77 of file llvmjit.c.

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

◆ StructFmgrInfo

LLVMTypeRef StructFmgrInfo

Definition at line 73 of file llvmjit.c.

◆ StructFormPgAttribute

LLVMTypeRef StructFormPgAttribute

Definition at line 65 of file llvmjit.c.

◆ StructFunctionCallInfoData

LLVMTypeRef StructFunctionCallInfoData

Definition at line 74 of file llvmjit.c.

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

◆ StructHeapTupleData

LLVMTypeRef StructHeapTupleData

Definition at line 61 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructHeapTupleDataChoice

LLVMTypeRef StructHeapTupleDataChoice

Definition at line 60 of file llvmjit.c.

◆ StructHeapTupleFields

LLVMTypeRef StructHeapTupleFields

Definition at line 58 of file llvmjit.c.

◆ StructHeapTupleFieldsField3

LLVMTypeRef StructHeapTupleFieldsField3

Definition at line 57 of file llvmjit.c.

◆ StructHeapTupleHeaderData

LLVMTypeRef StructHeapTupleHeaderData

Definition at line 59 of file llvmjit.c.

◆ StructHeapTupleTableSlot

LLVMTypeRef StructHeapTupleTableSlot

Definition at line 69 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ StructItemPointerData

LLVMTypeRef StructItemPointerData

Definition at line 63 of file llvmjit.c.

◆ StructMemoryContextData

LLVMTypeRef StructMemoryContextData

Definition at line 71 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructMinimalTupleData

LLVMTypeRef StructMinimalTupleData

Definition at line 62 of file llvmjit.c.

◆ StructMinimalTupleTableSlot

LLVMTypeRef StructMinimalTupleTableSlot

Definition at line 70 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ StructNullableDatum

LLVMTypeRef StructNullableDatum

Definition at line 56 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ StructPGFinfoRecord

LLVMTypeRef StructPGFinfoRecord

Definition at line 72 of file llvmjit.c.

◆ StructTupleConstr

LLVMTypeRef StructTupleConstr

Definition at line 66 of file llvmjit.c.

◆ StructTupleDescData

LLVMTypeRef StructTupleDescData

Definition at line 67 of file llvmjit.c.

Referenced by llvm_create_types().

◆ StructTupleTableSlot

LLVMTypeRef StructTupleTableSlot

Definition at line 68 of file llvmjit.c.

Referenced by llvm_create_types(), and slot_compile_deform().

◆ TypeParamBool

LLVMTypeRef TypeParamBool

Definition at line 53 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().

◆ TypePGFunction

LLVMTypeRef TypePGFunction

Definition at line 55 of file llvmjit.c.

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

◆ TypeSizeT

LLVMTypeRef TypeSizeT

Definition at line 52 of file llvmjit.c.

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

◆ TypeStorageBool

LLVMTypeRef TypeStorageBool

Definition at line 54 of file llvmjit.c.

Referenced by llvm_compile_expr(), and llvm_create_types().