| 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 | */ |
| 48 | PGFunction TypePGFunction; |
| 49 | size_t TypeSizeT; |
| 50 | bool TypeStorageBool; |
| 51 | |
| 52 | NullableDatum StructNullableDatum; |
| 53 | AggState StructAggState; |
| 54 | AggStatePerGroupData StructAggStatePerGroupData; |
| 55 | AggStatePerTransData StructAggStatePerTransData; |
| 56 | ExprContext StructExprContext; |
| 57 | ExprEvalStep StructExprEvalStep; |
| 58 | ExprState StructExprState; |
| 59 | FunctionCallInfoBaseData StructFunctionCallInfoData; |
| 60 | HeapTupleData StructHeapTupleData; |
| 61 | MemoryContextData StructMemoryContextData; |
| 62 | TupleTableSlot StructTupleTableSlot; |
| 63 | HeapTupleTableSlot StructHeapTupleTableSlot; |
| 64 | MinimalTupleTableSlot StructMinimalTupleTableSlot; |
| 65 | TupleDescData 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 | */ |
| 73 | extern Datum AttributeTemplate(PG_FUNCTION_ARGS); |
| 74 | Datum |
| 75 | AttributeTemplate(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 | */ |
| 87 | extern bool FunctionReturningBool(void); |
| 88 | bool |
| 89 | FunctionReturningBool(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 | */ |
| 99 | void *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 | |