OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ResultSetReductionJIT Class Reference

#include <ResultSetReductionJIT.h>

+ Inheritance diagram for ResultSetReductionJIT:
+ 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)
 
virtual ~ResultSetReductionJIT ()=default
 
virtual ReductionCode codegen () const
 

Static Public Member Functions

static void clearCache ()
 

Protected Member Functions

void isEmpty (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisions (const ReductionCode &reduction_code) const
 
void reduceOneEntryNoCollisionsIdx (const ReductionCode &reduction_code) const
 
void reduceLoop (const ReductionCode &reduction_code) const
 

Private Member Functions

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 reduceOneEntryBaselineIdx (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 55 of file ResultSetReductionJIT.h.

Constructor & Destructor Documentation

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_
virtual ResultSetReductionJIT::~ResultSetReductionJIT ( )
virtualdefault

Member Function Documentation

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

Definition at line 1243 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().

1243  {
1244  std::vector<std::string> target_init_vals_strings;
1245  std::transform(target_init_vals_.begin(),
1246  target_init_vals_.end(),
1247  std::back_inserter(target_init_vals_strings),
1248  [](const int64_t v) { return std::to_string(v); });
1249  const auto target_init_vals_key =
1250  boost::algorithm::join(target_init_vals_strings, ", ");
1251  std::vector<std::string> targets_strings;
1252  std::transform(
1253  targets_.begin(),
1254  targets_.end(),
1255  std::back_inserter(targets_strings),
1256  [](const TargetInfo& target_info) { return target_info_key(target_info); });
1257  const auto targets_key = boost::algorithm::join(targets_strings, ", ");
1258  return query_mem_desc_.reductionKey() + "\n" + target_init_vals_key + "\n" +
1259  targets_key;
1260 }
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:

void ResultSetReductionJIT::clearCache ( )
static

Definition at line 610 of file ResultSetReductionJIT.cpp.

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

610  {
611  // Clear stub cache to avoid crash caused by non-deterministic static destructor order
612  // of LLVM context and the cache.
615  g_rt_module = nullptr;
616 }
void clear()
Definition: LruCache.hpp:57
std::unique_ptr< llvm::Module > g_rt_module

+ Here is the call graph for this function:

ReductionCode ResultSetReductionJIT::codegen ( ) const
virtual

Reimplemented in GpuReductionHelperJIT.

Definition at line 531 of file ResultSetReductionJIT.cpp.

References QueryMemoryDescriptor::blocksShareMemory(), cacheKey(), cgen_state, CHECK(), 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, module(), 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 anonymous_namespace{Execute.cpp}::get_reduction_code(), and ResultSetManager::reduce().

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 compilation_context = s_code_cache.get(key);
563  if (compilation_context) {
564  auto cpu_context =
565  std::dynamic_pointer_cast<CpuCompilationContext>(compilation_context->first);
566  CHECK(cpu_context);
567  return {reinterpret_cast<ReductionCode::FuncPtr>(cpu_context->func()),
568  nullptr,
569  nullptr,
570  nullptr,
571  std::move(reduction_code.ir_is_empty),
572  std::move(reduction_code.ir_reduce_one_entry),
573  std::move(reduction_code.ir_reduce_one_entry_idx),
574  std::move(reduction_code.ir_reduce_loop)};
575  }
576  reduction_code.cgen_state.reset(new CgenState({}, false));
577  auto cgen_state = reduction_code.cgen_state.get();
578  std::unique_ptr<llvm::Module> module = runtime_module_shallow_copy(cgen_state);
579  cgen_state->module_ = module.get();
580  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
581  auto ir_reduce_one_entry =
582  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
583  auto ir_reduce_one_entry_idx =
584  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
585  auto ir_reduce_loop =
586  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
587  std::unordered_map<const Function*, llvm::Function*> f;
588  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
589  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
590  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
591  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
592  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
594  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
595  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
596  ir_reduce_one_entry_idx,
597  reduction_code,
598  f);
600  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
601  reduction_code.llvm_reduce_loop = ir_reduce_loop;
602  reduction_code.module = std::move(module);
603  return finalizeReductionCode(std::move(reduction_code),
604  ir_is_empty,
605  ir_reduce_one_entry,
606  ir_reduce_one_entry_idx,
607  key);
608 }
bool is_aggregate_query(const QueryDescriptionType hash_type)
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
std::unique_ptr< llvm::Module > runtime_module_shallow_copy(CgenState *cgen_state)
void reduceOneEntryNoCollisions(const ReductionCode &reduction_code) const
void reduceOneEntryBaselineIdx(const ReductionCode &reduction_code) const
#define LOG(tag)
Definition: Logger.h:188
void reduceLoop(const ReductionCode &reduction_code) const
void reduceOneEntryNoCollisionsIdx(const ReductionCode &reduction_code) const
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:25
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
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_
void translate_function(const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, const std::unordered_map< const Function *, llvm::Function * > &f)
false auto cgen_state
CHECK(cgen_state)
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)
QueryDescriptionType getQueryDescriptionType() const
void isEmpty(const ReductionCode &reduction_code) const
void reduceOneEntryBaseline(const ReductionCode &reduction_code) const
value_t * get(const key_t &key)
Definition: LruCache.hpp:39
const Executor * getExecutor() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 1196 of file ResultSetReductionJIT.cpp.

