OmniSciDB  eee9fa949c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TargetExprCodegenBuilder Struct Reference

#include <TargetExprBuilder.h>

+ Collaboration diagram for TargetExprCodegenBuilder:

Public Member Functions

 TargetExprCodegenBuilder (const QueryMemoryDescriptor &query_mem_desc, const RelAlgExecutionUnit &ra_exe_unit, const bool is_group_by)
 
void operator() (const Analyzer::Expr *target_expr, const Executor *executor, const CompilationOptions &co)
 
void codegen (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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const
 
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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const
 
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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) 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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const
 
llvm::Value * codegenSlotEmptyKey (llvm::Value *agg_col_ptr, std::vector< llvm::Value * > &target_lvs, Executor *executor, const int64_t init_val) const
 

Public Attributes

size_t target_index_counter {0}
 
size_t slot_index_counter {0}
 
const QueryMemoryDescriptorquery_mem_desc
 
const RelAlgExecutionUnitra_exe_unit
 
std::vector< TargetExprCodegentarget_exprs_to_codegen
 
std::vector< TargetExprCodegensample_exprs_to_codegen
 
bool is_group_by
 

Detailed Description

Definition at line 64 of file TargetExprBuilder.h.

Constructor & Destructor Documentation

TargetExprCodegenBuilder::TargetExprCodegenBuilder ( const QueryMemoryDescriptor query_mem_desc,
const RelAlgExecutionUnit ra_exe_unit,
const bool  is_group_by 
)
inline

Definition at line 65 of file TargetExprBuilder.h.

68  : query_mem_desc(query_mem_desc)
69  , ra_exe_unit(ra_exe_unit)
const RelAlgExecutionUnit & ra_exe_unit
const QueryMemoryDescriptor & query_mem_desc

Member Function Documentation

void TargetExprCodegenBuilder::codegen ( 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,
GroupByAndAggregate::DiamondCodegen diamond_codegen 
) const

Definition at line 520 of file TargetExprBuilder.cpp.

References CHECK().

Referenced by GroupByAndAggregate::codegenAggCalls().

529  {
530  CHECK(group_by_and_agg);
531  CHECK(executor);
532 
533  for (const auto& target_expr_codegen : target_exprs_to_codegen) {
534  target_expr_codegen.codegen(group_by_and_agg,
535  executor,
536  query_mem_desc,
537  co,
538  agg_out_ptr_w_idx,
539  agg_out_vec,
540  output_buffer_byte_stream,
541  out_row_idx,
542  diamond_codegen);
543  }
544  if (!sample_exprs_to_codegen.empty()) {
545  codegenSampleExpressions(group_by_and_agg,
546  executor,
547  query_mem_desc,
548  co,
549  agg_out_ptr_w_idx,
550  agg_out_vec,
551  output_buffer_byte_stream,
552  out_row_idx,
553  diamond_codegen);
554  }
555 }
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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const
std::vector< TargetExprCodegen > target_exprs_to_codegen
CHECK(cgen_state)
std::vector< TargetExprCodegen > sample_exprs_to_codegen

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TargetExprCodegenBuilder::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,
GroupByAndAggregate::DiamondCodegen diamond_codegen 
) const

Definition at line 618 of file TargetExprBuilder.cpp.

References CHECK(), CHECK_GE, CHECK_LT, GroupByAndAggregate::codegenAggArg(), GroupByAndAggregate::codegenAggColumnPtr(), CompilationOptions::device_type_, anonymous_namespace{TargetExprBuilder.cpp}::get_initial_agg_val(), GPU, TargetExprCodegen::is_group_by, and QueryMemoryDescriptor::isLogicalSizedColumnsAllowed().

