OmniSciDB  29e35f4d58
ResultSetReductionJIT Class Reference

#include <ResultSetReductionJIT.h>

+ Collaboration diagram for ResultSetReductionJIT:

Public Member Functions

 ResultSetReductionJIT (const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const std::vector< int64_t > &target_init_vals)
 
ReductionCode codegen () const
 

Static Public Member Functions

static void clearCache ()
 

Private Member Functions

void isEmpty (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisions (const ReductionCode &reduction_code) const
 
void reduceOneEntryTargetsNoCollisions (Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
 
void reduceOneEntryBaseline (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisionsIdx (const ReductionCode &reduction_code) const
 
void reduceOneEntryBaselineIdx (const ReductionCode &reduction_code) const
 
void reduceLoop (const ReductionCode &reduction_code) const
 
void reduceOneSlot (Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
 
void reduceOneAggregateSlot (Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const int64_t init_val, const int8_t chosen_bytes, Function *ir_reduce_one_entry) const
 
void reduceOneCountDistinctSlot (Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
 
ReductionCode finalizeReductionCode (ReductionCode reduction_code, const llvm::Function *ir_is_empty, const llvm::Function *ir_reduce_one_entry, const llvm::Function *ir_reduce_one_entry_idx, const CodeCacheKey &key) const
 
std::string cacheKey () const
 

Private Attributes

const QueryMemoryDescriptor query_mem_desc_
 
const std::vector< TargetInfotargets_
 
const std::vector< int64_t > target_init_vals_
 

Static Private Attributes

static CodeCache s_code_cache
 

Detailed Description

Definition at line 54 of file ResultSetReductionJIT.h.

Constructor & Destructor Documentation

◆ ResultSetReductionJIT()

ResultSetReductionJIT::ResultSetReductionJIT ( const QueryMemoryDescriptor query_mem_desc,
const std::vector< TargetInfo > &  targets,
const std::vector< int64_t > &  target_init_vals 
)

Definition at line 493 of file ResultSetReductionJIT.cpp.

496  : query_mem_desc_(query_mem_desc)
497  , targets_(targets)
498  , target_init_vals_(target_init_vals) {}
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
const std::vector< TargetInfo > targets_

Member Function Documentation

◆ cacheKey()

std::string ResultSetReductionJIT::cacheKey ( ) const
private

Definition at line 1225 of file ResultSetReductionJIT.cpp.

References join(), query_mem_desc_, QueryMemoryDescriptor::reductionKey(), anonymous_namespace{ResultSetReductionJIT.cpp}::target_info_key(), target_init_vals_, targets_, and to_string().

Referenced by codegen().

1225  {
1226  std::vector<std::string> target_init_vals_strings;
1227  std::transform(target_init_vals_.begin(),
1228  target_init_vals_.end(),
1229  std::back_inserter(target_init_vals_strings),
1230  [](const int64_t v) { return std::to_string(v); });
1231  const auto target_init_vals_key =
1232  boost::algorithm::join(target_init_vals_strings, ", ");
1233  std::vector<std::string> targets_strings;
1234  std::transform(
1235  targets_.begin(),
1236  targets_.end(),
1237  std::back_inserter(targets_strings),
1238  [](const TargetInfo& target_info) { return target_info_key(target_info); });
1239  const auto targets_key = boost::algorithm::join(targets_strings, ", ");
1240  return query_mem_desc_.reductionKey() + "\n" + target_init_vals_key + "\n" +
1241  targets_key;
1242 }
std::string join(T const &container, std::string const &delim)
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
std::string target_info_key(const TargetInfo &target_info)
std::string reductionKey() const
const std::vector< TargetInfo > targets_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearCache()

void ResultSetReductionJIT::clearCache ( )
static

Definition at line 607 of file ResultSetReductionJIT.cpp.

References LruCache< key_t, value_t, hash_t >::clear(), StubGenerator::clearCache(), g_rt_module, and s_code_cache.

607  {
608  // Clear stub cache to avoid crash caused by non-deterministic static destructor order
609  // of LLVM context and the cache.
612  g_rt_module = nullptr;
613 }
void clear()
Definition: LruCache.hpp:57
std::unique_ptr< llvm::Module > g_rt_module
+ Here is the call graph for this function:

◆ codegen()

ReductionCode ResultSetReductionJIT::codegen ( ) const

Definition at line 531 of file ResultSetReductionJIT.cpp.

References QueryMemoryDescriptor::blocksShareMemory(), cacheKey(), anonymous_namespace{ResultSetReductionJIT.cpp}::create_llvm_function(), QueryMemoryDescriptor::didOutputColumnar(), logger::FATAL, finalizeReductionCode(), LruCache< key_t, value_t, hash_t >::get(), QueryMemoryDescriptor::getEntryCount(), QueryMemoryDescriptor::getExecutor(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, GroupByPerfectHash, anonymous_namespace{ResultSetReductionJIT.cpp}::INTERP_THRESHOLD, anonymous_namespace{ResultSetReductionJIT.cpp}::is_aggregate_query(), isEmpty(), LOG, NonGroupedAggregate, query_mem_desc_, reduceLoop(), reduceOneEntryBaseline(), reduceOneEntryBaselineIdx(), reduceOneEntryNoCollisions(), reduceOneEntryNoCollisionsIdx(), runtime_module_shallow_copy(), s_code_cache, ReductionCode::s_reduction_mutex, anonymous_namespace{ResultSetReductionJIT.cpp}::setup_functions_ir(), and translate_function().

Referenced by ResultSetManager::reduce(), and Executor::reduceMultiDeviceResultSets().

531  {
532  const auto hash_type = query_mem_desc_.getQueryDescriptionType();
534  return {};
535  }
536  auto reduction_code = setup_functions_ir(hash_type);
537  isEmpty(reduction_code);
541  reduceOneEntryNoCollisions(reduction_code);
542  reduceOneEntryNoCollisionsIdx(reduction_code);
543  break;
544  }
546  reduceOneEntryBaseline(reduction_code);
547  reduceOneEntryBaselineIdx(reduction_code);
548  break;
549  }
550  default: {
551  LOG(FATAL) << "Unexpected query description type";
552  }
553  }
554  reduceLoop(reduction_code);
555  // For small result sets, avoid native code generation and use the interpreter instead.
558  return reduction_code;
559  }
560  std::lock_guard<std::mutex> reduction_guard(ReductionCode::s_reduction_mutex);
561  CodeCacheKey key{cacheKey()};
562  const auto val_ptr = s_code_cache.get(key);
563  if (val_ptr) {
564  return {reinterpret_cast<ReductionCode::FuncPtr>(std::get<0>(val_ptr->first.front())),
565  nullptr,
566  nullptr,
567  nullptr,
568  std::move(reduction_code.ir_is_empty),
569  std::move(reduction_code.ir_reduce_one_entry),
570  std::move(reduction_code.ir_reduce_one_entry_idx),
571  std::move(reduction_code.ir_reduce_loop)};
572  }
573  reduction_code.cgen_state.reset(new CgenState({}, false));
574  auto cgen_state = reduction_code.cgen_state.get();
575  std::unique_ptr<llvm::Module> module(runtime_module_shallow_copy(cgen_state));
576  cgen_state->module_ = module.get();
577  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
578  auto ir_reduce_one_entry =
579  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
580  auto ir_reduce_one_entry_idx =
581  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
582  auto ir_reduce_loop =
583  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
584  std::unordered_map<const Function*, llvm::Function*> f;
585  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
586  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
587  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
588  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
589  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
591  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
592  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
593  ir_reduce_one_entry_idx,
594  reduction_code,
595  f);
597  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
598  reduction_code.llvm_reduce_loop = ir_reduce_loop;
599  reduction_code.module = std::move(module);
600  return finalizeReductionCode(std::move(reduction_code),
601  ir_is_empty,
602  ir_reduce_one_entry,
603  ir_reduce_one_entry_idx,
604  key);
605 }
void reduceOneEntryBaseline(const ReductionCode &reduction_code) const
bool is_aggregate_query(const QueryDescriptionType hash_type)
void isEmpty(const ReductionCode &reduction_code) const
void reduceOneEntryNoCollisionsIdx(const ReductionCode &reduction_code) const
std::unique_ptr< llvm::Module > runtime_module_shallow_copy(CgenState *cgen_state)
#define LOG(tag)
Definition: Logger.h:188
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:61
int32_t(*)(int8_t *this_buff, const int8_t *that_buff, const int32_t start_entry_index, const int32_t end_entry_index, const int32_t that_entry_count, const void *this_qmd, const void *that_qmd, const void *serialized_varlen_buffer) FuncPtr
const QueryMemoryDescriptor query_mem_desc_
const Executor * getExecutor() const
ReductionCode finalizeReductionCode(ReductionCode reduction_code, const llvm::Function *ir_is_empty, const llvm::Function *ir_reduce_one_entry, const llvm::Function *ir_reduce_one_entry_idx, const CodeCacheKey &key) const
void reduceOneEntryNoCollisions(const ReductionCode &reduction_code) const
void translate_function(const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, const std::unordered_map< const Function *, llvm::Function *> &f)
llvm::Function * create_llvm_function(const Function *function, const CgenState *cgen_state)
static std::mutex s_reduction_mutex
ReductionCode setup_functions_ir(const QueryDescriptionType hash_type)
void reduceOneEntryBaselineIdx(const ReductionCode &reduction_code) const
value_t * get(const key_t &key)
Definition: LruCache.hpp:39
void reduceLoop(const ReductionCode &reduction_code) const
QueryDescriptionType getQueryDescriptionType() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalizeReductionCode()

