!2606 Minor cleanup in MOT JIT code
Merge pull request !2606 from Vinoth Veeraraghavan/master
This commit is contained in:
@ -49,7 +49,6 @@
|
||||
#include "mm_global_api.h"
|
||||
#include "catalog_column_types.h"
|
||||
#include "mot_internal.h"
|
||||
#include "jit_llvm_query_codegen.h"
|
||||
|
||||
namespace JitExec {
|
||||
DECLARE_LOGGER(JitCommon, JitExec)
|
||||
@ -68,11 +67,6 @@ const char* JitRuntimeFaultToString(int faultCode)
|
||||
}
|
||||
}
|
||||
|
||||
void JitResetCompileState()
|
||||
{
|
||||
JitLlvmResetCompileState();
|
||||
}
|
||||
|
||||
const char* CommandToString(JitCommandType commandType)
|
||||
{
|
||||
switch (commandType) {
|
||||
|
||||
@ -92,9 +92,6 @@ inline bool IsJitRuntimeFaultCode(int faultCode)
|
||||
/** @brief Converts JIT generic fault code to string. */
|
||||
extern const char* JitRuntimeFaultToString(int faultCode);
|
||||
|
||||
/** @brief Reset compile state for LLVM (cleanup in case of error). */
|
||||
extern void JitResetCompileState();
|
||||
|
||||
// common helpers for code generation
|
||||
/** @brief Converts an LLVM command type to string form. */
|
||||
extern const char* CommandToString(JitCommandType commandType);
|
||||
|
||||
@ -869,9 +869,6 @@ extern MotJitContext* JitCodegenQuery(Query* query, const char* queryString, Jit
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
// reset compile state for robustness
|
||||
JitResetCompileState();
|
||||
|
||||
// pop currently parsed query
|
||||
u_sess->mot_cxt.jit_pg_query = prevQuery;
|
||||
|
||||
@ -1006,9 +1003,6 @@ extern MotJitContext* JitCodegenFunction(PLpgSQL_function* function, HeapTuple p
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
// reset compile state for robustness
|
||||
JitResetCompileState();
|
||||
|
||||
if (nsPushed) {
|
||||
PopJitSourceNamespace();
|
||||
}
|
||||
|
||||
@ -2446,16 +2446,6 @@ static MotJitContext* JitInvokeCodegen(JitLlvmCodeGenContext* ctx, Query* query,
|
||||
return jitContext;
|
||||
}
|
||||
|
||||
#define JIT_ASSERT_QUERY_CODEGEN_UTIL_VALID() \
|
||||
do { \
|
||||
MOT_ASSERT(JIT_IF_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_DO_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_FOR_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_SWITCH_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_TRY_CURRENT() == nullptr); \
|
||||
} while (0)
|
||||
|
||||
static bool InitCodeGenContextByPlan(
|
||||
JitLlvmCodeGenContext* ctx, GsCodeGen* codeGen, GsCodeGen::LlvmBuilder* builder, JitPlan* plan)
|
||||
{
|
||||
@ -2521,7 +2511,7 @@ static bool InitCodeGenContextByPlan(
|
||||
|
||||
MotJitContext* JitCodegenLlvmQuery(Query* query, const char* query_string, JitPlan* plan, JitCodegenStats& codegenStats)
|
||||
{
|
||||
JIT_ASSERT_QUERY_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
GsCodeGen* codeGen = SetupCodegenEnv();
|
||||
if (codeGen == nullptr) {
|
||||
return nullptr;
|
||||
@ -2596,7 +2586,9 @@ MotJitContext* JitCodegenLlvmQuery(Query* query, const char* query_string, JitPl
|
||||
"Got LLVM-jitted function %p after compile, for query: %s", jitContext->m_llvmFunction, query_string);
|
||||
}
|
||||
|
||||
JIT_ASSERT_QUERY_CODEGEN_UTIL_VALID();
|
||||
// reset compile state for robustness
|
||||
llvm_util::JitResetCompileState();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
return (MotJitContext*)jitContext;
|
||||
}
|
||||
|
||||
@ -2642,15 +2634,4 @@ extern int JitExecLlvmQuery(JitQueryContext* jitContext, ParamListInfo params, T
|
||||
MOT_LOG_TRACE("JitExecLlvmQuery returned %d/%u for query: %s", result, jitContext->m_rc, jitContext->m_queryString);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern void JitLlvmResetCompileState()
|
||||
{
|
||||
u_sess->mot_cxt.jit_llvm_if_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_loop_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_while_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_do_while_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_for_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_switch_case_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_try_catch_stack = nullptr;
|
||||
}
|
||||
} // namespace JitExec
|
||||
|
||||
@ -59,21 +59,6 @@ MotJitContext* JitCodegenLlvmQuery(Query* query, const char* queryString, JitPla
|
||||
*/
|
||||
extern int JitExecLlvmQuery(JitQueryContext* jitContext, ParamListInfo params, TupleTableSlot* slot,
|
||||
uint64_t* tuplesProcessed, int* scanEnded, int newScan);
|
||||
|
||||
/**
|
||||
* @brief Executed a previously LLVM-jitted stored procedure.
|
||||
* @param jitContext The context produced by a previous call to @ref QueryCodegen().
|
||||
* @param params The list of bound parameters passed to the query.
|
||||
* @param[out] slot The slot used for reporting select result.
|
||||
* @param[out] tuplesProcessed The variable used to report the number of processed tuples.
|
||||
* @param[out] scanEnded The variable used to report if a range scan ended.
|
||||
* @return Zero if succeeded, otherwise an error code.
|
||||
* @note This function may cause transaction abort.
|
||||
*/
|
||||
extern int JitExecLlvmFunction(JitFunctionContext* jitContext, ParamListInfo params, TupleTableSlot* slot,
|
||||
uint64_t* tuplesProcessed, int* scanEnded);
|
||||
|
||||
extern void JitLlvmResetCompileState();
|
||||
} // namespace JitExec
|
||||
|
||||
#endif /* JIT_LLVM_QUERY_CODEGEN_H */
|
||||
|
||||
@ -5338,20 +5338,10 @@ static bool InitLocalVariables(JitLlvmFunctionCodeGenContext* ctx)
|
||||
return true;
|
||||
}
|
||||
|
||||
#define JIT_ASSERT_SP_CODEGEN_UTIL_VALID() \
|
||||
do { \
|
||||
MOT_ASSERT(JIT_IF_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_DO_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_FOR_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_SWITCH_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_TRY_CURRENT() == nullptr); \
|
||||
} while (0)
|
||||
|
||||
extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTuple procTuple, Oid functionOid,
|
||||
ReturnSetInfo* returnSetInfo, JitPlan* plan, JitCodegenStats& codegenStats)
|
||||
{
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
bool procNameIsNull = false;
|
||||
bool procSrcIsNull = false;
|
||||
bool procIsStrictIsNull = false;
|
||||
@ -5361,7 +5351,7 @@ extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTup
|
||||
if (procNameIsNull || procSrcIsNull || procIsStrictIsNull) {
|
||||
MOT_LOG_TRACE("Failed to generate jitted code for stored procedure: catalog entry for stored procedure "
|
||||
"contains null attributes");
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -5377,7 +5367,7 @@ extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTup
|
||||
if (!functionSource) {
|
||||
MOT_REPORT_ERROR(
|
||||
MOT_ERROR_OOM, "Parse Stored Procedure", "Failed to allocate memory for stored procedure source code");
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
return nullptr;
|
||||
}
|
||||
bool isStrict = DatumGetBool(procIsStrictDatum);
|
||||
@ -5388,14 +5378,14 @@ extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTup
|
||||
// prepare compile context
|
||||
GsCodeGen* codeGen = SetupCodegenEnv();
|
||||
if (codeGen == nullptr) {
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
return nullptr;
|
||||
}
|
||||
GsCodeGen::LlvmBuilder builder(codeGen->context());
|
||||
volatile JitLlvmFunctionCodeGenContext cgCtx = {};
|
||||
if (!InitLlvmFunctionCodeGenContext(
|
||||
(JitLlvmFunctionCodeGenContext*)&cgCtx, codeGen, &builder, function, returnSetInfo)) {
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
FreeGsCodeGen(codeGen);
|
||||
return nullptr;
|
||||
}
|
||||
@ -5490,7 +5480,10 @@ extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTup
|
||||
// cleanup
|
||||
function->pre_parse_trig = preParseTrig;
|
||||
DestroyLlvmFunctionCodeGenContext((JitLlvmFunctionCodeGenContext*)ctx);
|
||||
JIT_ASSERT_SP_CODEGEN_UTIL_VALID();
|
||||
|
||||
// reset compile state for robustness
|
||||
llvm_util::JitResetCompileState();
|
||||
JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID();
|
||||
return (MotJitContext*)jitContext;
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,19 @@ struct JitPlan;
|
||||
*/
|
||||
extern MotJitContext* JitCodegenLlvmFunction(PLpgSQL_function* function, HeapTuple procTuple, Oid functionOid,
|
||||
ReturnSetInfo* returnSetInfo, JitPlan* plan, JitCodegenStats& codegenStats);
|
||||
|
||||
/**
|
||||
* @brief Executed a previously LLVM-jitted stored procedure.
|
||||
* @param jitContext The context produced by a previous call to @ref QueryCodegen().
|
||||
* @param params The list of bound parameters passed to the query.
|
||||
* @param[out] slot The slot used for reporting select result.
|
||||
* @param[out] tuplesProcessed The variable used to report the number of processed tuples.
|
||||
* @param[out] scanEnded The variable used to report if a range scan ended.
|
||||
* @return Zero if succeeded, otherwise an error code.
|
||||
* @note This function may cause transaction abort.
|
||||
*/
|
||||
extern int JitExecLlvmFunction(JitFunctionContext* jitContext, ParamListInfo params, TupleTableSlot* slot,
|
||||
uint64_t* tuplesProcessed, int* scanEnded);
|
||||
} // namespace JitExec
|
||||
|
||||
#endif /* JIT_LLVM_SP_CODEGEN_H */
|
||||
@ -87,6 +87,17 @@ extern void CleanupCompileFrames(LlvmCodeGenContext* ctx)
|
||||
}
|
||||
}
|
||||
|
||||
extern void JitResetCompileState()
|
||||
{
|
||||
u_sess->mot_cxt.jit_llvm_if_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_loop_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_while_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_do_while_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_for_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_switch_case_stack = nullptr;
|
||||
u_sess->mot_cxt.jit_llvm_try_catch_stack = nullptr;
|
||||
}
|
||||
|
||||
extern llvm::FunctionCallee DefineFunction(llvm::Module* module, llvm::Type* returnType, const char* name, ...)
|
||||
{
|
||||
va_list vargs;
|
||||
|
||||
@ -222,6 +222,9 @@ extern void CloseCompileFrame(LlvmCodeGenContext* ctx);
|
||||
|
||||
extern void CleanupCompileFrames(LlvmCodeGenContext* ctx);
|
||||
|
||||
/** @brief Reset compile state for LLVM (cleanup in case of error). */
|
||||
extern void JitResetCompileState();
|
||||
|
||||
/**
|
||||
* @brief Helper function for defining LLVM external function.
|
||||
* @param module The LLVM module into which the function declaration is to be added.
|
||||
@ -898,6 +901,16 @@ private:
|
||||
};
|
||||
} // namespace llvm_util
|
||||
|
||||
#define JIT_ASSERT_LLVM_CODEGEN_UTIL_VALID() \
|
||||
do { \
|
||||
MOT_ASSERT(JIT_IF_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_DO_WHILE_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_FOR_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_SWITCH_CURRENT() == nullptr); \
|
||||
MOT_ASSERT(JIT_TRY_CURRENT() == nullptr); \
|
||||
} while (0)
|
||||
|
||||
/**************************************
|
||||
* Return Statement
|
||||
**************************************/
|
||||
|
||||
@ -1081,9 +1081,6 @@ static JitCodegenState RegenerateJitFunctionSource(JitSource* jitSource)
|
||||
}
|
||||
PG_END_TRY();
|
||||
|
||||
// reset compile state for robustness
|
||||
JitResetCompileState();
|
||||
|
||||
if (plan != nullptr) {
|
||||
JitDestroyPlan((JitPlan*)plan);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user