References CPU, CodeGenerator::generateNativeCPUCode(), logger::IR, ReductionCode::llvm_reduce_loop, LOG, ReductionCode::module, ReductionJIT, and serialize_llvm_object().

Referenced by codegen().

1201  {
1202  CompilationOptions co{
1204 
1205  LOG(IR) << "Reduction Loop:\n"
1206  << serialize_llvm_object(reduction_code.llvm_reduce_loop);
1207  LOG(IR) << "Reduction Is Empty Func:\n" << serialize_llvm_object(ir_is_empty);
1208  LOG(IR) << "Reduction One Entry Func:\n" << serialize_llvm_object(ir_reduce_one_entry);
1209  LOG(IR) << "Reduction One Entry Idx Func:\n"
1210  << serialize_llvm_object(ir_reduce_one_entry_idx);
1211 
1212  reduction_code.module.release();
1214  reduction_code.llvm_reduce_loop, {reduction_code.llvm_reduce_loop}, co);
1215  reduction_code.func_ptr = reinterpret_cast<ReductionCode::FuncPtr>(
1216  ee->getPointerToFunction(reduction_code.llvm_reduce_loop));
1217 
1218  auto cpu_compilation_context = std::make_shared<CpuCompilationContext>(std::move(ee));
1219  cpu_compilation_context->setFunctionPointer(reduction_code.llvm_reduce_loop);
1220  reduction_code.compilation_context = cpu_compilation_context;
1222  reduction_code.compilation_context,
1223  reduction_code.llvm_reduce_loop->getParent(),
1224  s_code_cache);
1225  return reduction_code;
1226 }
std::shared_ptr< CompilationContext > compilation_context
#define LOG(tag)
Definition: Logger.h:188
llvm::Function * llvm_reduce_loop
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
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
static void addCodeToCache(const CodeCacheKey &, std::shared_ptr< CompilationContext >, llvm::Module *, CodeCache &)
std::string serialize_llvm_object(const T *llvm_obj)
std::unique_ptr< llvm::Module > module

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 618 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(), and GpuReductionHelperJIT::codegen().