627  {
628  CHECK(sample_exprs_to_codegen.size() > 1 ||
629  sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
631  const auto& first_sample_expr = sample_exprs_to_codegen.front();
632  auto target_lvs = group_by_and_agg->codegenAggArg(first_sample_expr.target_expr, co);
633  CHECK_GE(target_lvs.size(), size_t(1));
634 
635  const auto init_val =
636  get_initial_agg_val(first_sample_expr.target_info, query_mem_desc);
637 
638  llvm::Value* agg_col_ptr{nullptr};
639  if (is_group_by) {
640  const auto agg_column_size_bytes =
641  query_mem_desc.isLogicalSizedColumnsAllowed() &&
642  !first_sample_expr.target_info.sql_type.is_varlen()
643  ? first_sample_expr.target_info.sql_type.get_size()
644  : sizeof(int64_t);
645  agg_col_ptr = group_by_and_agg->codegenAggColumnPtr(output_buffer_byte_stream,
646  out_row_idx,
647  agg_out_ptr_w_idx,
648  query_mem_desc,
649  agg_column_size_bytes,
650  first_sample_expr.base_slot_index,
651  first_sample_expr.target_idx);
652  } else {
653  CHECK_LT(static_cast<size_t>(first_sample_expr.base_slot_index), agg_out_vec.size());
654  agg_col_ptr =
655  executor->castToIntPtrTyIn(agg_out_vec[first_sample_expr.base_slot_index], 64);
656  }
657 
658  auto sample_cas_lv = codegenSlotEmptyKey(agg_col_ptr, target_lvs, executor, init_val);
659 
661  sample_cas_lv, executor, false, "sample_valcheck", &diamond_codegen, false);
662 
663  for (const auto& target_expr_codegen : sample_exprs_to_codegen) {
664  target_expr_codegen.codegen(group_by_and_agg,
665  executor,
666  query_mem_desc,
667  co,
668  agg_out_ptr_w_idx,
669  agg_out_vec,
670  output_buffer_byte_stream,
671  out_row_idx,
672  diamond_codegen,
673  &sample_cfg);
674  }
675 }
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.
bool isLogicalSizedColumnsAllowed() const
#define CHECK_GE(x, y)
Definition: Logger.h:210
llvm::Value * codegenSlotEmptyKey(llvm::Value *agg_col_ptr, std::vector< llvm::Value * > &target_lvs, Executor *executor, const int64_t init_val) const
CHECK(cgen_state)
std::vector< TargetExprCodegen > sample_exprs_to_codegen
ExecutorDeviceType device_type_
#define CHECK_LT(x, y)
Definition: Logger.h:207
std::vector< llvm::Value * > codegenAggArg(const Analyzer::Expr *target_expr, const CompilationOptions &co)
int64_t get_initial_agg_val(const TargetInfo &target_info, const QueryMemoryDescriptor &query_mem_desc)

+ Here is the call graph for this function:

void TargetExprCodegenBuilder::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,
GroupByAndAggregate::DiamondCodegen diamond_codegen 
) const

Definition at line 557 of file TargetExprBuilder.cpp.

References CHECK(), CompilationOptions::device_type_, and GPU.

566  {
567  CHECK(!sample_exprs_to_codegen.empty());
569  if (sample_exprs_to_codegen.size() == 1 &&
570  !sample_exprs_to_codegen.front().target_info.sql_type.is_varlen()) {
571  codegenSingleSlotSampleExpression(group_by_and_agg,
572  executor,
573  query_mem_desc,
574  co,
575  agg_out_ptr_w_idx,
576  agg_out_vec,
577  output_buffer_byte_stream,
578  out_row_idx,
579  diamond_codegen);
580  } else {
581  codegenMultiSlotSampleExpressions(group_by_and_agg,
582  executor,
583  query_mem_desc,
584  co,
585  agg_out_ptr_w_idx,
586  agg_out_vec,
587  output_buffer_byte_stream,
588  out_row_idx,
589  diamond_codegen);
590  }
591 }
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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const
CHECK(cgen_state)
std::vector< TargetExprCodegen > sample_exprs_to_codegen
ExecutorDeviceType device_type_
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, GroupByAndAggregate::DiamondCodegen &diamond_codegen) const

+ Here is the call graph for this function:

void TargetExprCodegenBuilder::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,
GroupByAndAggregate::DiamondCodegen diamond_codegen 
) const

Definition at line 593 of file TargetExprBuilder.cpp.

References CHECK(), CHECK_EQ, CompilationOptions::device_type_, and GPU.

