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);
132 auto agg_out_ptr_w_idx = agg_out_ptr_w_idx_in;
141 ? std::vector<llvm::Value*>{executor->codegenWindowFunction(
target_idx, co)}
143 const auto window_row_ptr = window_func
145 window_func, query_mem_desc, co, diamond_codegen)
147 if (window_row_ptr) {
149 std::make_tuple(window_row_ptr, std::get<1>(agg_out_ptr_w_idx_in));
151 out_row_idx = window_row_ptr;
155 llvm::Value* str_target_lv{
nullptr};
160 str_target_lv = target_lvs.front();
161 target_lvs.erase(target_lvs.begin());
167 if (target_lvs.size() < agg_fn_names.size()) {
168 if (!uses_flatbuffer) {
169 CHECK_EQ(target_lvs.size(), agg_fn_names.size() / 2);
171 std::vector<llvm::Value*> new_target_lvs;
172 new_target_lvs.reserve(agg_fn_names.size());
173 for (
const auto& target_lv : target_lvs) {
174 new_target_lvs.push_back(target_lv);
175 new_target_lvs.push_back(target_lv);
177 target_lvs = new_target_lvs;
180 if (target_lvs.size() < agg_fn_names.size()) {
181 if (!uses_flatbuffer) {
182 CHECK_EQ(
size_t(1), target_lvs.size());
183 CHECK_EQ(
size_t(2), agg_fn_names.size());
185 for (
size_t i = 1; i < agg_fn_names.size(); ++i) {
186 target_lvs.push_back(target_lvs.front());
191 if (!uses_flatbuffer) {
196 CHECK_EQ(agg_fn_names.size(), target_lvs.size());
199 CHECK(str_target_lv || (agg_fn_names.size() == target_lvs.size()));
200 CHECK(target_lvs.size() == 1 || target_lvs.size() == 2);
211 (!arg_expr || arg_expr->get_type_info().get_notnull())) {
212 CHECK_EQ(
size_t(1), agg_fn_names.size());
214 llvm::Value* agg_col_ptr{
nullptr};
218 CHECK_EQ(
size_t(0), col_off % chosen_bytes);
219 col_off /= chosen_bytes;
220 CHECK(std::get<1>(agg_out_ptr_w_idx));
224 std::get<0>(agg_out_ptr_w_idx),
227 bit_cast->getType()->getScalarType()->getPointerElementType(),
232 CHECK_EQ(
size_t(0), col_off % chosen_bytes);
233 col_off /= chosen_bytes;
235 std::get<0>(agg_out_ptr_w_idx),
238 bit_cast->getType()->getScalarType()->getPointerElementType(),
244 if (chosen_bytes !=
sizeof(int32_t)) {
247 const auto acc_i64 =
LL_BUILDER.CreateBitCast(
248 is_group_by ? agg_col_ptr : agg_out_vec[slot_index],
252 "agg_count_shared", std::vector<llvm::Value*>{acc_i64,
LL_INT(int64_t(1))});
254 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
257 #
if LLVM_VERSION_MAJOR > 12
260 llvm::AtomicOrdering::Monotonic);
264 is_group_by ? agg_col_ptr : agg_out_vec[slot_index],
268 acc_i32, llvm::Type::getInt32PtrTy(
LL_CONTEXT, 3));
270 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
273 #
if LLVM_VERSION_MAJOR > 12
276 llvm::AtomicOrdering::Monotonic);
279 const auto acc_i32 = (
is_group_by ? agg_col_ptr : agg_out_vec[slot_index]);
282 const auto shared_acc_i32 =
LL_BUILDER.CreatePointerCast(
283 acc_i32, llvm::Type::getInt32PtrTy(
LL_CONTEXT, 3));
284 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
287 #
if LLVM_VERSION_MAJOR > 12
290 llvm::AtomicOrdering::Monotonic);
292 LL_BUILDER.CreateAtomicRMW(llvm::AtomicRMWInst::Add,
295 #
if LLVM_VERSION_MAJOR > 12
298 llvm::AtomicOrdering::Monotonic);
311 output_buffer_byte_stream,
313 varlen_output_buffer,
322 const std::vector<llvm::Value*>& target_lvs,
323 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
324 const std::vector<llvm::Value*>& agg_out_vec,
325 llvm::Value* output_buffer_byte_stream,
326 llvm::Value* out_row_idx,
327 llvm::Value* varlen_output_buffer,
328 int32_t slot_index)
const {
330 size_t target_lv_idx = 0;
331 const bool lazy_fetched{executor->plan_state_->isLazyFetchColumn(
target_expr)};
339 for (
const auto& agg_base_name : agg_fn_names) {
345 const auto& elem_ti = arg_expr->get_type_info().get_elem_type();
349 CHECK_EQ(
size_t(0), col_off_in_bytes %
sizeof(int64_t));
350 col_off /=
sizeof(int64_t);
352 executor->cgen_state_->emitExternalCall(
358 ->getPointerElementType(),
359 std::get<0>(agg_out_ptr_w_idx),
361 : agg_out_vec[slot_index],
362 target_lvs[target_lv_idx],
363 code_generator.
posArg(arg_expr),
365 ?
static_cast<llvm::Value*
>(executor->cgen_state_->inlineFpNull(elem_ti))
366 : static_cast<llvm::Value*>(
367 executor->cgen_state_->inlineIntNull(elem_ti))});
373 llvm::Value* agg_col_ptr{
nullptr};
374 const auto chosen_bytes =
377 const auto& arg_type =
378 ((arg_expr && arg_expr->get_type_info().get_type() !=
kNULLT) &&
382 const bool is_fp_arg =
383 !lazy_fetched && arg_type.
get_type() !=
kNULLT && arg_type.is_fp();
393 agg_col_ptr->setName(
"agg_col_ptr");
400 CHECK_LT(target_lv_idx, target_lvs.size());
401 CHECK(varlen_output_buffer);
402 auto target_lv = target_lvs[target_lv_idx];
404 std::string agg_fname_suffix =
"";
407 agg_fname_suffix +=
"_shared";
412 auto& builder = executor->cgen_state_->ir_builder_;
413 auto orig_bb = builder.GetInsertBlock();
414 auto target_ptr_type = llvm::dyn_cast<llvm::PointerType>(target_lv->getType());
415 CHECK(target_ptr_type) <<
"Varlen projections expect a pointer input.";
417 builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
419 llvm::ConstantPointerNull::get(llvm::PointerType::get(
420 target_ptr_type->getPointerElementType(), 0)));
421 llvm::BasicBlock* true_bb{
nullptr};
424 is_nullptr, executor,
false,
"varlen_null_check",
nullptr,
false);
428 builder.SetInsertPoint(nullcheck_diamond.
cond_false_);
429 auto arr_ptr_lv = executor->cgen_state_->ir_builder_.CreateBitCast(
431 llvm::PointerType::get(
get_int_type(8, executor->cgen_state_->context_), 0));
432 const int64_t chosen_bytes =
435 const auto output_buffer_slot =
LL_BUILDER.CreateZExt(
436 LL_BUILDER.CreateLoad(arg->getType()->getPointerElementType(), arg),
439 CHECK(varlen_buffer_row_sz);
440 const auto output_buffer_slot_bytes =
LL_BUILDER.CreateAdd(
442 executor->cgen_state_->llInt(
443 static_cast<int64_t>(*varlen_buffer_row_sz))),
444 executor->cgen_state_->llInt(static_cast<int64_t>(
447 std::vector<llvm::Value*> varlen_agg_args{
448 executor->castToIntPtrTyIn(varlen_output_buffer, 8),
449 output_buffer_slot_bytes,
451 executor->cgen_state_->llInt(chosen_bytes)};
452 auto varlen_offset_ptr =
453 group_by_and_agg->
emitCall(agg_base_name + agg_fname_suffix, varlen_agg_args);
456 auto varlen_offset_int =
LL_BUILDER.CreatePtrToInt(
457 varlen_offset_ptr, llvm::Type::getInt64Ty(
LL_CONTEXT));
458 builder.CreateBr(nullcheck_diamond.
cond_true_);
461 builder.SetInsertPoint(nullcheck_diamond.
cond_true_);
463 builder.CreatePHI(llvm::Type::getInt64Ty(executor->cgen_state_->context_), 2);
464 output_phi->addIncoming(varlen_offset_int, nullcheck_diamond.
cond_false_);
465 output_phi->addIncoming(executor->cgen_state_->llInt(static_cast<int64_t>(0)),
468 std::vector<llvm::Value*> agg_args{agg_col_ptr, output_phi};
469 group_by_and_agg->
emitCall(
"agg_id" + agg_fname_suffix, agg_args);
472 builder.SetInsertPoint(true_bb);
482 const auto agg_chosen_bytes =
483 float_argument_input && !is_count_in_avg ?
sizeof(float) : chosen_bytes;
484 if (float_argument_input) {
485 CHECK_GE(chosen_bytes,
sizeof(
float));
488 auto target_lv = target_lvs[target_lv_idx];
492 if (!needs_unnest_double_patch) {
495 }
else if (is_fp_arg) {
498 if (!dynamic_cast<const Analyzer::AggExpr*>(
target_expr) || arg_expr) {
500 executor->cgen_state_->castToTypeIn(target_lv, (agg_chosen_bytes << 3));
505 llvm::Value* str_target_lv{
nullptr};
508 str_target_lv = target_lvs.front();
510 std::vector<llvm::Value*> agg_args{
511 executor->castToIntPtrTyIn((
is_group_by ? agg_col_ptr : agg_out_vec[slot_index]),
512 (agg_chosen_bytes << 3)),
513 (is_simple_count_target && !arg_expr)
514 ? (agg_chosen_bytes ==
sizeof(int32_t) ?
LL_INT(int32_t(0))
516 : (is_simple_count_target && arg_expr && str_target_lv ? str_target_lv
519 if (is_simple_count_target && arg_expr && str_target_lv) {
521 agg_chosen_bytes ==
sizeof(int32_t) ?
LL_INT(int32_t(0)) :
LL_INT(int64_t(0));
524 std::string agg_fname{agg_base_name};
527 if (agg_chosen_bytes ==
sizeof(
float)) {
529 agg_fname +=
"_float";
531 CHECK_EQ(agg_chosen_bytes,
sizeof(
double));
532 agg_fname +=
"_double";
535 }
else if (agg_chosen_bytes ==
sizeof(int32_t)) {
536 agg_fname +=
"_int32";
537 }
else if (agg_chosen_bytes ==
sizeof(int16_t) &&
539 agg_fname +=
"_int16";
540 }
else if (agg_chosen_bytes ==
sizeof(int8_t) && query_mem_desc.
didOutputColumnar()) {
541 agg_fname +=
"_int8";
545 CHECK_EQ(agg_chosen_bytes,
sizeof(int64_t));
546 CHECK(!chosen_type.is_fp());
550 CHECK_EQ(agg_chosen_bytes,
sizeof(int64_t));
558 if (need_skip_null && !arg_ti.is_geometry()) {
559 agg_fname +=
"_skip_val";
563 (need_skip_null && !arg_ti.is_geometry())) {
564 llvm::Value* null_in_lv{
nullptr};
565 if (arg_ti.is_fp()) {
566 null_in_lv = executor->cgen_state_->inlineFpNull(arg_ti);
568 null_in_lv = executor->cgen_state_->inlineIntNull(
575 executor->cgen_state_->castToTypeIn(null_in_lv, (agg_chosen_bytes << 3));
576 agg_args.push_back(null_lv);
581 code_generator.
codegen(agg_expr->get_arg1().get(),
true, co).front();
582 auto cond_lv = executor->codegenConditionalAggregateCondValSelector(
584 agg_args.push_back(cond_lv);
589 agg_fname +=
"_shared";
590 if (needs_unnest_double_patch) {
594 auto agg_fname_call_ret_lv = group_by_and_agg->
emitCall(agg_fname, agg_args);
596 if (agg_fname.find(
"checked") != std::string::npos) {
603 if (window_func && !window_func->hasFraming() &&
605 const auto window_func_context =
607 const auto pending_outputs =
608 LL_INT(window_func_context->aggregateStatePendingOutputs());
609 executor->cgen_state_->emitExternalCall(
"add_window_pending_output",
611 {agg_args.front(), pending_outputs});
612 const auto& window_func_ti = window_func->get_type_info();
613 std::string apply_window_pending_outputs_name =
"apply_window_pending_outputs";
614 switch (window_func_ti.get_type()) {
616 apply_window_pending_outputs_name +=
"_float";
618 apply_window_pending_outputs_name +=
"_columnar";
623 apply_window_pending_outputs_name +=
"_double";
627 apply_window_pending_outputs_name +=
"_int";
629 apply_window_pending_outputs_name +=
632 apply_window_pending_outputs_name +=
"64";
637 const auto partition_end =
638 LL_INT(reinterpret_cast<int64_t>(window_func_context->partitionEnd()));
639 executor->cgen_state_->emitExternalCall(apply_window_pending_outputs_name,
644 code_generator.
posArg(
nullptr)});
653 const Executor* executor,
658 CHECK(!dynamic_cast<const Analyzer::AggExpr*>(target_expr));
659 ++slot_index_counter;
660 ++target_index_counter;
663 if (dynamic_cast<const Analyzer::UOper*>(target_expr) &&
664 static_cast<const Analyzer::UOper*>(target_expr)->get_optype() ==
kUNNEST) {
665 throw std::runtime_error(
"UNNEST not supported in the projection list yet.");
667 if ((executor->plan_state_->isLazyFetchColumn(target_expr) || !
is_group_by) &&
672 VLOG(2) <<
"Throw CompilationRetryNoCompaction exception";
677 executor->plan_state_->isLazyFetchColumn(target_expr)) {
682 VLOG(2) <<
"Set padded slot-width byte for the slot-"
689 auto arg_expr =
agg_arg(target_expr);
696 !arg_expr->get_type_info().is_varlen()) {
709 sample_exprs_to_codegen.emplace_back(target_expr,
712 target_index_counter++,
715 target_exprs_to_codegen.emplace_back(target_expr,
718 target_index_counter++,
724 slot_index_counter += agg_fn_names.size();
750 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
751 const std::vector<llvm::Value*>& agg_out_vec,
752 llvm::Value* output_buffer_byte_stream,
753 llvm::Value* out_row_idx,
754 llvm::Value* varlen_output_buffer,
756 CHECK(group_by_and_agg);
764 executor->plan_state_->registerNonLazyFetchExpression(target_exprs_to_codegen);
766 for (
const auto& target_expr_codegen : target_exprs_to_codegen) {
767 target_expr_codegen.codegen(group_by_and_agg,
774 output_buffer_byte_stream,
776 varlen_output_buffer,
779 if (!sample_exprs_to_codegen.empty()) {
780 codegenSampleExpressions(group_by_and_agg,
786 output_buffer_byte_stream,
797 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
798 const std::vector<llvm::Value*>& agg_out_vec,
799 llvm::Value* output_buffer_byte_stream,
800 llvm::Value* out_row_idx,
803 CHECK(!sample_exprs_to_codegen.empty());
805 if (sample_exprs_to_codegen.size() == 1 &&
806 !sample_exprs_to_codegen.front().target_info.sql_type.is_varlen()) {
807 codegenSingleSlotSampleExpression(group_by_and_agg,
813 output_buffer_byte_stream,
817 codegenMultiSlotSampleExpressions(group_by_and_agg,
823 output_buffer_byte_stream,
834 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
835 const std::vector<llvm::Value*>& agg_out_vec,
836 llvm::Value* output_buffer_byte_stream,
837 llvm::Value* out_row_idx,
840 CHECK_EQ(
size_t(1), sample_exprs_to_codegen.size());
841 CHECK(!sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
844 sample_exprs_to_codegen.front().codegen(group_by_and_agg,
851 output_buffer_byte_stream,
862 const std::tuple<llvm::Value*, llvm::Value*>& agg_out_ptr_w_idx,
863 const std::vector<llvm::Value*>& agg_out_vec,
864 llvm::Value* output_buffer_byte_stream,
865 llvm::Value* out_row_idx,
868 CHECK(sample_exprs_to_codegen.size() > 1 ||
869 sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
871 const auto& first_sample_expr = sample_exprs_to_codegen.front();
872 auto target_lvs = group_by_and_agg->
codegenAggArg(first_sample_expr.target_expr, co);
873 CHECK_GE(target_lvs.size(), size_t(1));
875 const auto init_val =
878 llvm::Value* agg_col_ptr{
nullptr};
880 const auto agg_column_size_bytes =
882 !first_sample_expr.target_info.sql_type.is_varlen()
883 ? first_sample_expr.target_info.sql_type.get_size()
889 agg_column_size_bytes,
890 first_sample_expr.base_slot_index,
891 first_sample_expr.target_idx);
893 CHECK_LT(static_cast<size_t>(first_sample_expr.base_slot_index), agg_out_vec.size());
895 executor->castToIntPtrTyIn(agg_out_vec[first_sample_expr.base_slot_index], 64);
899 codegenSlotEmptyKey(agg_col_ptr, target_lvs, executor, query_mem_desc, init_val);
902 sample_cas_lv, executor,
false,
"sample_valcheck", &diamond_codegen,
false);
904 for (
const auto& target_expr_codegen : sample_exprs_to_codegen) {
905 target_expr_codegen.codegen(group_by_and_agg,
912 output_buffer_byte_stream,
921 llvm::Value* agg_col_ptr,
922 std::vector<llvm::Value*>& target_lvs,
925 const int64_t init_val)
const {
927 const auto& first_sample_expr = sample_exprs_to_codegen.front();
928 const auto first_sample_slot_bytes =
929 first_sample_expr.target_info.sql_type.is_varlen()
931 : first_sample_expr.target_info.sql_type.get_size();
932 llvm::Value* target_lv_casted{
nullptr};
934 if (first_sample_expr.target_info.sql_type.is_varlen()) {
937 }
else if (first_sample_expr.target_info.sql_type.is_fp()) {
941 target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
943 first_sample_slot_bytes ==
sizeof(float) ? llvm::Type::getInt32Ty(
LL_CONTEXT)
946 target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
947 target_lvs.front(), llvm::Type::getInt64Ty(
LL_CONTEXT));
949 }
else if (first_sample_slot_bytes !=
sizeof(int64_t) &&
952 executor->cgen_state_->ir_builder_.CreateCast(llvm::Instruction::CastOps::SExt,
956 target_lv_casted = target_lvs.front();
959 std::string slot_empty_cas_func_name(
"slotEmptyKeyCAS");
960 llvm::Value* init_val_lv{
LL_INT(init_val)};
962 !first_sample_expr.target_info.sql_type.is_varlen()) {
964 switch (first_sample_slot_bytes) {
966 slot_empty_cas_func_name +=
"_int8";
969 slot_empty_cas_func_name +=
"_int16";
972 slot_empty_cas_func_name +=
"_int32";
977 UNREACHABLE() <<
"Invalid slot size for slotEmptyKeyCAS function.";
980 if (first_sample_slot_bytes !=
sizeof(int64_t)) {
981 init_val_lv = llvm::ConstantInt::get(
986 auto sample_cas_lv = executor->cgen_state_->emitExternalCall(
987 slot_empty_cas_func_name,
988 llvm::Type::getInt1Ty(executor->cgen_state_->context_),
989 {agg_col_ptr, target_lv_casted, init_val_lv});
990 return sample_cas_lv;
997 <<
", target_idx:" << target_expr_codegen.
target_idx
998 <<
", is_group_by: " << target_expr_codegen.
is_group_by <<
")";
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
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
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)
std::string toString() const
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)
bool usesFlatBuffer() const
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
virtual std::string toString() const =0
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