Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* llvmjit_types.c
|
|
|
|
* List of types needed by JIT emitting code.
|
|
|
|
*
|
|
|
|
* JIT emitting code often needs to access struct elements, create functions
|
|
|
|
* with the correct signature etc. To allow synchronizing these types with a
|
|
|
|
* low chance of definitions getting out of sync, this file lists types and
|
|
|
|
* functions that directly need to be accessed from LLVM.
|
|
|
|
*
|
|
|
|
* When LlVM is first used in a backend, a bitcode version of this file, will
|
|
|
|
* be loaded. The needed types and signatures will be stored into Struct*,
|
|
|
|
* Type*, Func* variables.
|
|
|
|
*
|
|
|
|
* NB: This file will not be linked into the server, it's just converted to
|
|
|
|
* bitcode.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016-2018, PostgreSQL Global Development Group
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/lib/llvmjit_types.c
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2018-02-05 18:09:28 +01:00
|
|
|
#include "access/htup.h"
|
|
|
|
#include "access/htup_details.h"
|
|
|
|
#include "access/tupdesc.h"
|
|
|
|
#include "catalog/pg_attribute.h"
|
|
|
|
#include "executor/execExpr.h"
|
|
|
|
#include "executor/nodeAgg.h"
|
|
|
|
#include "executor/tuptable.h"
|
Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
#include "fmgr.h"
|
2018-02-05 18:09:28 +01:00
|
|
|
#include "nodes/execnodes.h"
|
|
|
|
#include "nodes/memnodes.h"
|
|
|
|
#include "utils/expandeddatum.h"
|
|
|
|
#include "utils/palloc.h"
|
|
|
|
|
Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List of types needed for JITing. These have to be non-static, otherwise
|
|
|
|
* clang/LLVM will omit them. As this file will never be linked into
|
|
|
|
* anything, that's harmless.
|
|
|
|
*/
|
2018-02-05 18:09:28 +01:00
|
|
|
PGFunction TypePGFunction;
|
2018-03-23 06:15:51 +01:00
|
|
|
size_t TypeSizeT;
|
|
|
|
bool TypeStorageBool;
|
2018-02-05 18:09:28 +01:00
|
|
|
|
|
|
|
AggState StructAggState;
|
|
|
|
AggStatePerGroupData StructAggStatePerGroupData;
|
|
|
|
AggStatePerTransData StructAggStatePerTransData;
|
|
|
|
ExprContext StructExprContext;
|
|
|
|
ExprEvalStep StructExprEvalStep;
|
|
|
|
ExprState StructExprState;
|
|
|
|
FunctionCallInfoData StructFunctionCallInfoData;
|
|
|
|
HeapTupleData StructHeapTupleData;
|
|
|
|
MemoryContextData StructMemoryContextData;
|
|
|
|
TupleTableSlot StructTupleTableSlot;
|
|
|
|
struct tupleDesc StructtupleDesc;
|
Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To determine which attributes functions need to have (depends e.g. on
|
|
|
|
* compiler version and settings) to be compatible for inlining, we simply
|
|
|
|
* copy the attributes of this function.
|
|
|
|
*/
|
|
|
|
extern Datum AttributeTemplate(PG_FUNCTION_ARGS);
|
|
|
|
Datum
|
|
|
|
AttributeTemplate(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
PG_RETURN_NULL();
|
|
|
|
}
|
|
|
|
|
2018-03-23 06:15:51 +01:00
|
|
|
/*
|
|
|
|
* Clang represents stdbool.h style booleans that are returned by functions
|
|
|
|
* differently (as i1) than stored ones (as i8). Therefore we do not just need
|
|
|
|
* TypeBool (above), but also a way to determine the width of a returned
|
|
|
|
* integer. This allows us to keep compatible with non-stdbool using
|
|
|
|
* architectures.
|
|
|
|
*/
|
|
|
|
extern bool FunctionReturningBool(void);
|
|
|
|
bool
|
|
|
|
FunctionReturningBool(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To force signatures of functions used during JITing to be present,
|
|
|
|
* reference the functions required. This again has to be non-static, to avoid
|
|
|
|
* being removed as unnecessary.
|
|
|
|
*/
|
|
|
|
void *referenced_functions[] =
|
|
|
|
{
|
2018-02-05 18:09:28 +01:00
|
|
|
strlen,
|
2018-03-26 21:57:19 +02:00
|
|
|
varsize_any,
|
2018-02-05 18:09:28 +01:00
|
|
|
slot_getsomeattrs,
|
|
|
|
heap_getsysattr,
|
|
|
|
MakeExpandedObjectReadOnlyInternal,
|
|
|
|
ExecEvalArrayRefSubscript,
|
|
|
|
ExecAggTransReparent,
|
|
|
|
ExecAggInitGroup
|
Support for optimizing and emitting code in LLVM JIT provider.
This commit introduces the ability to actually generate code using
LLVM. In particular, this adds:
- Ability to emit code both in heavily optimized and largely
unoptimized fashion
- Batching facility to allow functions to be defined in small
increments, but optimized and emitted in executable form in larger
batches (for performance and memory efficiency)
- Type and function declaration synchronization between runtime
generated code and normal postgres code. This is critical to be able
to access struct fields etc.
- Developer oriented jit_dump_bitcode GUC, for inspecting / debugging
the generated code.
- per JitContext statistics of number of functions, time spent
generating code, optimizing, and emitting it. This will later be
employed for EXPLAIN support.
This commit doesn't yet contain any code actually generating
functions. That'll follow in later commits.
Documentation for GUCs added, and for JIT in general, will be added in
later commits.
Author: Andres Freund, with contributions by Pierre Ducroquet
Testing-By: Thomas Munro, Peter Eisentraut
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de
2018-03-22 19:05:22 +01:00
|
|
|
};
|