602  {
603  CHECK_EQ(size_t(1), sample_exprs_to_codegen.size());
604  CHECK(!sample_exprs_to_codegen.front().target_info.sql_type.is_varlen());
606  // no need for the atomic if we only have one SAMPLE target
607  sample_exprs_to_codegen.front().codegen(group_by_and_agg,
608  executor,
609  query_mem_desc,
610  co,
611  agg_out_ptr_w_idx,
612  agg_out_vec,
613  output_buffer_byte_stream,
614  out_row_idx,
615  diamond_codegen);
616 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
CHECK(cgen_state)
std::vector< TargetExprCodegen > sample_exprs_to_codegen
ExecutorDeviceType device_type_

+ Here is the call graph for this function:

llvm::Value * TargetExprCodegenBuilder::codegenSlotEmptyKey ( llvm::Value *  agg_col_ptr,
std::vector< llvm::Value * > &  target_lvs,
Executor executor,
const int64_t  init_val 
) const

Definition at line 677 of file TargetExprBuilder.cpp.

References CHECK_EQ, get_int_type(), QueryMemoryDescriptor::isLogicalSizedColumnsAllowed(), LL_BUILDER, LL_CONTEXT, LL_INT, and UNREACHABLE.

681  {
682  const auto& first_sample_expr = sample_exprs_to_codegen.front();
683  const auto first_sample_slot_bytes =
684  first_sample_expr.target_info.sql_type.is_varlen()
685  ? sizeof(int64_t)
686  : first_sample_expr.target_info.sql_type.get_size();
687  llvm::Value* target_lv_casted{nullptr};
688  // deciding whether proper casting is required for the first sample's slot:
689  if (first_sample_expr.target_info.sql_type.is_varlen()) {
690  target_lv_casted =
691  LL_BUILDER.CreatePtrToInt(target_lvs.front(), llvm::Type::getInt64Ty(LL_CONTEXT));
692  } else if (first_sample_expr.target_info.sql_type.is_fp()) {
693  // Initialization value for SAMPLE on a float column should be 0
694  CHECK_EQ(init_val, 0);
696  target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
697  target_lvs.front(),
698  first_sample_slot_bytes == sizeof(float) ? llvm::Type::getInt32Ty(LL_CONTEXT)
699  : llvm::Type::getInt64Ty(LL_CONTEXT));
700  } else {
701  target_lv_casted = executor->cgen_state_->ir_builder_.CreateFPToSI(
702  target_lvs.front(), llvm::Type::getInt64Ty(LL_CONTEXT));
703  }
704  } else if (first_sample_slot_bytes != sizeof(int64_t) &&
706  target_lv_casted =
707  executor->cgen_state_->ir_builder_.CreateCast(llvm::Instruction::CastOps::SExt,
708  target_lvs.front(),
709  llvm::Type::getInt64Ty(LL_CONTEXT));
710  } else {
711  target_lv_casted = target_lvs.front();
712  }
713 
714  std::string slot_empty_cas_func_name("slotEmptyKeyCAS");
715  llvm::Value* init_val_lv{LL_INT(init_val)};
717  !first_sample_expr.target_info.sql_type.is_varlen()) {
718  // add proper suffix to the function name:
719  switch (first_sample_slot_bytes) {
720  case 1:
721  slot_empty_cas_func_name += "_int8";
722  break;
723  case 2:
724  slot_empty_cas_func_name += "_int16";
725  break;
726  case 4:
727  slot_empty_cas_func_name += "_int32";
728  break;
729  case 8:
730  break;
731  default:
732  UNREACHABLE() << "Invalid slot size for slotEmptyKeyCAS function.";
733  break;
734  }
735  if (first_sample_slot_bytes != sizeof(int64_t)) {
736  init_val_lv = llvm::ConstantInt::get(
737  get_int_type(first_sample_slot_bytes * 8, LL_CONTEXT), init_val);
738  }
739  }
740 
741  auto sample_cas_lv = executor->cgen_state_->emitExternalCall(
742  slot_empty_cas_func_name,
743  llvm::Type::getInt1Ty(executor->cgen_state_->context_),
744  {agg_col_ptr, target_lv_casted, init_val_lv});
745  return sample_cas_lv;
746 }
#define LL_BUILDER
#define CHECK_EQ(x, y)
Definition: Logger.h:205
bool isLogicalSizedColumnsAllowed() const
#define UNREACHABLE()
Definition: Logger.h:241
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
const QueryMemoryDescriptor & query_mem_desc
#define LL_INT(v)
std::vector< TargetExprCodegen > sample_exprs_to_codegen
#define LL_CONTEXT

+ Here is the call graph for this function:

void TargetExprCodegenBuilder::operator() ( const Analyzer::Expr target_expr,
const Executor executor,
const CompilationOptions co 
)

Definition at line 445 of file TargetExprBuilder.cpp.