618  {
619  auto ir_is_empty = reduction_code.ir_is_empty.get();
622  Value* key{nullptr};
623  Value* empty_key_val{nullptr};
624  const auto keys_ptr = ir_is_empty->arg(0);
629  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
630  target_init_vals_.size());
631  const int64_t target_slot_off =
633  const auto slot_ptr = ir_is_empty->add<GetElementPtr>(
634  keys_ptr,
635  ir_is_empty->addConstant<ConstantInt>(target_slot_off, Type::Int32),
636  "is_empty_slot_ptr");
637  const auto compact_sz =
639  key = emit_read_int_from_buff(slot_ptr, compact_sz, ir_is_empty);
640  empty_key_val = ir_is_empty->addConstant<ConstantInt>(
642  } else {
644  case 4: {
647  key = emit_load_i32(keys_ptr, ir_is_empty);
648  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_32, Type::Int32);
649  break;
650  }
651  case 8: {
652  key = emit_load_i64(keys_ptr, ir_is_empty);
653  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_64, Type::Int64);
654  break;
655  }
656  default:
657  LOG(FATAL) << "Invalid key width";
658  }
659  }
660  const auto ret =
661  ir_is_empty->add<ICmp>(ICmp::Predicate::EQ, key, empty_key_val, "is_key_empty");
662  ir_is_empty->add<Ret>(ret);
663 }
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:210
size_t getEffectiveKeyWidth() const
const std::vector< int64_t > target_init_vals_
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
Value * emit_load_i32(Value *ptr, Function *function)
CHECK(cgen_state)
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
QueryDescriptionType getQueryDescriptionType() const
#define CHECK_LT(x, y)
Definition: Logger.h:207
Value * emit_load_i64(Value *ptr, Function *function)
#define EMPTY_KEY_32
int32_t getTargetIdxForKey() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 1008 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(), and GpuReductionHelperJIT::codegen().

1008  {
1009  auto ir_reduce_loop = reduction_code.ir_reduce_loop.get();
1010  const auto this_buff_arg = ir_reduce_loop->arg(0);
1011  const auto that_buff_arg = ir_reduce_loop->arg(1);
1012  const auto start_index_arg = ir_reduce_loop->arg(2);
1013  const auto end_index_arg = ir_reduce_loop->arg(3);
1014  const auto that_entry_count_arg = ir_reduce_loop->arg(4);
1015  const auto this_qmd_handle_arg = ir_reduce_loop->arg(5);
1016  const auto that_qmd_handle_arg = ir_reduce_loop->arg(6);
1017  const auto serialized_varlen_buffer_arg = ir_reduce_loop->arg(7);
1018  For* for_loop =
1019  static_cast<For*>(ir_reduce_loop->add<For>(start_index_arg, end_index_arg, ""));
1020  generate_loop_body(for_loop,
1021  ir_reduce_loop,
1022  reduction_code.ir_reduce_one_entry_idx.get(),
1023  this_buff_arg,
1024  that_buff_arg,
1025  start_index_arg,
1026  that_entry_count_arg,
1027  this_qmd_handle_arg,
1028  that_qmd_handle_arg,
1029  serialized_varlen_buffer_arg);
1030  ir_reduce_loop->add<Ret>(ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32));
1031 }
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:

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 1108 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().

1117  {
1118  switch (target_info.agg_kind) {
1119  case kCOUNT:
1120  case kAPPROX_COUNT_DISTINCT: {
1121  if (is_distinct_target(target_info)) {
1122  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1124  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1125  break;
1126  }
1127  CHECK_EQ(int64_t(0), init_val);
1128  emit_aggregate_one_count(this_ptr1, that_ptr1, chosen_bytes, ir_reduce_one_entry);
1129  break;
1130  }
1131  case kAVG: {
1132  // Ignore float argument compaction for count component for fear of its overflow
1133  emit_aggregate_one_count(this_ptr2,
1134  that_ptr2,
1135  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx),
1136  ir_reduce_one_entry);
1137  }
1138  // fall thru
1139  case kSUM: {
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 kMIN: {
1151  this_ptr1,
1152  that_ptr1,
1153  init_val,
1154  chosen_bytes,
1155  target_info,
1156  ir_reduce_one_entry);
1157  break;
1158  }
1159  case kMAX: {
1161  this_ptr1,
1162  that_ptr1,
1163  init_val,
1164  chosen_bytes,
1165  target_info,
1166  ir_reduce_one_entry);
1167  break;
1168  }
1169  default:
1170  LOG(FATAL) << "Invalid aggregate type";
1171  }
1172 }
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:205
#define LOG(tag)
Definition: Logger.h:188
const QueryMemoryDescriptor query_mem_desc_
Definition: sqldefs.h:73
void reduceOneCountDistinctSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
Definition: sqldefs.h:75
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:129
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
SQLAgg agg_kind
Definition: TargetInfo.h:41
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:

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 1174 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().