ReductionCode ResultSetReductionJIT::finalizeReductionCode ( ReductionCode  reduction_code,
const llvm::Function *  ir_is_empty,
const llvm::Function *  ir_reduce_one_entry,
const llvm::Function *  ir_reduce_one_entry_idx,
const CodeCacheKey key 
) const
private

Definition at line 1186 of file ResultSetReductionJIT.cpp.

References Executor::addCodeToCache(), CPU, ReductionCode::func_ptr, CodeGenerator::generateNativeCPUCode(), ReductionCode::llvm_reduce_loop, ReductionCode::module, ReductionJIT, and s_code_cache.

Referenced by codegen().

1191  {
1192  CompilationOptions co{
1194  reduction_code.module.release();
1196  reduction_code.llvm_reduce_loop, {reduction_code.llvm_reduce_loop}, co);
1197  reduction_code.func_ptr = reinterpret_cast<ReductionCode::FuncPtr>(
1198  ee->getPointerToFunction(reduction_code.llvm_reduce_loop));
1199  auto cache_val =
1200  std::make_tuple(reinterpret_cast<void*>(reduction_code.func_ptr), std::move(ee));
1201  std::vector<std::tuple<void*, ExecutionEngineWrapper>> cache_vals;
1202  cache_vals.emplace_back(std::move(cache_val));
1204  std::move(cache_vals),
1205  reduction_code.llvm_reduce_loop->getParent(),
1206  s_code_cache);
1207  return reduction_code;
1208 }
static void addCodeToCache(const CodeCacheKey &, std::vector< std::tuple< void *, ExecutionEngineWrapper >>, llvm::Module *, CodeCache &)
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function *> &live_funcs, const CompilationOptions &co)
llvm::Function * llvm_reduce_loop
int32_t(*)(int8_t *this_buff, const int8_t *that_buff, const int32_t start_entry_index, const int32_t end_entry_index, const int32_t that_entry_count, const void *this_qmd, const void *that_qmd, const void *serialized_varlen_buffer) FuncPtr
std::unique_ptr< llvm::Module > module
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isEmpty()

