diff options
author | Andres Freund <andres@anarazel.de> | 2018-03-22 22:15:51 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-03-22 22:15:51 -0700 |
commit | 2111a48a0c5e5198a68cba0c8fb82c4f61be5928 (patch) | |
tree | 9023a35057ba617c55ff67d8648901bdf6b5b62e /src/backend/jit/llvm/llvmjit.c | |
parent | fdb78948d89b5cc018e3dbf851fafd1652cb5921 (diff) | |
download | postgresql-2111a48a0c5e5198a68cba0c8fb82c4f61be5928.tar.gz postgresql-2111a48a0c5e5198a68cba0c8fb82c4f61be5928.zip |
Adapt expression JIT to stdbool.h introduction.
The LLVM JIT provider uses clang to synchronize types between normal C
code and runtime generated code. Clang represents stdbool.h style
booleans in return values & parameters differently from booleans
stored in variables.
Thus the expression compilation code from 2a0faed9d needs to be
adapted to 9a95a77d9. Instead of hardcoding i8 as the type for
booleans (which already was wrong on some edge case platforms!), use
postgres' notion of a boolean as used for storage and for parameters.
Per buildfarm animal xenodermus.
Author: Andres Freund
Diffstat (limited to 'src/backend/jit/llvm/llvmjit.c')
-rw-r--r-- | src/backend/jit/llvm/llvmjit.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c index 21d36605a48..cd3c40c5f1b 100644 --- a/src/backend/jit/llvm/llvmjit.c +++ b/src/backend/jit/llvm/llvmjit.c @@ -46,6 +46,8 @@ typedef struct LLVMJitHandle /* types & functions commonly needed for JITing */ LLVMTypeRef TypeSizeT; +LLVMTypeRef TypeParamBool; +LLVMTypeRef TypeStorageBool; LLVMTypeRef TypePGFunction; LLVMTypeRef StructHeapTupleFieldsField3; LLVMTypeRef StructHeapTupleFields; @@ -682,7 +684,7 @@ llvm_shutdown(int code, Datum arg) } } -/* helper for llvm_create_types */ +/* helper for llvm_create_types, returning a global var's type */ static LLVMTypeRef load_type(LLVMModuleRef mod, const char *name) { @@ -702,6 +704,31 @@ load_type(LLVMModuleRef mod, const char *name) return typ; } +/* helper for llvm_create_types, returning a function's return type */ +static LLVMTypeRef +load_return_type(LLVMModuleRef mod, const char *name) +{ + LLVMValueRef value; + LLVMTypeRef typ; + + /* this'll return a *pointer* to the function */ + value = LLVMGetNamedFunction(mod, name); + if (!value) + elog(ERROR, "function %s is unknown", name); + + /* get type of function pointer */ + typ = LLVMTypeOf(value); + Assert(typ != NULL); + /* dereference pointer */ + typ = LLVMGetElementType(typ); + Assert(typ != NULL); + /* and look at return type */ + typ = LLVMGetReturnType(typ); + Assert(typ != NULL); + + return typ; +} + /* * Load required information, types, function signatures from llvmjit_types.c * and make them available in global variables. @@ -740,6 +767,8 @@ llvm_create_types(void) llvm_layout = pstrdup(LLVMGetDataLayoutStr(mod)); TypeSizeT = load_type(mod, "TypeSizeT"); + TypeParamBool = load_return_type(mod, "FunctionReturningBool"); + TypeStorageBool = load_type(mod, "TypeStorageBool"); TypePGFunction = load_type(mod, "TypePGFunction"); StructExprContext = load_type(mod, "StructExprContext"); StructExprEvalStep = load_type(mod, "StructExprEvalStep"); |