1178  {
1180  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1181  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1182  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1183  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1184  ir_reduce_one_entry->add<ExternalCall>(
1185  "count_distinct_set_union_jit_rt",
1186  Type::Void,
1187  std::vector<const Value*>{
1188  new_set_handle,
1189  old_set_handle,
1190  that_qmd_arg,
1191  this_qmd_arg,
1192  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1193  "");
1194 }
const QueryMemoryDescriptor query_mem_desc_
size_t getCountDistinctDescriptorsSize() const
#define CHECK_LT(x, y)
Definition: Logger.h:207
Value * emit_load_i64(Value *ptr, Function *function)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 780 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().

781  {
782  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
783  const auto this_targets_ptr_arg = ir_reduce_one_entry->arg(0);
784  const auto that_targets_ptr_arg = ir_reduce_one_entry->arg(1);
785  Value* this_ptr1 = this_targets_ptr_arg;
786  Value* that_ptr1 = that_targets_ptr_arg;
787  size_t j = 0;
788  size_t init_agg_val_idx = 0;
789  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
790  ++target_logical_idx) {
791  const auto& target_info = targets_[target_logical_idx];
792  Value* this_ptr2{nullptr};
793  Value* that_ptr2{nullptr};
794  if (target_info.is_agg &&
795  (target_info.agg_kind == kAVG ||
796  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
797  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
798  const auto second_slot_rel_off =
799  ir_reduce_one_entry->addConstant<ConstantInt>(sizeof(int64_t), Type::Int32);
800  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
801  this_ptr1, second_slot_rel_off, "this_" + desc);
802  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
803  that_ptr1, second_slot_rel_off, "that_" + desc);
804  }
805  reduceOneSlot(this_ptr1,
806  this_ptr2,
807  that_ptr1,
808  that_ptr2,
809  target_info,
810  target_logical_idx,
811  j,
812  init_agg_val_idx,
813  j,
814  ir_reduce_one_entry);
815  if (target_logical_idx + 1 == targets_.size()) {
816  break;
817  }
819  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
820  } else {
821  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
822  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
823  }
824  }
825  j = advance_slot(j, target_info, false);
826  const auto next_desc =
827  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
828  auto next_slot_rel_off = ir_reduce_one_entry->addConstant<ConstantInt>(
829  init_agg_val_idx * sizeof(int64_t), Type::Int32);
830  this_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
831  this_targets_ptr_arg, next_slot_rel_off, next_desc);
832  that_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
833  that_targets_ptr_arg, next_slot_rel_off, next_desc);
834  }
835  ir_reduce_one_entry->add<Ret>(
836  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
837 }
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
ssize_t getTargetGroupbyIndex(const size_t target_idx) 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:

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

Definition at line 873 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, Int64, 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::SExt, Cast::Trunc, and Void.

Referenced by codegen().