void ResultSetReductionJIT::isEmpty ( const ReductionCode reduction_code) const
private

Definition at line 615 of file ResultSetReductionJIT.cpp.

References CHECK, CHECK_GE, CHECK_LT, QueryMemoryDescriptor::didOutputColumnar(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i32(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff(), EMPTY_KEY_32, EMPTY_KEY_64, ICmp::EQ, logger::FATAL, get_byteoff_of_slot(), QueryMemoryDescriptor::getEffectiveKeyWidth(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getQueryDescriptionType(), QueryMemoryDescriptor::getTargetIdxForKey(), GroupByPerfectHash, QueryMemoryDescriptor::hasKeylessHash(), Int32, Int64, ReductionCode::ir_is_empty, anonymous_namespace{ResultSetReductionJIT.cpp}::is_aggregate_query(), LOG, query_mem_desc_, and target_init_vals_.

Referenced by codegen().

615  {
616  auto ir_is_empty = reduction_code.ir_is_empty.get();
619  Value* key{nullptr};
620  Value* empty_key_val{nullptr};
621  const auto keys_ptr = ir_is_empty->arg(0);
626  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
627  target_init_vals_.size());
628  const int64_t target_slot_off =
630  const auto slot_ptr = ir_is_empty->add<GetElementPtr>(
631  keys_ptr,
632  ir_is_empty->addConstant<ConstantInt>(target_slot_off, Type::Int32),
633  "is_empty_slot_ptr");
634  const auto compact_sz =
636  key = emit_read_int_from_buff(slot_ptr, compact_sz, ir_is_empty);
637  empty_key_val = ir_is_empty->addConstant<ConstantInt>(
639  } else {
641  case 4: {
644  key = emit_load_i32(keys_ptr, ir_is_empty);
645  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_32, Type::Int32);
646  break;
647  }
648  case 8: {
649  key = emit_load_i64(keys_ptr, ir_is_empty);
650  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_64, Type::Int64);
651  break;
652  }
653  default:
654  LOG(FATAL) << "Invalid key width";
655  }
656  }
657  const auto ret =
658  ir_is_empty->add<ICmp>(ICmp::Predicate::EQ, key, empty_key_val, "is_key_empty");
659  ir_is_empty->add<Ret>(ret);
660 }
bool is_aggregate_query(const QueryDescriptionType hash_type)
#define EMPTY_KEY_64
Value * emit_read_int_from_buff(Value *ptr, const int8_t compact_sz, Function *function)
#define LOG(tag)
Definition: Logger.h:188
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
#define CHECK_GE(x, y)
Definition: Logger.h:206
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
Value * emit_load_i32(Value *ptr, Function *function)
int32_t getTargetIdxForKey() const
#define CHECK_LT(x, y)
Definition: Logger.h:203
Value * emit_load_i64(Value *ptr, Function *function)
#define CHECK(condition)
Definition: Logger.h:193
#define EMPTY_KEY_32
QueryDescriptionType getQueryDescriptionType() const
size_t getEffectiveKeyWidth() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceLoop()

void ResultSetReductionJIT::reduceLoop ( const ReductionCode reduction_code) const
private

Definition at line 998 of file ResultSetReductionJIT.cpp.

References anonymous_namespace{ResultSetReductionJIT.cpp}::generate_loop_body(), Int32, ReductionCode::ir_reduce_loop, and ReductionCode::ir_reduce_one_entry_idx.

Referenced by codegen().