References agg_arg(), anonymous_namespace{TargetExprBuilder.cpp}::agg_fn_base_names(), TargetInfo::agg_kind, CHECK(), constrained_not_null(), CompilationOptions::device_type_, g_bigint_count, get_target_info(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getQueryDescriptionType(), GPU, TargetInfo::is_agg, anonymous_namespace{TargetExprBuilder.cpp}::is_columnar_projection(), TargetExprCodegen::is_group_by, kSAMPLE, kSINGLE_VALUE, kUNNEST, NonGroupedAggregate, TargetInfo::skip_null_val, and TargetExprCodegen::target_info.

447  {
449  CHECK(!dynamic_cast<const Analyzer::AggExpr*>(target_expr));
452  return;
453  }
454  if (dynamic_cast<const Analyzer::UOper*>(target_expr) &&
455  static_cast<const Analyzer::UOper*>(target_expr)->get_optype() == kUNNEST) {
456  throw std::runtime_error("UNNEST not supported in the projection list yet.");
457  }
458  if ((executor->plan_state_->isLazyFetchColumn(target_expr) || !is_group_by) &&
460  sizeof(int64_t)) &&
462  // TODO(miyu): enable different byte width in the layout w/o padding
464  }
465 
466  auto target_info = get_target_info(target_expr, g_bigint_count);
467  auto arg_expr = agg_arg(target_expr);
468  if (arg_expr) {
469  if (target_info.agg_kind == kSINGLE_VALUE || target_info.agg_kind == kSAMPLE) {
470  target_info.skip_null_val = false;
473  !arg_expr->get_type_info().is_varlen()) {
474  // TODO: COUNT is currently not null-aware for varlen types. Need to add proper code
475  // generation for handling varlen nulls.
476  target_info.skip_null_val = true;
477  } else if (constrained_not_null(arg_expr, ra_exe_unit.quals)) {
478  target_info.skip_null_val = false;
479  }
480  }
481 
484  (co.device_type_ == ExecutorDeviceType::GPU) && target_info.is_agg &&
485  (target_info.agg_kind == kSAMPLE)) {
486  sample_exprs_to_codegen.emplace_back(target_expr,
487  target_info,
490  is_group_by);
491  } else {
492  target_exprs_to_codegen.emplace_back(target_expr,
493  target_info,
496  is_group_by);
497  }
498 
499  const auto agg_fn_names = agg_fn_base_names(target_info);
500  slot_index_counter += agg_fn_names.size();
501 }
const RelAlgExecutionUnit & ra_exe_unit
const Analyzer::Expr * agg_arg(const Analyzer::Expr *expr)
bool constrained_not_null(const Analyzer::Expr *expr, const std::list< std::shared_ptr< Analyzer::Expr >> &quals)
std::vector< std::string > agg_fn_base_names(const TargetInfo &target_info)
TargetInfo get_target_info(const PointerType target_expr, const bool bigint_count)
Definition: TargetInfo.h:66
std::vector< TargetExprCodegen > target_exprs_to_codegen
const QueryMemoryDescriptor & query_mem_desc
CHECK(cgen_state)
bool g_bigint_count
std::vector< TargetExprCodegen > sample_exprs_to_codegen
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
ExecutorDeviceType device_type_
QueryDescriptionType getQueryDescriptionType() const
std::list< std::shared_ptr< Analyzer::Expr > > quals
bool is_columnar_projection(const QueryMemoryDescriptor &query_mem_desc)

+ Here is the call graph for this function:

Member Data Documentation

bool TargetExprCodegenBuilder::is_group_by

Definition at line 133 of file TargetExprBuilder.h.

const QueryMemoryDescriptor& TargetExprCodegenBuilder::query_mem_desc

Definition at line 127 of file TargetExprBuilder.h.

const RelAlgExecutionUnit& TargetExprCodegenBuilder::ra_exe_unit

Definition at line 128 of file TargetExprBuilder.h.

std::vector<TargetExprCodegen> TargetExprCodegenBuilder::sample_exprs_to_codegen

Definition at line 131 of file TargetExprBuilder.h.

size_t TargetExprCodegenBuilder::slot_index_counter {0}

Definition at line 125 of file TargetExprBuilder.h.

std::vector<TargetExprCodegen> TargetExprCodegenBuilder::target_exprs_to_codegen

Definition at line 130 of file TargetExprBuilder.h.

size_t TargetExprCodegenBuilder::target_index_counter {0}

Definition at line 124 of file TargetExprBuilder.h.


The documentation for this struct was generated from the following files: