Class CodeGenerator

class CodeGenerator

Subclassed by ScalarCodeGenerator

Public Functions

CodeGenerator(Executor *executor)
CodeGenerator(CgenState *cgen_state, PlanState *plan_state)
std::vector<llvm::Value *> codegen(const Analyzer::Expr *expr, const bool fetch_columns, const CompilationOptions &co)
std::vector<llvm::Value *> codegenHoistedConstants(const std::vector<const Analyzer::Constant *> &constants, const EncodingType enc_type, const int dict_id)
llvm::Value *codegenCastBetweenIntTypes(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, bool upscale = true)
void codegenCastBetweenIntTypesOverflowChecks(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const int64_t scale)
llvm::Value *posArg(const Analyzer::Expr *expr) const
llvm::Value *toBool(llvm::Value *lv)
llvm::Value *castArrayPointer(llvm::Value *ptr, const SQLTypeInfo &elem_ti)

Public Static Functions

llvm::ConstantInt *codegenIntConst(const Analyzer::Constant *constant, CgenState *cgen_state)
std::unordered_set<llvm::Function *> markDeadRuntimeFuncs(llvm::Module &module, const std::vector<llvm::Function *> &roots, const std::vector<llvm::Function *> &leaves)
ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set<llvm::Function *> &live_funcs, const CompilationOptions &co)
std::string generatePTX(const std::string &cuda_llir, llvm::TargetMachine *nvptx_target_machine, llvm::LLVMContext &context)
std::unique_ptr<llvm::TargetMachine> initializeNVPTXBackend(const CudaMgr_Namespace::NvidiaDeviceArch arch)
bool alwaysCloneRuntimeFunction(const llvm::Function *func)
void linkModuleWithLibdevice(Executor *executor, llvm::Module &module, llvm::PassManagerBuilder &pass_manager_builder, const GPUTarget &gpu_target)
std::shared_ptr<GpuCompilationContext> generateNativeGPUCode(Executor *executor, llvm::Function *func, llvm::Function *wrapper_func, const std::unordered_set<llvm::Function *> &live_funcs, const bool is_gpu_smem_used, const CompilationOptions &co, const GPUTarget &gpu_target)
bool prioritizeQuals(const RelAlgExecutionUnit &ra_exe_unit, std::vector<Analyzer::Expr *> &primary_quals, std::vector<Analyzer::Expr *> &deferred_quals, const PlanState::HoistedFiltersSet &hoisted_quals)
ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)

Protected Functions

Executor *executor() const

Protected Attributes

CgenState *cgen_state_
PlanState *plan_state_

Private Functions