998  {
999  auto ir_reduce_loop = reduction_code.ir_reduce_loop.get();
1000  const auto this_buff_arg = ir_reduce_loop->arg(0);
1001  const auto that_buff_arg = ir_reduce_loop->arg(1);
1002  const auto start_index_arg = ir_reduce_loop->arg(2);
1003  const auto end_index_arg = ir_reduce_loop->arg(3);
1004  const auto that_entry_count_arg = ir_reduce_loop->arg(4);
1005  const auto this_qmd_handle_arg = ir_reduce_loop->arg(5);
1006  const auto that_qmd_handle_arg = ir_reduce_loop->arg(6);
1007  const auto serialized_varlen_buffer_arg = ir_reduce_loop->arg(7);
1008  For* for_loop =
1009  static_cast<For*>(ir_reduce_loop->add<For>(start_index_arg, end_index_arg, ""));
1010  generate_loop_body(for_loop,
1011  ir_reduce_loop,
1012  reduction_code.ir_reduce_one_entry_idx.get(),
1013  this_buff_arg,
1014  that_buff_arg,
1015  start_index_arg,
1016  that_entry_count_arg,
1017  this_qmd_handle_arg,
1018  that_qmd_handle_arg,
1019  serialized_varlen_buffer_arg);
1020  ir_reduce_loop->add<Ret>(ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32));
1021 }
std::unique_ptr< Function > ir_reduce_loop
void generate_loop_body(For *for_loop, Function *ir_reduce_loop, Function *ir_reduce_one_entry_idx, Value *this_buff, Value *that_buff, Value *start_index, Value *that_entry_count, Value *this_qmd_handle, Value *that_qmd_handle, Value *serialized_varlen_buffer)
std::unique_ptr< Function > ir_reduce_one_entry_idx
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneAggregateSlot()

void ResultSetReductionJIT::reduceOneAggregateSlot ( Value this_ptr1,
Value this_ptr2,
Value that_ptr1,
Value that_ptr2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const int64_t  init_val,
const int8_t  chosen_bytes,
Function ir_reduce_one_entry 
) const
private

Definition at line 1098 of file ResultSetReductionJIT.cpp.

References TargetInfo::agg_kind, CHECK_EQ, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), logger::FATAL, QueryMemoryDescriptor::getPaddedSlotWidthBytes(), is_distinct_target(), kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kMAX, kMIN, kSUM, LOG, query_mem_desc_, and reduceOneCountDistinctSlot().

Referenced by reduceOneSlot().

1107  {
1108  switch (target_info.agg_kind) {
1109  case kCOUNT:
1110  case kAPPROX_COUNT_DISTINCT: {
1111  if (is_distinct_target(target_info)) {
1112  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1114  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1115  break;
1116  }
1117  CHECK_EQ(int64_t(0), init_val);
1118  emit_aggregate_one_count(this_ptr1, that_ptr1, chosen_bytes, ir_reduce_one_entry);
1119  break;
1120  }
1121  case kAVG: {
1122  // Ignore float argument compaction for count component for fear of its overflow
1123  emit_aggregate_one_count(this_ptr2,
1124  that_ptr2,
1125  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx),
1126  ir_reduce_one_entry);
1127  }
1128  // fall thru
1129  case kSUM: {
1131  this_ptr1,
1132  that_ptr1,
1133  init_val,
1134  chosen_bytes,
1135  target_info,
1136  ir_reduce_one_entry);
1137  break;
1138  }
1139  case kMIN: {
1141  this_ptr1,
1142  that_ptr1,
1143  init_val,
1144  chosen_bytes,
1145  target_info,
1146  ir_reduce_one_entry);
1147  break;
1148  }
1149  case kMAX: {
1151  this_ptr1,
1152  that_ptr1,
1153  init_val,
1154  chosen_bytes,
1155  target_info,
1156  ir_reduce_one_entry);
1157  break;
1158  }
1159  default:
1160  LOG(FATAL) << "Invalid aggregate type";
1161  }
1162 }
void emit_aggregate_one_nullable_value(const std::string &agg_kind, Value *val_ptr, Value *other_ptr, const int64_t init_val, const size_t chosen_bytes, const TargetInfo &agg_info, Function *ir_reduce_one_entry)
#define CHECK_EQ(x, y)
Definition: Logger.h:201
#define LOG(tag)
Definition: Logger.h:188
const QueryMemoryDescriptor query_mem_desc_
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
Definition: sqldefs.h:73
Definition: sqldefs.h:75
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:117
SQLAgg agg_kind
Definition: TargetInfo.h:41
void reduceOneCountDistinctSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
Definition: sqldefs.h:76
void emit_aggregate_one_count(Value *val_ptr, Value *other_ptr, const size_t chosen_bytes, Function *ir_reduce_one_entry)
Definition: sqldefs.h:74
Definition: sqldefs.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneCountDistinctSlot()

void ResultSetReductionJIT::reduceOneCountDistinctSlot ( Value this_ptr1,
Value that_ptr1,
const size_t  target_logical_idx,
Function ir_reduce_one_entry 
) const
private

Definition at line 1164 of file ResultSetReductionJIT.cpp.