874  {
875  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
880  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
881  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
882  const auto that_entry_idx = ir_reduce_one_entry_idx->arg(2);
883  const auto that_entry_count = ir_reduce_one_entry_idx->arg(3);
884  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
885  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
886  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
887  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
889  const auto that_entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
890  Cast::CastOp::SExt, that_entry_idx, Type::Int64, "that_entry_idx_64");
891  const auto that_row_off_in_bytes =
892  ir_reduce_one_entry_idx->add<BinaryOperator>(BinaryOperator::BinaryOp::Mul,
893  that_entry_idx_64,
894  row_bytes,
895  "that_row_off_in_bytes");
896  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
897  that_buff, that_row_off_in_bytes, "that_row_ptr");
898  const auto that_is_empty =
899  ir_reduce_one_entry_idx->add<Call>(reduction_code.ir_is_empty.get(),
900  std::vector<const Value*>{that_row_ptr},
901  "that_is_empty");
902  ir_reduce_one_entry_idx->add<ReturnEarly>(
903  that_is_empty,
904  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
905  "");
906  const auto key_count = query_mem_desc_.getGroupbyColCount();
907  const auto one_element =
908  ir_reduce_one_entry_idx->addConstant<ConstantInt>(1, Type::Int32);
909  const auto this_targets_ptr_i64_ptr = ir_reduce_one_entry_idx->add<Alloca>(
910  Type::Int64Ptr, one_element, "this_targets_ptr_out");
911  const auto this_is_empty_ptr =
912  ir_reduce_one_entry_idx->add<Alloca>(Type::Int8, one_element, "this_is_empty_out");
913  ir_reduce_one_entry_idx->add<ExternalCall>(
914  "get_group_value_reduction_rt",
915  Type::Void,
916  std::vector<const Value*>{
917  this_buff,
918  that_row_ptr,
919  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_count, Type::Int32),
920  this_qmd_handle,
921  that_buff,
922  that_entry_idx,
923  that_entry_count,
924  row_bytes,
925  this_targets_ptr_i64_ptr,
926  this_is_empty_ptr},
927  "");
928  const auto this_targets_ptr_i64 = ir_reduce_one_entry_idx->add<Load>(
929  this_targets_ptr_i64_ptr, "this_targets_ptr_i64");
930  auto this_is_empty =
931  ir_reduce_one_entry_idx->add<Load>(this_is_empty_ptr, "this_is_empty");
932  this_is_empty = ir_reduce_one_entry_idx->add<Cast>(
933  Cast::CastOp::Trunc, this_is_empty, Type::Int1, "this_is_empty_bool");
934  ir_reduce_one_entry_idx->add<ReturnEarly>(
935  this_is_empty,
936  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
937  "");
939  const auto this_targets_ptr = ir_reduce_one_entry_idx->add<Cast>(
940  Cast::CastOp::BitCast, this_targets_ptr_i64, Type::Int8Ptr, "this_targets_ptr");
941  const auto key_byte_count = key_qw_count * sizeof(int64_t);
942  const auto key_byte_count_lv =
943  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_byte_count, Type::Int32);
944  const auto that_targets_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
945  that_row_ptr, key_byte_count_lv, "that_targets_ptr");
946  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
947  reduction_code.ir_reduce_one_entry.get(),
948  std::vector<const Value*>{this_targets_ptr,
949  that_targets_ptr,
950  this_qmd_handle,
951  that_qmd_handle,
952  serialized_varlen_buffer_arg},
953  "");
954  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
955 }
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
CHECK(cgen_state)
size_t getGroupbyColCount() const
std::unique_ptr< Function > ir_reduce_one_entry_idx
QueryDescriptionType getQueryDescriptionType() const
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 665 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(), and GpuReductionHelperJIT::codegen().

666  {
667  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
668  const auto this_row_ptr = ir_reduce_one_entry->arg(0);
669  const auto that_row_ptr = ir_reduce_one_entry->arg(1);
670  const auto that_is_empty =
671  ir_reduce_one_entry->add<Call>(reduction_code.ir_is_empty.get(),
672  std::vector<const Value*>{that_row_ptr},
673  "that_is_empty");
674  ir_reduce_one_entry->add<ReturnEarly>(
675  that_is_empty, ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32), "");
676 
677  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
678  if (key_bytes) { // copy the key from right hand side
679  ir_reduce_one_entry->add<MemCpy>(
680  this_row_ptr,
681  that_row_ptr,
682  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes, Type::Int32));
683  }
684 
685  const auto key_bytes_with_padding = align_to_int64(key_bytes);
686  const auto key_bytes_lv =
687  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes_with_padding, Type::Int32);
688  const auto this_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
689  this_row_ptr, key_bytes_lv, "this_targets_start");
690  const auto that_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
691  that_row_ptr, key_bytes_lv, "that_targets_start");
692 
694  ir_reduce_one_entry, this_targets_start_ptr, that_targets_start_ptr);
695 }
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
std::unique_ptr< Function > ir_is_empty
void reduceOneEntryTargetsNoCollisions(Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
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:

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

Definition at line 839 of file ResultSetReductionJIT.cpp.

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

Referenced by codegen(), and GpuReductionHelperJIT::codegen().

840  {
841  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
846  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
847  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
848  const auto entry_idx = ir_reduce_one_entry_idx->arg(2);
849  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
850  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
851  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
852  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
854  const auto entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
855  Cast::CastOp::SExt, entry_idx, Type::Int64, "entry_idx_64");
856  const auto row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
857  BinaryOperator::BinaryOp::Mul, entry_idx_64, row_bytes, "row_off_in_bytes");
858  const auto this_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
859  this_buff, row_off_in_bytes, "this_row_ptr");
860  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
861  that_buff, row_off_in_bytes, "that_row_ptr");
862  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
863  reduction_code.ir_reduce_one_entry.get(),
864  std::vector<const Value*>{this_row_ptr,
865  that_row_ptr,
866  this_qmd_handle,
867  that_qmd_handle,
868  serialized_varlen_buffer_arg},
869  "");
870  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
871 }
std::unique_ptr< Function > ir_reduce_one_entry
const QueryMemoryDescriptor query_mem_desc_
CHECK(cgen_state)
std::unique_ptr< Function > ir_reduce_one_entry_idx
QueryDescriptionType getQueryDescriptionType() const
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 697 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().

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

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 1033 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(), SQLTypeInfo::get_elem_type(), get_width_for_slot(), QueryMemoryDescriptor::getTargetGroupbyIndex(), Int32, Int64, TargetInfo::is_agg, SQLTypeInfo::is_geometry(), SQLTypeInfo::is_string(), SQLTypeInfo::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().