std::vector<llvm::Value *> codegen(const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const CompilationOptions &co)
std::vector<llvm::Value *> codegenColumn(const Analyzer::ColumnVar *col_var, const bool fetch_column, const CompilationOptions &co)
llvm::Value *codegenArith(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegenUMinus(const Analyzer::UOper *uoper, const CompilationOptions &co)
llvm::Value *codegenCmp(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegenCmp(const SQLOps optype, const SQLQualifier qualifier, std::vector<llvm::Value *> lhs_lvs, const SQLTypeInfo &lhs_ti, const Analyzer::Expr *rhs, const CompilationOptions &co)
llvm::Value *codegenIsNull(const Analyzer::UOper *uoper, const CompilationOptions &co)
llvm::Value *codegenIsNullNumber(llvm::Value *operand_lv, const SQLTypeInfo &ti)
llvm::Value *codegenLogical(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegenLogical(const Analyzer::UOper *uoper, const CompilationOptions &co)
llvm::Value *codegenCast(const Analyzer::UOper *uoper, const CompilationOptions &co)
llvm::Value *codegenCast(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const bool operand_is_const, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::InValues *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::InIntegerSet *expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegen(const Analyzer::CaseExpr *case_expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::ExtractExpr *extract_expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::DateaddExpr *dateadd_expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::DatediffExpr *datediff_expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::DatetruncExpr *datetrunc_expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::CharLengthExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::KeyForStringExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::SampleRatioExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::WidthBucketExpr *expr, const CompilationOptions &co)
llvm::Value *codegenConstantWidthBucketExpr(const Analyzer::WidthBucketExpr *expr, const CompilationOptions &co)
llvm::Value *codegenWidthBucketExpr(const Analyzer::WidthBucketExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::LowerExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::LikeExpr *expr, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::RegexpExpr *expr, const CompilationOptions &co)
llvm::Value *codegenUnnest(const Analyzer::UOper *uoper, const CompilationOptions &co)
llvm::Value *codegenArrayAt(const Analyzer::BinOper *array_at, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::CardinalityExpr *expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegenArrayExpr(const Analyzer::ArrayExpr *array_expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoColumnVar(const Analyzer::GeoColumnVar *geo_col_var, const bool fetch_columns, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoExpr(const Analyzer::GeoExpr *expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoConstant(const Analyzer::GeoConstant *geo_constant, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoOperator(const Analyzer::GeoOperator *geo_operator, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoUOper(const Analyzer::GeoUOper *geo_expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoBinOper(const Analyzer::GeoBinOper *geo_expr, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeosPredicateCall(const std::string &func, std::vector<llvm::Value *> argument_list, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeosConstructorCall(const std::string &func, std::vector<llvm::Value *> argument_list, llvm::Value *result_srid, const CompilationOptions &co)
std::vector<llvm::Value *> codegenGeoArgs(const std::vector<std::shared_ptr<Analyzer::Expr>> &geo_args, const CompilationOptions &co)
llvm::Value *codegenFunctionOper(const Analyzer::FunctionOper *function_oper, const CompilationOptions &co)
llvm::Value *codegenFunctionOperWithCustomTypeHandling(const Analyzer::FunctionOperWithCustomTypeHandling *function_oper, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegen(const Analyzer::UOper *u_oper, const CompilationOptions &co)
std::vector<llvm::Value *> codegenHoistedConstantsLoads(const SQLTypeInfo &type_info, const EncodingType enc_type, const int dict_id, const int16_t lit_off)
std::vector<llvm::Value *> codegenHoistedConstantsPlaceholders(const SQLTypeInfo &type_info, const EncodingType enc_type, const int16_t lit_off, const std::vector<llvm::Value *> &literal_loads)
std::vector<llvm::Value *> codegenColVar(const Analyzer::ColumnVar *col_var, const bool fetch_column, const bool update_query_plan, const CompilationOptions &co)
llvm::Value *codegenFixedLengthColVar(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg)
llvm::Value *codegenFixedLengthColVarInWindow(const Analyzer::ColumnVar *col_var, llvm::Value *col_byte_stream, llvm::Value *pos_arg)
llvm::Value *codegenWindowPosition(WindowFunctionContext *window_func_context, llvm::Value *pos_arg)
std::vector<llvm::Value *> codegenVariableLengthStringColVar(llvm::Value *col_byte_stream, llvm::Value *pos_arg)
llvm::Value *codegenRowId(const Analyzer::ColumnVar *col_var, const CompilationOptions &co)
llvm::Value *codgenAdjustFixedEncNull(llvm::Value *val, const SQLTypeInfo &col_ti)
std::vector<llvm::Value *> codegenOuterJoinNullPlaceholder(const Analyzer::ColumnVar *col_var, const bool fetch_column, const CompilationOptions &co)
llvm::Value *codegenIntArith(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const CompilationOptions &co)
llvm::Value *codegenFpArith(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv)
llvm::Value *codegenCastTimestampToDate(llvm::Value *ts_lv, const int dimen, const bool nullable)
llvm::Value *codegenCastBetweenTimestamps(llvm::Value *ts_lv, const SQLTypeInfo &operand_dimen, const SQLTypeInfo &target_dimen, const bool nullable)
llvm::Value *codegenCastFromString(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti, const bool operand_is_const, const CompilationOptions &co)
llvm::Value *codegenCastToFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
llvm::Value *codegenCastFromFp(llvm::Value *operand_lv, const SQLTypeInfo &operand_ti, const SQLTypeInfo &ti)
llvm::Value *codegenAdd(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &ti, const CompilationOptions &co)
llvm::Value *codegenSub(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &ti, const CompilationOptions &co)
void codegenSkipOverflowCheckForNull(llvm::Value *lhs_lv, llvm::Value *rhs_lv, llvm::BasicBlock *no_overflow_bb, const SQLTypeInfo &ti)
llvm::Value *codegenMul(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &ti, const CompilationOptions &co, bool downscale = true)
llvm::Value *codegenDiv(llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &ti, bool upscale = true)
llvm::Value *codegenDeciDiv(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegenMod(llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_typename, const std::string &null_check_suffix, const SQLTypeInfo &ti)
llvm::Value *codegenCase(const Analyzer::CaseExpr *case_expr, llvm::Type *case_llvm_type, const bool is_real_str, const CompilationOptions &co)
llvm::Value *codegenExtractHighPrecisionTimestamps(llvm::Value *ts_lv, const SQLTypeInfo &ti, const ExtractField &field)
llvm::Value *codegenDateTruncHighPrecisionTimestamps(llvm::Value *ts_lv, const SQLTypeInfo &ti, const DatetruncField &field)
llvm::Value *codegenCmpDecimalConst(const SQLOps optype, const SQLQualifier qualifier, const Analyzer::Expr *lhs, const SQLTypeInfo &lhs_ti, const Analyzer::Expr *rhs, const CompilationOptions &co)
llvm::Value *codegenOverlaps(const SQLOps optype, const SQLQualifier qualifier, const std::shared_ptr<Analyzer::Expr> lhs, const std::shared_ptr<Analyzer::Expr> rhs, const CompilationOptions &co)
llvm::Value *codegenStrCmp(const SQLOps optype, const SQLQualifier qualifier, const std::shared_ptr<Analyzer::Expr> lhs, const std::shared_ptr<Analyzer::Expr> rhs, const CompilationOptions &co)
llvm::Value *codegenQualifierCmp(const SQLOps optype, const SQLQualifier qualifier, std::vector<llvm::Value *> lhs_lvs, const Analyzer::Expr *rhs, const CompilationOptions &co)
llvm::Value *codegenLogicalShortCircuit(const Analyzer::BinOper *bin_oper, const CompilationOptions &co)
llvm::Value *codegenDictLike(const std::shared_ptr<Analyzer::Expr> arg, const Analyzer::Constant *pattern, const bool ilike, const bool is_simple, const char escape_char, const CompilationOptions &co)
llvm::Value *codegenDictStrCmp(const std::shared_ptr<Analyzer::Expr> lhs, const std::shared_ptr<Analyzer::Expr> rhs, const SQLOps compare_operator, const CompilationOptions &co)
llvm::Value *codegenDictRegexp(const std::shared_ptr<Analyzer::Expr> arg, const Analyzer::Constant *pattern, const char escape_char, const CompilationOptions &co)
llvm::Value *foundOuterJoinMatch(const size_t nesting_level) const
llvm::Value *resolveGroupedColumnReference(const Analyzer::ColumnVar *col_var)
llvm::Value *colByteStream(const Analyzer::ColumnVar *col_var, const bool fetch_column, const bool hoist_literals)
std::shared_ptr<const Analyzer::Expr> hashJoinLhs(const Analyzer::ColumnVar *rhs) const
std::shared_ptr<const Analyzer::ColumnVar> hashJoinLhsTuple(const Analyzer::ColumnVar *rhs, const Analyzer::BinOper *tautological_eq) const
std::unique_ptr<InValuesBitmap> createInValuesBitmap(const Analyzer::InValues *in_values, const CompilationOptions &co)
bool checkExpressionRanges(const Analyzer::UOper *uoper, int64_t min, int64_t max)
bool checkExpressionRanges(const Analyzer::BinOper *bin_oper, int64_t min, int64_t max)
std::tuple<CodeGenerator::ArgNullcheckBBs, llvm::Value *> beginArgsNullcheck(const Analyzer::FunctionOper *function_oper, const std::vector<llvm::Value *> &orig_arg_lvs)
llvm::Value *endArgsNullcheck(const ArgNullcheckBBs &bbs, llvm::Value *fn_ret_lv, llvm::Value *null_array_ptr, const Analyzer::FunctionOper *function_oper)
llvm::Value *codegenFunctionOperNullArg(const Analyzer::FunctionOper *function_oper, const std::vector<llvm::Value *> &orig_arg_lvs)
llvm::Value *codegenCompression(const SQLTypeInfo &type_info)
std::pair<llvm::Value *, llvm::Value *> codegenArrayBuff(llvm::Value *chunk, llvm::Value *row_pos, SQLTypes array_type, bool cast_and_extend)
void codegenBufferArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *buffer_buf, llvm::Value *buffer_size, llvm::Value *buffer_is_null, std::vector<llvm::Value *> &output_args)
llvm::StructType *createPointStructType(const std::string &udf_func_name, size_t param_num)
void codegenGeoPointArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *point_buf, llvm::Value *point_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector<llvm::Value *> &output_args)
llvm::StructType *createLineStringStructType(const std::string &udf_func_name, size_t param_num)
void codegenGeoLineStringArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *line_string_buf, llvm::Value *line_string_size, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector<llvm::Value *> &output_args)
llvm::StructType *createPolygonStructType(const std::string &udf_func_name, size_t param_num)
void codegenGeoPolygonArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *polygon_buf, llvm::Value *polygon_size, llvm::Value *ring_sizes_buf, llvm::Value *num_rings, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector<llvm::Value *> &output_args)
llvm::StructType *createMultiPolygonStructType(const std::string &udf_func_name, size_t param_num)
void codegenGeoMultiPolygonArgs(const std::string &udf_func_name, size_t param_num, llvm::Value *polygon_coords, llvm::Value *polygon_coords_size, llvm::Value *ring_sizes_buf, llvm::Value *ring_sizes, llvm::Value *polygon_bounds, llvm::Value *polygon_bounds_sizes, llvm::Value *compression, llvm::Value *input_srid, llvm::Value *output_srid, std::vector<llvm::Value *> &output_args)
std::vector<llvm::Value *> codegenFunctionOperCastArgs(const Analyzer::FunctionOper *function_oper, const ExtensionFunction *ext_func_sig, const std::vector<llvm::Value *> &orig_arg_lvs, const std::vector<size_t> &orig_arg_lvs_index, const std::unordered_map<llvm::Value *, llvm::Value *> &const_arr_size, const CompilationOptions &co)
llvm::Function *getArithWithOverflowIntrinsic(const Analyzer::BinOper *bin_oper, llvm::Type *type)
llvm::Value *codegenBinOpWithOverflowForCPU(const Analyzer::BinOper *bin_oper, llvm::Value *lhs_lv, llvm::Value *rhs_lv, const std::string &null_check_suffix, const SQLTypeInfo &ti)

Private Members

Executor *executor_

Friends

friend CodeGenerator::GroupByAndAggregate
struct ArgNullcheckBBs

Public Members

llvm::BasicBlock *args_null_bb
llvm::BasicBlock *args_notnull_bb
llvm::BasicBlock *orig_bb
struct ExecutorRequired : public runtime_error

Public Functions

ExecutorRequired()
struct GPUTarget

Public Members

llvm::TargetMachine *nvptx_target_machine
const CudaMgr_Namespace::CudaMgr *cuda_mgr
unsigned block_size
CgenState *cgen_state
bool row_func_not_inlined
struct NullCheckCodegen

Public Functions

NullCheckCodegen(CgenState *cgen_state, Executor *executor, llvm::Value *nullable_lv, const SQLTypeInfo &nullable_ti, const std::string &name = "")
llvm::Value *finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)

Public Members

CgenState *cgen_state = {nullptr}
std::string name
llvm::BasicBlock *nullcheck_bb = {nullptr}
llvm::PHINode *nullcheck_value = {nullptr}
std::unique_ptr<DiamondCodegen> null_check