References CHECK_LT, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), QueryMemoryDescriptor::getCountDistinctDescriptorsSize(), Int64, query_mem_desc_, and Void.

Referenced by reduceOneAggregateSlot().

1168  {
1170  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1171  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1172  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1173  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1174  ir_reduce_one_entry->add<ExternalCall>(
1175  "count_distinct_set_union_jit_rt",
1176  Type::Void,
1177  std::vector<const Value*>{
1178  new_set_handle,
1179  old_set_handle,
1180  that_qmd_arg,
1181  this_qmd_arg,
1182  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1183  "");
1184 }
size_t getCountDistinctDescriptorsSize() const
const QueryMemoryDescriptor query_mem_desc_
#define CHECK_LT(x, y)
Definition: Logger.h:203
Value * emit_load_i64(Value *ptr, Function *function)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneEntryBaseline()

void ResultSetReductionJIT::reduceOneEntryBaseline ( const ReductionCode reduction_code) const
private

Definition at line 777 of file ResultSetReductionJIT.cpp.

References advance_slot(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, ReductionCode::ir_reduce_one_entry, kAVG, kSAMPLE, query_mem_desc_, reduceOneSlot(), QueryMemoryDescriptor::targetGroupbyIndicesSize(), targets_, and to_string().

Referenced by codegen().

778  {
779  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
780  const auto this_targets_ptr_arg = ir_reduce_one_entry->arg(0);
781  const auto that_targets_ptr_arg = ir_reduce_one_entry->arg(1);
782  Value* this_ptr1 = this_targets_ptr_arg;
783  Value* that_ptr1 = that_targets_ptr_arg;
784  size_t j = 0;
785  size_t init_agg_val_idx = 0;
786  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
787  ++target_logical_idx) {
788  const auto& target_info = targets_[target_logical_idx];
789  Value* this_ptr2{nullptr};
790  Value* that_ptr2{nullptr};
791  if (target_info.is_agg &&
792  (target_info.agg_kind == kAVG ||
793  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
794  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
795  const auto second_slot_rel_off =
796  ir_reduce_one_entry->addConstant<ConstantInt>(sizeof(int64_t), Type::Int32);
797  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
798  this_ptr1, second_slot_rel_off, "this_" + desc);
799  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
800  that_ptr1, second_slot_rel_off, "that_" + desc);
801  }
802  reduceOneSlot(this_ptr1,
803  this_ptr2,
804  that_ptr1,
805  that_ptr2,
806  target_info,
807  target_logical_idx,
808  j,
809  init_agg_val_idx,
810  j,
811  ir_reduce_one_entry);
812  if (target_logical_idx + 1 == targets_.size()) {
813  break;
814  }
816  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
817  } else {
818  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
819  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
820  }
821  }
822  j = advance_slot(j, target_info, false);
823  const auto next_desc =
824  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
825  auto next_slot_rel_off = ir_reduce_one_entry->addConstant<ConstantInt>(
826  init_agg_val_idx * sizeof(int64_t), Type::Int32);
827  this_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
828  this_targets_ptr_arg, next_slot_rel_off, next_desc);
829  that_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
830  that_targets_ptr_arg, next_slot_rel_off, next_desc);
831  }
832  ir_reduce_one_entry->add<Ret>(
833  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
834 }
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
void reduceOneSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
size_t targetGroupbyIndicesSize() const
Definition: sqldefs.h:72
const std::vector< TargetInfo > targets_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneEntryBaselineIdx()

void ResultSetReductionJIT::reduceOneEntryBaselineIdx ( const ReductionCode reduction_code) const
private

Definition at line 868 of file ResultSetReductionJIT.cpp.

