32 #define LL_CONTEXT executor->cgen_state_->context_
33 #define LL_BUILDER executor->cgen_state_->ir_builder_
34 #define LL_BOOL(v) executor->ll_bool(v)
35 #define LL_INT(v) executor->cgen_state_->llInt(v)
36 #define LL_FP(v) executor->cgen_state_->llFp(v)
37 #define ROW_FUNC executor->cgen_state_->row_func_
49 if (is_varlen_projection) {
51 CHECK(chosen_type.is_geometry());
52 return {
"agg_id_varlen"};
55 if (chosen_type.is_geometry()) {
56 return std::vector<std::string>(2 * chosen_type.get_physical_coord_cols(),
59 if (chosen_type.is_varlen()) {
62 return {
"agg_id",
"agg_id"};
68 return {
"agg_sum",
"agg_count"};
70 return {target_info.
is_distinct ?
"agg_count_distinct" :
"agg_count"};
72 return {
"agg_count_if"};
80 return {
"agg_sum_if"};
82 return {
"agg_approximate_count_distinct"};
84 return {
"agg_approx_quantile"};
86 return {
"checked_single_agg_id"};
90 return {
"agg_mode_func"};
105 return target_info.
is_agg && shared::is_any<kCOUNT>(target_info.
agg_kind) &&
122 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx_in,
123 const std::vector<llvm::Value*>& agg_out_vec,
124 llvm::Value* output_buffer_byte_stream,
125 llvm::Value* out_row_idx,
126 llvm::Value* varlen_output_buffer,
129 CHECK(group_by_and_agg);
133 auto agg_out_ptr_w_idx = agg_out_ptr_w_idx_in;
142 ? std::vector<llvm::Value*>{executor->codegenWindowFunction(
target_idx, co)}
144 const auto window_row_ptr = window_func
146 window_func, query_mem_desc, co, diamond_codegen)
148 if (window_row_ptr) {
150 std::make_tuple(window_row_ptr, std::get<1>(agg_out_ptr_w_idx_in));
152 out_row_idx = window_row_ptr;
156 llvm::Value* str_target_lv{
nullptr};
161 str_target_lv = target_lvs.front();
162 target_lvs.erase(target_lvs.begin());
168 if (target_lvs.size() < agg_fn_names.size()) {
169 CHECK_EQ(target_lvs.size(), agg_fn_names.size() / 2);
170 std::vector<llvm::Value*> new_target_lvs;
171 new_target_lvs.reserve(agg_fn_names.size());
172 for (
const auto& target_lv : target_lvs) {
173 new_target_lvs.push_back(target_lv);
174 new_target_lvs.push_back(target_lv);
176 target_lvs = new_target_lvs;
179 if (target_lvs.size() < agg_fn_names.size()) {
180 CHECK_EQ(
size_t(1), target_lvs.size());
181 CHECK_EQ(
size_t(2), agg_fn_names.size());
182 for (
size_t i = 1; i < agg_fn_names.size(); ++i) {
183 target_lvs.push_back(target_lvs.front());
190 CHECK_EQ(agg_fn_names.size(), target_lvs.size());
193 CHECK(str_target_lv || (agg_fn_names.size() == target_lvs.size()));
194 CHECK(target_lvs.size() == 1 || target_lvs.size() == 2);
205 (!arg_expr || arg_expr->get_type_info().get_notnull())) {
206 CHECK_EQ(
size_t(1), agg_fn_names.size());
208 llvm::Value* agg_col_ptr{
nullptr};
212 CHECK_EQ(
size_t(0), col_off % chosen_bytes);
213 col_off /= chosen_bytes;
214 CHECK(std::get<1>(agg_out_ptr_w_idx));
218 std::get<0>(agg_out_ptr_w_idx),
221 bit_cast->getType()->getScalarType()->getPointerElementType(),
226 CHECK_EQ(
size_t(0), col_off % chosen_bytes);
227 col_off /= chosen_bytes;
229 std::get<0>(agg_out_ptr_w_idx),
232 bit_cast->getType()->getScalarType()->getPointerElementType(),
238 if (chosen_bytes !=
sizeof(int32_t)) {
241 const auto acc_i64 =
LL_BUILDER.CreateBitCast(
242 is_group_by ? agg_col_ptr : agg_out_vec[slot_index],
246 "agg_count_shared", std::vector<llvm::Value*>{acc_i64,
LL_INT(int64_t(1))});
248 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
251 #
if LLVM_VERSION_MAJOR > 12
254 llvm::AtomicOrdering::Monotonic);
258 is_group_by ? agg_col_ptr : agg_out_vec[slot_index],
262 acc_i32, llvm::Type::getInt32PtrTy(
LL_CONTEXT, 3));
264 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
267 #
if LLVM_VERSION_MAJOR > 12
270 llvm::AtomicOrdering::Monotonic);
273 const auto acc_i32 = (
is_group_by ? agg_col_ptr : agg_out_vec[slot_index]);
276 const auto shared_acc_i32 =
LL_BUILDER.CreatePointerCast(
277 acc_i32, llvm::Type::getInt32PtrTy(
LL_CONTEXT, 3));
278 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
281 #
if LLVM_VERSION_MAJOR > 12
284 llvm::AtomicOrdering::Monotonic);
286 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
289 #
if LLVM_VERSION_MAJOR > 12
292 llvm::AtomicOrdering::Monotonic);
305 output_buffer_byte_stream,
307 varlen_output_buffer,
316 const std::vector<llvm::Value*>& target_lvs,
317 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
318 const std::vector<llvm::Value*>& agg_out_vec,
319 llvm::Value* output_buffer_byte_stream,
320 llvm::Value* out_row_idx,
321 llvm::Value* varlen_output_buffer,
322 int32_t slot_index)
const {
324 size_t target_lv_idx = 0;
325 const bool lazy_fetched{executor->plan_state_->isLazyFetchColumn(
target_expr)};
333 for (
const auto& agg_base_name : agg_fn_names) {
339 const auto& elem_ti = arg_expr->get_type_info().get_elem_type();
343 CHECK_EQ(
size_t(0), col_off_in_bytes %
sizeof(int64_t));
344 col_off /=
sizeof(int64_t);
346 executor->cgen_state_->emitExternalCall(
352 ->getPointerElementType(),
353 std::get<0>(agg_out_ptr_w_idx),
355 : agg_out_vec[slot_index],
356 target_lvs[target_lv_idx],
357 code_generator.
posArg(arg_expr),
359 ?
static_cast<llvm::Value*
>(executor->cgen_state_->inlineFpNull(elem_ti))
360 : static_cast<llvm::Value*>(
361 executor->cgen_state_->inlineIntNull(elem_ti))});
367 llvm::Value* agg_col_ptr{
nullptr};
368 const auto chosen_bytes =
371 const auto& arg_type =
372 ((arg_expr && arg_expr->get_type_info().get_type() !=
kNULLT) &&
376 const bool is_fp_arg =
377 !lazy_fetched && arg_type.
get_type() !=
kNULLT && arg_type.is_fp();
387 agg_col_ptr->setName(
"agg_col_ptr");
394 CHECK_LT(target_lv_idx, target_lvs.size());
395 CHECK(varlen_output_buffer);
396 auto target_lv = target_lvs[target_lv_idx];
398 std::string agg_fname_suffix =
"";
401 agg_fname_suffix +=
"_shared";
406 auto& builder = executor->cgen_state_->ir_builder_;
407 auto orig_bb = builder.GetInsertBlock();
408 auto target_ptr_type = llvm::dyn_cast<llvm::PointerType>(target_lv->getType());
409 CHECK(target_ptr_type) <<
"Varlen projections expect a pointer input.";
411 builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
413 llvm::ConstantPointerNull::get(llvm::PointerType::get(
414 target_ptr_type->getPointerElementType(), 0)));
415 llvm::BasicBlock* true_bb{
nullptr};
418 is_nullptr, executor,
false,
"varlen_null_check",
nullptr,
false);
422 builder.SetInsertPoint(nullcheck_diamond.
cond_false_);
423 auto arr_ptr_lv = executor->cgen_state_->ir_builder_.CreateBitCast(
425 llvm::PointerType::get(
get_int_type(8, executor->cgen_state_->context_), 0));
426 const int64_t chosen_bytes =
429 const auto output_buffer_slot =
LL_BUILDER.CreateZExt(
430 LL_BUILDER.CreateLoad(arg->getType()->getPointerElementType(), arg),
433 CHECK(varlen_buffer_row_sz);
434 const auto output_buffer_slot_bytes =
LL_BUILDER.CreateAdd(
436 executor->cgen_state_->llInt(
437 static_cast<int64_t>(*varlen_buffer_row_sz))),
438 executor->cgen_state_->llInt(static_cast<int64_t>(
441 std::vector<llvm::Value*> varlen_agg_args{
442 executor->castToIntPtrTyIn(varlen_output_buffer, 8),
443 output_buffer_slot_bytes,
445 executor->cgen_state_->llInt(chosen_bytes)};
446 auto varlen_offset_ptr =
447 group_by_and_agg->
emitCall(agg_base_name + agg_fname_suffix, varlen_agg_args);
450 auto varlen_offset_int =
LL_BUILDER.CreatePtrToInt(
451 varlen_offset_ptr, llvm::Type::getInt64Ty(
LL_CONTEXT));
452 builder.CreateBr(nullcheck_diamond.
cond_true_);
455 builder.SetInsertPoint(nullcheck_diamond.
cond_true_);
457 builder.CreatePHI(llvm::Type::getInt64Ty(executor->cgen_state_->context_), 2);
458 output_phi->addIncoming(varlen_offset_int, nullcheck_diamond.
cond_false_);
459 output_phi->addIncoming(executor->cgen_state_->llInt(static_cast<int64_t>(0)),
462 std::vector<llvm::Value*> agg_args{agg_col_ptr, output_phi};
463 group_by_and_agg->
emitCall(
"agg_id" + agg_fname_suffix, agg_args);
466 builder.SetInsertPoint(true_bb);
476 const auto agg_chosen_bytes =
477 float_argument_input && !is_count_in_avg ?
sizeof(float) : chosen_bytes;
478 if (float_argument_input) {
479 CHECK_GE(chosen_bytes,
sizeof(
float));
482 auto target_lv = target_lvs[target_lv_idx];
486 if (!needs_unnest_double_patch) {
489 }
else if (is_fp_arg) {
492 if (!dynamic_cast<const Analyzer::AggExpr*>(
target_expr) || arg_expr) {
494 executor->cgen_state_->castToTypeIn(target_lv, (agg_chosen_bytes << 3));
499 llvm::Value* str_target_lv{
nullptr};
502 str_target_lv = target_lvs.front();
504 std::vector<llvm::Value*> agg_args{
505 executor->castToIntPtrTyIn((
is_group_by ? agg_col_ptr : agg_out_vec[slot_index]),
506 (agg_chosen_bytes << 3)),
507 (is_simple_count_target && !arg_expr)
508 ? (agg_chosen_bytes ==
sizeof(int32_t) ?
LL_INT(int32_t(0))
510 : (is_simple_count_target && arg_expr && str_target_lv ? str_target_lv
513 if (is_simple_count_target && arg_expr && str_target_lv) {
515 agg_chosen_bytes ==
sizeof(int32_t) ?
LL_INT(int32_t(0)) :
LL_INT(int64_t(0));
518 std::string agg_fname{agg_base_name};
521 if (agg_chosen_bytes ==
sizeof(
float)) {
523 agg_fname +=
"_float";
525 CHECK_EQ(agg_chosen_bytes,
sizeof(
double));
526 agg_fname +=
"_double";
529 }
else if (agg_chosen_bytes ==
sizeof(int32_t)) {
530 agg_fname +=
"_int32";
531 }
else if (agg_chosen_bytes ==
sizeof(int16_t) &&
533 agg_fname +=
"_int16";
534 }
else if (agg_chosen_bytes ==
sizeof(int8_t) && query_mem_desc.
didOutputColumnar()) {
535 agg_fname +=
"_int8";
539 CHECK_EQ(agg_chosen_bytes,
sizeof(int64_t));
540 CHECK(!chosen_type.is_fp());
544 CHECK_EQ(agg_chosen_bytes,
sizeof(int64_t));
552 if (need_skip_null && !arg_ti.is_geometry()) {
553 agg_fname +=
"_skip_val";
557 (need_skip_null && !arg_ti.is_geometry())) {
558 llvm::Value* null_in_lv{
nullptr};
559 if (arg_ti.is_fp()) {
560 null_in_lv = executor->cgen_state_->inlineFpNull(arg_ti);
562 null_in_lv = executor->cgen_state_->inlineIntNull(
569 executor->cgen_state_->castToTypeIn(null_in_lv, (agg_chosen_bytes << 3));
570 agg_args.push_back(null_lv);
575 code_generator.
codegen(agg_expr->get_arg1().get(),
true, co).front();
576 auto cond_lv = executor->codegenConditionalAggregateCondValSelector(
578 agg_args.push_back(cond_lv);
583 agg_fname +=
"_shared";
584 if (needs_unnest_double_patch) {
588 auto agg_fname_call_ret_lv = group_by_and_agg->
emitCall(agg_fname, agg_args);
590 if (agg_fname.find(
"checked") != std::string::npos) {
597 if (window_func && !window_func->hasFraming() &&
599 const auto window_func_context =
601 const auto pending_outputs =
602 LL_INT(window_func_context->aggregateStatePendingOutputs());
603 executor->cgen_state_->emitExternalCall(
"add_window_pending_output",
605 {agg_args.front(), pending_outputs});
606 const auto& window_func_ti = window_func->get_type_info();
607 std::string apply_window_pending_outputs_name =
"apply_window_pending_outputs";
608 switch (window_func_ti.get_type()) {
610 apply_window_pending_outputs_name +=
"_float";
612 apply_window_pending_outputs_name +=
"_columnar";
617 apply_window_pending_outputs_name +=
"_double";
621 apply_window_pending_outputs_name +=
"_int";
623 apply_window_pending_outputs_name +=
626 apply_window_pending_outputs_name +=
"64";
631 const auto partition_end =
632 LL_INT(reinterpret_cast<int64_t>(window_func_context->partitionEnd()));
633 executor->cgen_state_->emitExternalCall(apply_window_pending_outputs_name,
638 code_generator.
posArg(
nullptr)});
647 const Executor* executor,
652 CHECK(!dynamic_cast<const Analyzer::AggExpr*>(target_expr));
653 ++slot_index_counter;
654 ++target_index_counter;
657 if (dynamic_cast<const Analyzer::UOper*>(target_expr) &&
658 static_cast<const Analyzer::UOper*>(target_expr)->get_optype() ==
kUNNEST) {
659 throw std::runtime_error(
"UNNEST not supported in the projection list yet.");
661 if ((executor->plan_state_->isLazyFetchColumn(target_expr) || !
is_group_by) &&
670 executor->plan_state_->isLazyFetchColumn(target_expr)) {
680 auto arg_expr =
agg_arg(target_expr);
687 !arg_expr->get_type_info().is_varlen()) {
700 sample_exprs_to_codegen.emplace_back(target_expr,
703 target_index_counter++,
706 target_exprs_to_codegen.emplace_back(target_expr,
709 target_index_counter++,
715 slot_index_counter += agg_fn_names.size();
741 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
742 const std::vector<llvm::Value*>& agg_out_vec,
743 llvm::Value* output_buffer_byte_stream,
744 llvm::Value* out_row_idx,
745 llvm::Value* varlen_output_buffer,
747 CHECK(group_by_and_agg);
751 for (
const auto& target_expr_codegen : target_exprs_to_codegen) {
752 target_expr_codegen.codegen(group_by_and_agg,
759 output_buffer_byte_stream,
761 varlen_output_buffer,
764 if (!sample_exprs_to_codegen.empty()) {
765 codegenSampleExpressions(group_by_and_agg,
771 output_buffer_byte_stream,
782 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
783 const std::vector<llvm::Value*>& agg_out_vec,
784 llvm::Value* output_buffer_byte_stream,
785 llvm::Value* out_row_idx,
788 CHECK(!sample_exprs_to_codegen.empty());
790 if (sample_exprs_to_codegen.size() == 1 &&
791 !sample_exprs_to_codegen.front().target_info.sql_type.is_varlen()) {
792 codegenSingleSlotSampleExpression(group_by_and_agg,
798 output_buffer_byte_stream,
802 codegenMultiSlotSampleExpressions(group_by_and_agg,
808 output_buffer_byte_stream,
819 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
820 const std::vector<llvm::Value*>& agg_out_vec,
821 llvm::Value* output_buffer_byte_stream,
822 llvm::Value* out_row_idx,
825 CHECK_EQ(
size_t(1), sample_exprs_to_codegen.size());
826 CHECK(!sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
829 sample_exprs_to_codegen.front().codegen(group_by_and_agg,
836 output_buffer_byte_stream,
847 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
848 const std::vector<llvm::Value*>& agg_out_vec,
849 llvm::Value* output_buffer_byte_stream,
850 llvm::Value* out_row_idx,
853 CHECK(sample_exprs_to_codegen.size() > 1 ||
854 sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
856 const auto& first_sample_expr = sample_exprs_to_codegen.front();
857 auto target_lvs = group_by_and_agg->
codegenAggArg(first_sample_expr.target_expr, co);
858 CHECK_GE(target_lvs.size(), size_t(1));
860 const auto init_val =
863 llvm::Value* agg_col_ptr{
nullptr};
865 const auto agg_column_size_bytes =
867 !first_sample_expr.target_info.sql_type.is_varlen()
868 ? first_sample_expr.target_info.sql_type.get_size()
874 agg_column_size_bytes,
875 first_sample_expr.base_slot_index,
876 first_sample_expr.target_idx);
878 CHECK_LT(static_cast<size_t>(first_sample_expr.base_slot_index), agg_out_vec.size());
880 executor->castToIntPtrTyIn(agg_out_vec[first_sample_expr.base_slot_index], 64);
884 codegenSlotEmptyKey(agg_col_ptr, target_lvs, executor, query_mem_desc, init_val);
887 sample_cas_lv, executor,
false,
"sample_valcheck", &diamond_codegen,
false);
889 for (
const auto& target_expr_codegen : sample_exprs_to_codegen) {
890 target_expr_codegen.codegen(group_by_and_agg,
897 output_buffer_byte_stream,
906 llvm::Value* agg_col_ptr,
907 std::vector<llvm::Value*>& target_lvs,
910 const int64_t init_val)
const {
912 const auto& first_sample_expr = sample_exprs_to_codegen.front();
913 const auto first_sample_slot_bytes =
914 first_sample_expr.target_info.sql_type.is_varlen()
916 : first_sample_expr.target_info.sql_type.get_size();
917 llvm::Value* target_lv_casted{
nullptr};
919 if (first_sample_expr.target_info.sql_type.is_varlen()) {
922 }
else if (first_sample_expr.target_info.sql_type.is_fp()) {
926 target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
928 first_sample_slot_bytes ==
sizeof(float) ? llvm::Type::getInt32Ty(
LL_CONTEXT)
931 target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
932 target_lvs.front(), llvm::Type::getInt64Ty(
LL_CONTEXT));
934 }
else if (first_sample_slot_bytes !=
sizeof(int64_t) &&
937 executor->cgen_state_->ir_builder_.CreateCast(llvm::Instruction::CastOps::SExt,
941 target_lv_casted = target_lvs.front();
944 std::string slot_empty_cas_func_name(
"slotEmptyKeyCAS");
945 llvm::Value* init_val_lv{
LL_INT(init_val)};
947 !first_sample_expr.target_info.sql_type.is_varlen()) {
949 switch (first_sample_slot_bytes) {
951 slot_empty_cas_func_name +=
"_int8";
954 slot_empty_cas_func_name +=
"_int16";
957 slot_empty_cas_func_name +=
"_int32";
962 UNREACHABLE() <<
"Invalid slot size for slotEmptyKeyCAS function.";
965 if (first_sample_slot_bytes !=
sizeof(int64_t)) {
966 init_val_lv = llvm::ConstantInt::get(
971 auto sample_cas_lv = executor->cgen_state_->emitExternalCall(
972 slot_empty_cas_func_name,
973 llvm::Type::getInt1Ty(executor->cgen_state_->context_),
974 {agg_col_ptr, target_lv_casted, init_val_lv});
975 return sample_cas_lv;
size_t varlenOutputRowSizeToSlot(const size_t slot_idx) const
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
bool target_has_geo(const TargetInfo &target_info)
bool constrained_not_null(const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
llvm::BasicBlock * cond_false_
llvm::Value * codegenAggColumnPtr(llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const QueryMemoryDescriptor &query_mem_desc, const size_t chosen_bytes, const size_t agg_out_off, const size_t target_idx)
: returns the pointer to where the aggregation should be stored.
std::vector< std::string > agg_fn_base_names(const TargetInfo &target_info, const bool is_varlen_projection)
bool isLogicalSizedColumnsAllowed() const
void codegenMode(const size_t target_idx, const Analyzer::Expr *target_expr, std::vector< llvm::Value * > &agg_args, const QueryMemoryDescriptor &query_mem_desc, const ExecutorDeviceType device_type)
void codegen(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, DiamondCodegen &diamond_codegen, DiamondCodegen *sample_cfg=nullptr) const
void codegenMultiSlotSampleExpressions(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const
llvm::Value * posArg(const Analyzer::Expr *) const
bool is_agg_domain_range_equivalent(const SQLAgg agg_kind)
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value * > &args)
int64_t get_agg_initial_val(const SQLAgg agg, const SQLTypeInfo &ti, const bool enable_compaction, const unsigned min_byte_width_to_compact)
void codegenApproxQuantile(const size_t target_idx, const Analyzer::Expr *target_expr, std::vector< llvm::Value * > &agg_args, const QueryMemoryDescriptor &query_mem_desc, const ExecutorDeviceType device_type)
void checkErrorCode(llvm::Value *retCode)
bool takes_float_argument(const TargetInfo &target_info)
#define LLVM_ALIGN(alignment)
HOST DEVICE SQLTypes get_type() const
bool isSharedMemoryUsed() const
bool needsUnnestDoublePatch(llvm::Value const *val_ptr, const std::string &agg_base_name, const bool threads_share_memory, const CompilationOptions &co) const
llvm::BasicBlock * cond_true_
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
static WindowFunctionContext * getActiveWindowFunctionContext(Executor *executor)
TargetInfo get_target_info(const Analyzer::Expr *target_expr, const bool bigint_count)
std::string patch_agg_fname(const std::string &agg_name)
Helpers for codegen of target expressions.
size_t getColOnlyOffInBytes(const size_t col_idx) const
const SQLTypeInfo get_compact_type(const TargetInfo &target)
bool is_varlen_projection(const Analyzer::Expr *target_expr, const SQLTypeInfo &ti)
size_t getCompactByteWidth() const
llvm::Value * get_arg_by_name(llvm::Function *func, const std::string &name)
void operator()(const Analyzer::Expr *target_expr, const Executor *executor, QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co)
llvm::Value * convertNullIfAny(const SQLTypeInfo &arg_type, const TargetInfo &agg_info, llvm::Value *target)
void codegenSampleExpressions(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const
void codegen(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const GpuSharedMemoryContext &gpu_smem_context, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, DiamondCodegen &diamond_codegen) const
bool is_distinct_target(const TargetInfo &target_info)
void codegenCountDistinct(const size_t target_idx, const Analyzer::Expr *target_expr, std::vector< llvm::Value * > &agg_args, const QueryMemoryDescriptor &, const ExecutorDeviceType)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
QueryDescriptionType getQueryDescriptionType() const
ExecutorDeviceType device_type
std::optional< size_t > varlenOutputBufferElemSize() const
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
bool window_function_is_aggregate(const SqlWindowFunctionKind kind)
llvm::Value * codegenSlotEmptyKey(llvm::Value *agg_col_ptr, std::vector< llvm::Value * > &target_lvs, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const int64_t init_val) const
HOST DEVICE EncodingType get_compression() const
const Analyzer::Expr * target_expr
std::vector< llvm::Value * > codegenAggArg(const Analyzer::Expr *target_expr, const CompilationOptions &co)
llvm::Value * codegenWindowRowPointer(const Analyzer::WindowFunction *window_func, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, DiamondCodegen &diamond_codegen)
bool window_function_requires_peer_handling(const Analyzer::WindowFunction *window_func)
bool is_simple_count(const TargetInfo &target_info)
bool didOutputColumnar() const
bool threadsShareMemory() const
static void resetWindowFunctionContext(Executor *executor)
void setPaddedSlotWidthBytes(const size_t slot_idx, const int8_t bytes)
int64_t get_initial_agg_val(const TargetInfo &target_info, const QueryMemoryDescriptor &query_mem_desc)
std::string numeric_type_name(const SQLTypeInfo &ti)
const int8_t getLogicalSlotWidthBytes(const size_t slot_idx) const
int get_physical_coord_cols() const
size_t getColOffInBytes(const size_t col_idx) const
void codegenAggregate(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::vector< llvm::Value * > &target_lvs, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, llvm::Value *varlen_output_buffer, int32_t slot_index) const
bool is_columnar_projection(const QueryMemoryDescriptor &query_mem_desc)
void codegenSingleSlotSampleExpression(GroupByAndAggregate *group_by_and_agg, Executor *executor, const QueryMemoryDescriptor &query_mem_desc, const CompilationOptions &co, const std::tuple< llvm::Value *, llvm::Value * > &agg_out_ptr_w_idx, const std::vector< llvm::Value * > &agg_out_vec, llvm::Value *output_buffer_byte_stream, llvm::Value *out_row_idx, DiamondCodegen &diamond_codegen) const