1042  {
1044  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1045  return;
1046  }
1047  }
1048  const bool float_argument_input = takes_float_argument(target_info);
1049  const auto chosen_bytes =
1050  get_width_for_slot(target_slot_idx, float_argument_input, query_mem_desc_);
1051  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1052  auto init_val = target_init_vals_[init_agg_val_idx];
1053  if (target_info.is_agg &&
1054  (target_info.agg_kind != kSINGLE_VALUE && target_info.agg_kind != kSAMPLE)) {
1055  reduceOneAggregateSlot(this_ptr1,
1056  this_ptr2,
1057  that_ptr1,
1058  that_ptr2,
1059  target_info,
1060  target_logical_idx,
1061  target_slot_idx,
1062  init_val,
1063  chosen_bytes,
1064  ir_reduce_one_entry);
1065  } else if (target_info.agg_kind == kSINGLE_VALUE) {
1066  const auto checked_rc = emit_checked_write_projection(
1067  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1068 
1069  auto checked_rc_bool = ir_reduce_one_entry->add<ICmp>(
1071  checked_rc,
1072  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32),
1073  "");
1074 
1075  ir_reduce_one_entry->add<ReturnEarly>(checked_rc_bool, checked_rc, "");
1076 
1077  } else {
1079  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1080  if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
1081  CHECK(this_ptr2 && that_ptr2);
1082  size_t length_to_elems{0};
1083  if (target_info.sql_type.is_geometry()) {
1084  // TODO: Assumes hard-coded sizes for geometry targets
1085  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1086  } else {
1087  const auto& elem_ti = target_info.sql_type.get_elem_type();
1088  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1089  }
1090  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry->arg(4);
1091  ir_reduce_one_entry->add<ExternalCall>(
1092  "serialized_varlen_buffer_sample",
1093  Type::Void,
1094  std::vector<const Value*>{
1095  serialized_varlen_buffer_arg,
1096  this_ptr1,
1097  this_ptr2,
1098  that_ptr1,
1099  that_ptr2,
1100  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64),
1101  ir_reduce_one_entry->addConstant<ConstantInt>(length_to_elems,
1102  Type::Int64)},
1103  "");
1104  }
1105  }
1106 }
SQLTypeInfo sql_type
Definition: TargetInfo.h:42
bool is_varlen() const
Definition: sqltypes.h:430
const std::vector< int64_t > target_init_vals_
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
bool takes_float_argument(const TargetInfo &target_info)
Definition: TargetInfo.h:133
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
CHECK(cgen_state)
size_t targetGroupbyIndicesSize() const
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)
SQLAgg agg_kind
Definition: TargetInfo.h:41
ssize_t getTargetGroupbyIndex(const size_t target_idx) const
#define CHECK_LT(x, y)
Definition: Logger.h:207
bool is_geometry() const
Definition: sqltypes.h:427
bool is_string() const
Definition: sqltypes.h:415
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:622

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

CodeCache ResultSetReductionJIT::s_code_cache
staticprivate

Definition at line 134 of file ResultSetReductionJIT.h.

Referenced by clearCache(), and codegen().

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

Definition at line 133 of file ResultSetReductionJIT.h.

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

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

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