References Cast::BitCast, CHECK, QueryMemoryDescriptor::didOutputColumnar(), get_row_bytes(), get_slot_off_quad(), QueryMemoryDescriptor::getGroupbyColCount(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByBaselineHash, QueryMemoryDescriptor::hasKeylessHash(), Int1, Int32, Int64Ptr, Int8, Int8Ptr, ReductionCode::ir_is_empty, ReductionCode::ir_reduce_one_entry, ReductionCode::ir_reduce_one_entry_idx, key_qw_count, BinaryOperator::Mul, query_mem_desc_, Cast::Trunc, and Void.

Referenced by codegen().

869  {
870  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
875  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
876  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
877  const auto that_entry_idx = ir_reduce_one_entry_idx->arg(2);
878  const auto that_entry_count = ir_reduce_one_entry_idx->arg(3);
879  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
880  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
881  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
882  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
884  const auto that_row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
885  BinaryOperator::BinaryOp::Mul, that_entry_idx, row_bytes, "that_row_off_in_bytes");
886  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
887  that_buff, that_row_off_in_bytes, "that_row_ptr");
888  const auto that_is_empty =
889  ir_reduce_one_entry_idx->add<Call>(reduction_code.ir_is_empty.get(),
890  std::vector<const Value*>{that_row_ptr},
891  "that_is_empty");
892  ir_reduce_one_entry_idx->add<ReturnEarly>(
893  that_is_empty,
894  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
895  "");
896  const auto key_count = query_mem_desc_.getGroupbyColCount();
897  const auto one_element =
898  ir_reduce_one_entry_idx->addConstant<ConstantInt>(1, Type::Int32);
899  const auto this_targets_ptr_i64_ptr = ir_reduce_one_entry_idx->add<Alloca>(
900  Type::Int64Ptr, one_element, "this_targets_ptr_out");
901  const auto this_is_empty_ptr =
902  ir_reduce_one_entry_idx->add<Alloca>(Type::Int8, one_element, "this_is_empty_out");
903  ir_reduce_one_entry_idx->add<ExternalCall>(
904  "get_group_value_reduction_rt",
905  Type::Void,
906  std::vector<const Value*>{
907  this_buff,
908  that_row_ptr,
909  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_count, Type::Int32),
910  this_qmd_handle,
911  that_buff,
912  that_entry_idx,
913  that_entry_count,
914  row_bytes,
915  this_targets_ptr_i64_ptr,
916  this_is_empty_ptr},
917  "");
918  const auto this_targets_ptr_i64 = ir_reduce_one_entry_idx->add<Load>(
919  this_targets_ptr_i64_ptr, "this_targets_ptr_i64");
920  auto this_is_empty =
921  ir_reduce_one_entry_idx->add<Load>(this_is_empty_ptr, "this_is_empty");
922  this_is_empty = ir_reduce_one_entry_idx->add<Cast>(
923  Cast::CastOp::Trunc, this_is_empty, Type::Int1, "this_is_empty_bool");
924  ir_reduce_one_entry_idx->add<ReturnEarly>(
925  this_is_empty,
926  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
927  "");
929  const auto this_targets_ptr = ir_reduce_one_entry_idx->add<Cast>(
930  Cast::CastOp::BitCast, this_targets_ptr_i64, Type::Int8Ptr, "this_targets_ptr");
931  const auto key_byte_count = key_qw_count * sizeof(int64_t);
932  const auto key_byte_count_lv =
933  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_byte_count, Type::Int32);
934  const auto that_targets_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
935  that_row_ptr, key_byte_count_lv, "that_targets_ptr");
936  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
937  reduction_code.ir_reduce_one_entry.get(),
938  std::vector<const Value*>{this_targets_ptr,
939  that_targets_ptr,
940  this_qmd_handle,
941  that_qmd_handle,
942  serialized_varlen_buffer_arg},
943  "");
944  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
945 }
size_t get_slot_off_quad(const QueryMemoryDescriptor &query_mem_desc)
std::unique_ptr< Function > ir_reduce_one_entry
const int64_t const uint32_t const uint32_t key_qw_count
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
std::unique_ptr< Function > ir_reduce_one_entry_idx
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
#define CHECK(condition)
Definition: Logger.h:193
QueryDescriptionType getQueryDescriptionType() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneEntryNoCollisions()

void ResultSetReductionJIT::reduceOneEntryNoCollisions ( const ReductionCode reduction_code) const
private

Definition at line 662 of file ResultSetReductionJIT.cpp.

References align_to_int64(), get_key_bytes_rowwise(), Int32, ReductionCode::ir_is_empty, ReductionCode::ir_reduce_one_entry, query_mem_desc_, and reduceOneEntryTargetsNoCollisions().

Referenced by codegen().

663  {
664  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
665  const auto this_row_ptr = ir_reduce_one_entry->arg(0);
666  const auto that_row_ptr = ir_reduce_one_entry->arg(1);
667  const auto that_is_empty =
668  ir_reduce_one_entry->add<Call>(reduction_code.ir_is_empty.get(),
669  std::vector<const Value*>{that_row_ptr},
670  "that_is_empty");
671  ir_reduce_one_entry->add<ReturnEarly>(
672  that_is_empty, ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32), "");
673 
674  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
675  if (key_bytes) { // copy the key from right hand side
676  ir_reduce_one_entry->add<MemCpy>(
677  this_row_ptr,
678  that_row_ptr,
679  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes, Type::Int32));
680  }
681 
682  const auto key_bytes_with_padding = align_to_int64(key_bytes);
683  const auto key_bytes_lv =
684  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes_with_padding, Type::Int32);
685  const auto this_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
686  this_row_ptr, key_bytes_lv, "this_targets_start");
687  const auto that_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
688  that_row_ptr, key_bytes_lv, "that_targets_start");
689 
691  ir_reduce_one_entry, this_targets_start_ptr, that_targets_start_ptr);
692 }
void reduceOneEntryTargetsNoCollisions(Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneEntryNoCollisionsIdx()

void ResultSetReductionJIT::reduceOneEntryNoCollisionsIdx ( const ReductionCode reduction_code) const
private

Definition at line 836 of file ResultSetReductionJIT.cpp.

References CHECK, get_row_bytes(), QueryMemoryDescriptor::getQueryDescriptionType(), GroupByPerfectHash, Int32, ReductionCode::ir_reduce_one_entry, ReductionCode::ir_reduce_one_entry_idx, BinaryOperator::Mul, NonGroupedAggregate, and query_mem_desc_.

Referenced by codegen().

837  {
838  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
843  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
844  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
845  const auto entry_idx = ir_reduce_one_entry_idx->arg(2);
846  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
847  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
848  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
849  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
851  const auto row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
852  BinaryOperator::BinaryOp::Mul, entry_idx, row_bytes, "row_off_in_bytes");
853  const auto this_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
854  this_buff, row_off_in_bytes, "this_row_ptr");
855  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
856  that_buff, row_off_in_bytes, "that_row_ptr");
857  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
858  reduction_code.ir_reduce_one_entry.get(),
859  std::vector<const Value*>{this_row_ptr,
860  that_row_ptr,
861  this_qmd_handle,
862  that_qmd_handle,
863  serialized_varlen_buffer_arg},
864  "");
865  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
866 }
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_reduce_one_entry_idx
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
#define CHECK(condition)
Definition: Logger.h:193
QueryDescriptionType getQueryDescriptionType() const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneEntryTargetsNoCollisions()

