Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2111a48

Browse files
committed
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 2a0faed needs to be adapted to 9a95a77. 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
1 parent fdb7894 commit 2111a48

File tree

5 files changed

+132
-64
lines changed

5 files changed

+132
-64
lines changed

src/backend/jit/llvm/llvmjit.c

+30-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ typedef struct LLVMJitHandle
4646

4747
/* types & functions commonly needed for JITing */
4848
LLVMTypeRef TypeSizeT;
49+
LLVMTypeRef TypeParamBool;
50+
LLVMTypeRef TypeStorageBool;
4951
LLVMTypeRef TypePGFunction;
5052
LLVMTypeRef StructHeapTupleFieldsField3;
5153
LLVMTypeRef StructHeapTupleFields;
@@ -682,7 +684,7 @@ llvm_shutdown(int code, Datum arg)
682684
}
683685
}
684686

685-
/* helper for llvm_create_types */
687+
/* helper for llvm_create_types, returning a global var's type */
686688
static LLVMTypeRef
687689
load_type(LLVMModuleRef mod, const char *name)
688690
{
@@ -702,6 +704,31 @@ load_type(LLVMModuleRef mod, const char *name)
702704
return typ;
703705
}
704706

707+
/* helper for llvm_create_types, returning a function's return type */
708+
static LLVMTypeRef
709+
load_return_type(LLVMModuleRef mod, const char *name)
710+
{
711+
LLVMValueRef value;
712+
LLVMTypeRef typ;
713+
714+
/* this'll return a *pointer* to the function */
715+
value = LLVMGetNamedFunction(mod, name);
716+
if (!value)
717+
elog(ERROR, "function %s is unknown", name);
718+
719+
/* get type of function pointer */
720+
typ = LLVMTypeOf(value);
721+
Assert(typ != NULL);
722+
/* dereference pointer */
723+
typ = LLVMGetElementType(typ);
724+
Assert(typ != NULL);
725+
/* and look at return type */
726+
typ = LLVMGetReturnType(typ);
727+
Assert(typ != NULL);
728+
729+
return typ;
730+
}
731+
705732
/*
706733
* Load required information, types, function signatures from llvmjit_types.c
707734
* and make them available in global variables.
@@ -740,6 +767,8 @@ llvm_create_types(void)
740767
llvm_layout = pstrdup(LLVMGetDataLayoutStr(mod));
741768

742769
TypeSizeT = load_type(mod, "TypeSizeT");
770+
TypeParamBool = load_return_type(mod, "FunctionReturningBool");
771+
TypeStorageBool = load_type(mod, "TypeStorageBool");
743772
TypePGFunction = load_type(mod, "TypePGFunction");
744773
StructExprContext = load_type(mod, "StructExprContext");
745774
StructExprEvalStep = load_type(mod, "StructExprEvalStep");

0 commit comments

Comments
 (0)