1/*-------------------------------------------------------------------------
2 *
3 * llvmjit_types.c
4 * List of types needed by JIT emitting code.
5 *
6 * JIT emitting code often needs to access struct elements, create functions
7 * with the correct signature etc. To allow synchronizing these types with a
8 * low chance of definitions getting out of sync, this file lists types and
9 * functions that directly need to be accessed from LLVM.
10 *
11 * When LLVM is first used in a backend, a bitcode version of this file will
12 * be loaded. The needed types and signatures will be stored into Struct*,
13 * Type*, Func* variables.
14 *
15 * NB: This file will not be linked into the server, it's just converted to
16 * bitcode.
17 *
18 *
19 * Copyright (c) 2016-2019, PostgreSQL Global Development Group
20 *
21 * IDENTIFICATION
22 * src/backend/jit/llvm/llvmjit_types.c
23 *
24 *-------------------------------------------------------------------------
25 */
26
27#include "postgres.h"
28
29#include "access/htup.h"
30#include "access/htup_details.h"
31#include "access/tupdesc.h"
32#include "catalog/pg_attribute.h"
33#include "executor/execExpr.h"
34#include "executor/nodeAgg.h"
35#include "executor/tuptable.h"
36#include "fmgr.h"
37#include "nodes/execnodes.h"
38#include "nodes/memnodes.h"
39#include "utils/expandeddatum.h"
40#include "utils/palloc.h"
41
42
43/*
44 * List of types needed for JITing. These have to be non-static, otherwise
45 * clang/LLVM will omit them. As this file will never be linked into
46 * anything, that's harmless.
47 */
48PGFunction TypePGFunction;
49size_t TypeSizeT;
50bool TypeStorageBool;
51
52NullableDatum StructNullableDatum;
53AggState StructAggState;
54AggStatePerGroupData StructAggStatePerGroupData;
55AggStatePerTransData StructAggStatePerTransData;
56ExprContext StructExprContext;
57ExprEvalStep StructExprEvalStep;
58ExprState StructExprState;
59FunctionCallInfoBaseData StructFunctionCallInfoData;
60HeapTupleData StructHeapTupleData;
61MemoryContextData StructMemoryContextData;
62TupleTableSlot StructTupleTableSlot;
63HeapTupleTableSlot StructHeapTupleTableSlot;
64MinimalTupleTableSlot StructMinimalTupleTableSlot;
65TupleDescData StructTupleDescData;
66
67
68/*
69 * To determine which attributes functions need to have (depends e.g. on
70 * compiler version and settings) to be compatible for inlining, we simply
71 * copy the attributes of this function.
72 */
73extern Datum AttributeTemplate(PG_FUNCTION_ARGS);
74Datum
75AttributeTemplate(PG_FUNCTION_ARGS)
76{
77 PG_RETURN_NULL();
78}
79
80/*
81 * Clang represents stdbool.h style booleans that are returned by functions
82 * differently (as i1) than stored ones (as i8). Therefore we do not just need
83 * TypeBool (above), but also a way to determine the width of a returned
84 * integer. This allows us to keep compatible with non-stdbool using
85 * architectures.
86 */
87extern bool FunctionReturningBool(void);
88bool
89FunctionReturningBool(void)
90{
91 return false;
92}
93
94/*
95 * To force signatures of functions used during JITing to be present,
96 * reference the functions required. This again has to be non-static, to avoid
97 * being removed as unnecessary.
98 */
99void *referenced_functions[] =
100{
101 strlen,
102 varsize_any,
103 slot_getsomeattrs_int,
104 slot_getmissingattrs,
105 MakeExpandedObjectReadOnlyInternal,
106 ExecEvalSubscriptingRef,
107 ExecEvalSysVar,
108 ExecAggTransReparent,
109 ExecAggInitGroup
110};
111