void ResultSetReductionJIT::reduceOneEntryTargetsNoCollisions ( Function ir_reduce_one_entry,
Value this_targets_start_ptr,
Value that_targets_start_ptr 
) const
private

Definition at line 694 of file ResultSetReductionJIT.cpp.

References QueryMemoryDescriptor::getColSlotContext(), QueryMemoryDescriptor::getPaddedSlotWidthBytes(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, kAVG, kSAMPLE, query_mem_desc_, reduceOneSlot(), QueryMemoryDescriptor::targetGroupbyIndicesSize(), targets_, to_string(), and UNLIKELY.

Referenced by reduceOneEntryNoCollisions().

697  {
698  const auto& col_slot_context = query_mem_desc_.getColSlotContext();
699  Value* this_targets_ptr = this_targets_start_ptr;
700  Value* that_targets_ptr = that_targets_start_ptr;
701  size_t init_agg_val_idx = 0;
702  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
703  ++target_logical_idx) {
704  const auto& target_info = targets_[target_logical_idx];
705  const auto& slots_for_col = col_slot_context.getSlotsForCol(target_logical_idx);
706  Value* this_ptr2{nullptr};
707  Value* that_ptr2{nullptr};
708 
709  bool two_slot_target{false};
710  if (target_info.is_agg &&
711  (target_info.agg_kind == kAVG ||
712  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
713  // Note that this assumes if one of the slot pairs in a given target is an array,
714  // all slot pairs are arrays. Currently this is true for all geo targets, but we
715  // should better codify and store this information in the future
716  two_slot_target = true;
717  }
718 
719  for (size_t target_slot_idx = slots_for_col.front();
720  target_slot_idx < slots_for_col.back() + 1;
721  target_slot_idx += 2) {
722  const auto slot_off_val = query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
723  const auto slot_off =
724  ir_reduce_one_entry->addConstant<ConstantInt>(slot_off_val, Type::Int32);
725  if (UNLIKELY(two_slot_target)) {
726  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
727  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
728  this_targets_ptr, slot_off, "this_" + desc);
729  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
730  that_targets_ptr, slot_off, "that_" + desc);
731  }
732  reduceOneSlot(this_targets_ptr,
733  this_ptr2,
734  that_targets_ptr,
735  that_ptr2,
736  target_info,
737  target_logical_idx,
738  target_slot_idx,
739  init_agg_val_idx,
740  slots_for_col.front(),
741  ir_reduce_one_entry);
742  auto increment_agg_val_idx_maybe =
743  [&init_agg_val_idx, &target_logical_idx, this](const int slot_count) {
745  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
746  init_agg_val_idx += slot_count;
747  }
748  };
749  if (target_logical_idx + 1 == targets_.size() &&
750  target_slot_idx + 1 >= slots_for_col.back()) {
751  break;
752  }
753  const auto next_desc =
754  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
755  if (UNLIKELY(two_slot_target)) {
756  increment_agg_val_idx_maybe(2);
757  const auto two_slot_off = ir_reduce_one_entry->addConstant<ConstantInt>(
758  slot_off_val + query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1),
759  Type::Int32);
760  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
761  this_targets_ptr, two_slot_off, "this_" + next_desc);
762  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
763  that_targets_ptr, two_slot_off, "that_" + next_desc);
764  } else {
765  increment_agg_val_idx_maybe(1);
766  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
767  this_targets_ptr, slot_off, "this_" + next_desc);
768  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
769  that_targets_ptr, slot_off, "that_" + next_desc);
770  }
771  }
772  }
773  ir_reduce_one_entry->add<Ret>(
774  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
775 }
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
void reduceOneSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const size_t init_agg_val_idx, const size_t first_slot_idx_for_target, Function *ir_reduce_one_entry) const
const QueryMemoryDescriptor query_mem_desc_
std::string to_string(char const *&&v)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
size_t targetGroupbyIndicesSize() const
#define UNLIKELY(x)
Definition: likely.h:20
const ColSlotContext & getColSlotContext() const
Definition: sqldefs.h:72
const std::vector< TargetInfo > targets_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reduceOneSlot()

void ResultSetReductionJIT::reduceOneSlot ( Value this_ptr1,
Value this_ptr2,
Value that_ptr1,
Value that_ptr2,
const TargetInfo target_info,
const size_t  target_logical_idx,
const size_t  target_slot_idx,
const size_t  init_agg_val_idx,
const size_t  first_slot_idx_for_target,
Function ir_reduce_one_entry 
) const
private

Definition at line 1023 of file ResultSetReductionJIT.cpp.

References TargetInfo::agg_kind, CHECK, CHECK_LT, anonymous_namespace{ResultSetReductionJIT.cpp}::emit_checked_write_projection(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), get_width_for_slot(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, Int64, TargetInfo::is_agg, SQLTypeInfoCore< TYPE_FACET_PACK >::is_geometry(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_varlen(), kSAMPLE, kSINGLE_VALUE, ICmp::NE, query_mem_desc_, reduceOneAggregateSlot(), TargetInfo::sql_type, takes_float_argument(), target_init_vals_, QueryMemoryDescriptor::targetGroupbyIndicesSize(), and Void.

Referenced by reduceOneEntryBaseline(), and reduceOneEntryTargetsNoCollisions().

1032  {
1034  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1035  return;
1036  }
1037  }
1038  const bool float_argument_input = takes_float_argument(target_info);
1039  const auto chosen_bytes =
1040  get_width_for_slot(target_slot_idx, float_argument_input, query_mem_desc_);
1041  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1042  auto init_val = target_init_vals_[init_agg_val_idx];
1043  if (target_info.is_agg &&
1044  (target_info.agg_kind != kSINGLE_VALUE && target_info.agg_kind != kSAMPLE)) {
1045  reduceOneAggregateSlot(this_ptr1,
1046  this_ptr2,
1047  that_ptr1,
1048  that_ptr2,
1049  target_info,
1050  target_logical_idx,
1051  target_slot_idx,
1052  init_val,
1053  chosen_bytes,
1054  ir_reduce_one_entry);
1055  } else if (target_info.agg_kind == kSINGLE_VALUE) {
1056  const auto checked_rc = emit_checked_write_projection(
1057  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1058 
1059  auto checked_rc_bool = ir_reduce_one_entry->add<ICmp>(
1061  checked_rc,
1062  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32),
1063  "");
1064 
1065  ir_reduce_one_entry->add<ReturnEarly>(checked_rc_bool, checked_rc, "");
1066 
1067  } else {
1069  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1070  if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
1071  CHECK(this_ptr2 && that_ptr2);
1072  size_t length_to_elems{0};
1073  if (target_info.sql_type.is_geometry()) {
1074  // TODO: Assumes hard-coded sizes for geometry targets
1075  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1076  } else {
1077  const auto& elem_ti = target_info.sql_type.get_elem_type();
1078  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1079  }
1080  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry->arg(4);
1081  ir_reduce_one_entry->add<ExternalCall>(
1082  "serialized_varlen_buffer_sample",
1083  Type::Void,
1084  std::vector<const Value*>{
1085  serialized_varlen_buffer_arg,
1086  this_ptr1,
1087  this_ptr2,
1088  that_ptr1,
1089  that_ptr2,
1090  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64),
1091  ir_reduce_one_entry->addConstant<ConstantInt>(length_to_elems,
1092  Type::Int64)},
1093  "");
1094  }
1095  }
1096 }
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
bool is_varlen() const
Definition: sqltypes.h:491
const std::vector< int64_t > target_init_vals_
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:121
const Value * emit_checked_write_projection(Value *slot_pi8, Value *other_pi8, const int64_t init_val, const size_t chosen_bytes, Function *ir_reduce_one_entry)
int8_t get_width_for_slot(const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
const QueryMemoryDescriptor query_mem_desc_
bool is_agg
Definition: TargetInfo.h:40
void emit_write_projection(Value *slot_pi8, Value *other_pi8, const int64_t init_val, const size_t chosen_bytes, Function *ir_reduce_one_entry)
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:659
size_t targetGroupbyIndicesSize() const
SQLAgg agg_kind
Definition: TargetInfo.h:41
#define CHECK_LT(x, y)
Definition: Logger.h:203
#define CHECK(condition)
Definition: Logger.h:193
bool is_geometry() const
Definition: sqltypes.h:489
bool is_string() const
Definition: sqltypes.h:477
void reduceOneAggregateSlot(Value *this_ptr1, Value *this_ptr2, Value *that_ptr1, Value *that_ptr2, const TargetInfo &target_info, const size_t target_logical_idx, const size_t target_slot_idx, const int64_t init_val, const int8_t chosen_bytes, Function *ir_reduce_one_entry) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ query_mem_desc_

◆ s_code_cache

CodeCache ResultSetReductionJIT::s_code_cache
staticprivate

Definition at line 132 of file ResultSetReductionJIT.h.

Referenced by clearCache(), codegen(), and finalizeReductionCode().

◆ target_init_vals_

const std::vector<int64_t> ResultSetReductionJIT::target_init_vals_
private

Definition at line 131 of file ResultSetReductionJIT.h.

Referenced by cacheKey(), isEmpty(), and reduceOneSlot().

◆ targets_

const std::vector<TargetInfo> ResultSetReductionJIT::targets_
private

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