OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ResultSetReductionJIT.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ResultSetReductionJIT.h"
20 
21 #include "CodeGenerator.h"
22 #include "DynamicWatchdog.h"
23 #include "Execute.h"
24 #include "IRCodegenUtils.h"
27 #include "Shared/likely.h"
28 #include "Shared/quantile.h"
29 
30 #include <llvm/Bitcode/BitcodeReader.h>
31 #include <llvm/IR/Function.h>
32 #include <llvm/IR/IRBuilder.h>
33 #include <llvm/IR/Verifier.h>
34 #include <llvm/Support/SourceMgr.h>
35 #include <llvm/Support/raw_os_ostream.h>
36 
37 namespace {
38 
39 // Error code to be returned when the watchdog timer triggers during the reduction.
40 const int32_t WATCHDOG_ERROR{-1};
41 // Error code to be returned when the interrupt is triggered during the reduction.
42 const int32_t INTERRUPT_ERROR{10};
43 // Use the interpreter, not the JIT, for a number of entries lower than the threshold.
44 const size_t INTERP_THRESHOLD{25};
45 
46 // Load the value stored at 'ptr' interpreted as 'ptr_type'.
47 Value* emit_load(Value* ptr, Type ptr_type, Function* function) {
48  return function->add<Load>(
49  function->add<Cast>(Cast::CastOp::BitCast, ptr, ptr_type, ""),
50  ptr->label() + "_loaded");
51 }
52 
53 // Load the value stored at 'ptr' as a 32-bit signed integer.
54 Value* emit_load_i32(Value* ptr, Function* function) {
55  return emit_load(ptr, Type::Int32Ptr, function);
56 }
57 
58 // Load the value stored at 'ptr' as a 64-bit signed integer.
59 Value* emit_load_i64(Value* ptr, Function* function) {
60  return emit_load(ptr, Type::Int64Ptr, function);
61 }
62 
63 // Read a 32- or 64-bit integer stored at 'ptr' and sign extend to 64-bit.
64 Value* emit_read_int_from_buff(Value* ptr, const int8_t compact_sz, Function* function) {
65  switch (compact_sz) {
66  case 8: {
67  return emit_load_i64(ptr, function);
68  }
69  case 4: {
70  const auto loaded_val = emit_load_i32(ptr, function);
71  return function->add<Cast>(Cast::CastOp::SExt, loaded_val, Type::Int64, "");
72  }
73  default: {
74  LOG(FATAL) << "Invalid byte width: " << compact_sz;
75  return nullptr;
76  }
77  }
78 }
79 
80 // Emit a runtime call to accumulate into the 'val_ptr' byte address the 'other_ptr'
81 // value when the type is specified as not null.
82 void emit_aggregate_one_value(const std::string& agg_kind,
83  Value* val_ptr,
84  Value* other_ptr,
85  const size_t chosen_bytes,
86  const TargetInfo& agg_info,
87  Function* ir_reduce_one_entry) {
88  const auto sql_type = get_compact_type(agg_info);
89  const auto dest_name = agg_kind + "_dest";
90  if (sql_type.is_fp()) {
91  if (chosen_bytes == sizeof(float)) {
92  const auto agg = ir_reduce_one_entry->add<Cast>(
93  Cast::CastOp::BitCast, val_ptr, Type::Int32Ptr, dest_name);
94  const auto val = emit_load(other_ptr, Type::FloatPtr, ir_reduce_one_entry);
95  ir_reduce_one_entry->add<Call>(
96  "agg_" + agg_kind + "_float", std::vector<const Value*>{agg, val}, "");
97  } else {
98  CHECK_EQ(chosen_bytes, sizeof(double));
99  const auto agg = ir_reduce_one_entry->add<Cast>(
100  Cast::CastOp::BitCast, val_ptr, Type::Int64Ptr, dest_name);
101  const auto val = emit_load(other_ptr, Type::DoublePtr, ir_reduce_one_entry);
102  ir_reduce_one_entry->add<Call>(
103  "agg_" + agg_kind + "_double", std::vector<const Value*>{agg, val}, "");
104  }
105  } else {
106  if (chosen_bytes == sizeof(int32_t)) {
107  const auto agg = ir_reduce_one_entry->add<Cast>(
108  Cast::CastOp::BitCast, val_ptr, Type::Int32Ptr, dest_name);
109  const auto val = emit_load(other_ptr, Type::Int32Ptr, ir_reduce_one_entry);
110  ir_reduce_one_entry->add<Call>(
111  "agg_" + agg_kind + "_int32", std::vector<const Value*>{agg, val}, "");
112  } else {
113  CHECK_EQ(chosen_bytes, sizeof(int64_t));
114  const auto agg = ir_reduce_one_entry->add<Cast>(
115  Cast::CastOp::BitCast, val_ptr, Type::Int64Ptr, dest_name);
116  const auto val = emit_load(other_ptr, Type::Int64Ptr, ir_reduce_one_entry);
117  ir_reduce_one_entry->add<Call>(
118  "agg_" + agg_kind, std::vector<const Value*>{agg, val}, "");
119  }
120  }
121 }
122 
123 // Same as above, but support nullable types as well.
124 void emit_aggregate_one_nullable_value(const std::string& agg_kind,
125  Value* val_ptr,
126  Value* other_ptr,
127  const int64_t init_val,
128  const size_t chosen_bytes,
129  const TargetInfo& agg_info,
130  Function* ir_reduce_one_entry) {
131  const auto dest_name = agg_kind + "_dest";
132  if (agg_info.skip_null_val) {
133  const auto sql_type = get_compact_type(agg_info);
134  if (sql_type.is_fp()) {
135  if (chosen_bytes == sizeof(float)) {
136  const auto agg = ir_reduce_one_entry->add<Cast>(
137  Cast::CastOp::BitCast, val_ptr, Type::Int32Ptr, dest_name);
138  const auto val = emit_load(other_ptr, Type::FloatPtr, ir_reduce_one_entry);
139  const auto init_val_lv = ir_reduce_one_entry->addConstant<ConstantFP>(
140  *reinterpret_cast<const float*>(may_alias_ptr(&init_val)), Type::Float);
141  ir_reduce_one_entry->add<Call>("agg_" + agg_kind + "_float_skip_val",
142  std::vector<const Value*>{agg, val, init_val_lv},
143  "");
144  } else {
145  CHECK_EQ(chosen_bytes, sizeof(double));
146  const auto agg = ir_reduce_one_entry->add<Cast>(
147  Cast::CastOp::BitCast, val_ptr, Type::Int64Ptr, dest_name);
148  const auto val = emit_load(other_ptr, Type::DoublePtr, ir_reduce_one_entry);
149  const auto init_val_lv = ir_reduce_one_entry->addConstant<ConstantFP>(
150  *reinterpret_cast<const double*>(may_alias_ptr(&init_val)), Type::Double);
151  ir_reduce_one_entry->add<Call>("agg_" + agg_kind + "_double_skip_val",
152  std::vector<const Value*>{agg, val, init_val_lv},
153  "");
154  }
155  } else {
156  if (chosen_bytes == sizeof(int32_t)) {
157  const auto agg = ir_reduce_one_entry->add<Cast>(
158  Cast::CastOp::BitCast, val_ptr, Type::Int32Ptr, dest_name);
159  const auto val = emit_load(other_ptr, Type::Int32Ptr, ir_reduce_one_entry);
160  const auto init_val_lv =
161  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int32);
162  ir_reduce_one_entry->add<Call>("agg_" + agg_kind + "_int32_skip_val",
163  std::vector<const Value*>{agg, val, init_val_lv},
164  "");
165  } else {
166  CHECK_EQ(chosen_bytes, sizeof(int64_t));
167  const auto agg = ir_reduce_one_entry->add<Cast>(
168  Cast::CastOp::BitCast, val_ptr, Type::Int64Ptr, dest_name);
169  const auto val = emit_load(other_ptr, Type::Int64Ptr, ir_reduce_one_entry);
170  const auto init_val_lv =
171  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64);
172  ir_reduce_one_entry->add<Call>("agg_" + agg_kind + "_skip_val",
173  std::vector<const Value*>{agg, val, init_val_lv},
174  "");
175  }
176  }
177  } else {
179  agg_kind, val_ptr, other_ptr, chosen_bytes, agg_info, ir_reduce_one_entry);
180  }
181 }
182 
183 // Emit code to accumulate the 'other_ptr' count into the 'val_ptr' destination.
185  Value* other_ptr,
186  const size_t chosen_bytes,
187  Function* ir_reduce_one_entry) {
188  const auto dest_name = "count_dest";
189  if (chosen_bytes == sizeof(int32_t)) {
190  const auto agg = ir_reduce_one_entry->add<Cast>(
191  Cast::CastOp::BitCast, val_ptr, Type::Int32Ptr, dest_name);
192  const auto val = emit_load(other_ptr, Type::Int32Ptr, ir_reduce_one_entry);
193  ir_reduce_one_entry->add<Call>(
194  "agg_sum_int32", std::vector<const Value*>{agg, val}, "");
195  } else {
196  CHECK_EQ(chosen_bytes, sizeof(int64_t));
197  const auto agg = ir_reduce_one_entry->add<Cast>(
198  Cast::CastOp::BitCast, val_ptr, Type::Int64Ptr, dest_name);
199  const auto val = emit_load(other_ptr, Type::Int64Ptr, ir_reduce_one_entry);
200  ir_reduce_one_entry->add<Call>("agg_sum", std::vector<const Value*>{agg, val}, "");
201  }
202 }
203 
204 // Emit code to load the value stored at the 'other_pi8' as an integer of the given width
205 // 'chosen_bytes' and write it to the 'slot_pi8' destination only if necessary (the
206 // existing value at destination is the initialization value).
208  Value* other_pi8,
209  const int64_t init_val,
210  const size_t chosen_bytes,
211  Function* ir_reduce_one_entry) {
212  const auto func_name = "write_projection_int" + std::to_string(chosen_bytes * 8);
213  if (chosen_bytes == sizeof(int32_t)) {
214  const auto proj_val = emit_load_i32(other_pi8, ir_reduce_one_entry);
215  ir_reduce_one_entry->add<Call>(
216  func_name,
217  std::vector<const Value*>{
218  slot_pi8,
219  proj_val,
220  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64)},
221  "");
222  } else {
223  CHECK_EQ(chosen_bytes, sizeof(int64_t));
224  const auto proj_val = emit_load_i64(other_pi8, ir_reduce_one_entry);
225  ir_reduce_one_entry->add<Call>(
226  func_name,
227  std::vector<const Value*>{
228  slot_pi8,
229  proj_val,
230  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64)},
231  "");
232  }
233 }
234 
235 // Emit code to load the value stored at the 'other_pi8' as an integer of the given width
236 // 'chosen_bytes' and write it to the 'slot_pi8' destination only if necessary (the
237 // existing value at destination is the initialization value).
239  Value* other_pi8,
240  const int64_t init_val,
241  const size_t chosen_bytes,
242  Function* ir_reduce_one_entry) {
243  if (chosen_bytes == sizeof(int32_t)) {
244  const auto func_name = "checked_single_agg_id_int32";
245  const auto proj_val = emit_load_i32(other_pi8, ir_reduce_one_entry);
246  const auto slot_pi32 = ir_reduce_one_entry->add<Cast>(
247  Cast::CastOp::BitCast, slot_pi8, Type::Int32Ptr, "");
248  return ir_reduce_one_entry->add<Call>(
249  func_name,
250  Type::Int32,
251  std::vector<const Value*>{
252  slot_pi32,
253  proj_val,
254  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int32)},
255  "");
256  } else {
257  const auto func_name = "checked_single_agg_id";
258  CHECK_EQ(chosen_bytes, sizeof(int64_t));
259  const auto proj_val = emit_load_i64(other_pi8, ir_reduce_one_entry);
260  const auto slot_pi64 = ir_reduce_one_entry->add<Cast>(
261  Cast::CastOp::BitCast, slot_pi8, Type::Int64Ptr, "");
262 
263  return ir_reduce_one_entry->add<Call>(
264  func_name,
265  Type::Int32,
266  std::vector<const Value*>{
267  slot_pi64,
268  proj_val,
269  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64)},
270  "");
271  }
272 }
273 
274 std::unique_ptr<Function> create_function(
275  const std::string name,
276  const std::vector<Function::NamedArg>& arg_types,
277  const Type ret_type,
278  const bool always_inline) {
279  return std::make_unique<Function>(name, arg_types, ret_type, always_inline);
280 }
281 
282 // Create the declaration for the 'is_empty_entry' function. Use private linkage since
283 // it's a helper only called from the generated code and mark it as always inline.
284 std::unique_ptr<Function> setup_is_empty_entry(ReductionCode* reduction_code) {
285  return create_function(
286  "is_empty_entry", {{"row_ptr", Type::Int8Ptr}}, Type::Int1, /*always_inline=*/true);
287 }
288 
289 // Create the declaration for the 'reduce_one_entry' helper.
290 std::unique_ptr<Function> setup_reduce_one_entry(ReductionCode* reduction_code,
291  const QueryDescriptionType hash_type) {
292  std::string this_ptr_name;
293  std::string that_ptr_name;
294  switch (hash_type) {
296  this_ptr_name = "this_targets_ptr";
297  that_ptr_name = "that_targets_ptr";
298  break;
299  }
302  this_ptr_name = "this_row_ptr";
303  that_ptr_name = "that_row_ptr";
304  break;
305  }
306  default: {
307  LOG(FATAL) << "Unexpected query description type";
308  }
309  }
310  return create_function("reduce_one_entry",
311  {{this_ptr_name, Type::Int8Ptr},
312  {that_ptr_name, Type::Int8Ptr},
313  {"this_qmd", Type::VoidPtr},
314  {"that_qmd", Type::VoidPtr},
315  {"serialized_varlen_buffer_arg", Type::VoidPtr}},
316  Type::Int32,
317  /*always_inline=*/true);
318 }
319 
320 // Create the declaration for the 'reduce_one_entry_idx' helper.
321 std::unique_ptr<Function> setup_reduce_one_entry_idx(ReductionCode* reduction_code) {
322  return create_function("reduce_one_entry_idx",
323  {{"this_buff", Type::Int8Ptr},
324  {"that_buff", Type::Int8Ptr},
325  {"that_entry_idx", Type::Int32},
326  {"that_entry_count", Type::Int32},
327  {"this_qmd_handle", Type::VoidPtr},
328  {"that_qmd_handle", Type::VoidPtr},
329  {"serialized_varlen_buffer", Type::VoidPtr}},
330  Type::Int32,
331  /*always_inline=*/true);
332 }
333 
334 // Create the declaration for the 'reduce_loop' entry point. Use external linkage, this is
335 // the public API of the generated code directly used from result set reduction.
336 std::unique_ptr<Function> setup_reduce_loop(ReductionCode* reduction_code) {
337  return create_function("reduce_loop",
338  {{"this_buff", Type::Int8Ptr},
339  {"that_buff", Type::Int8Ptr},
340  {"start_index", Type::Int32},
341  {"end_index", Type::Int32},
342  {"that_entry_count", Type::Int32},
343  {"this_qmd_handle", Type::VoidPtr},
344  {"that_qmd_handle", Type::VoidPtr},
345  {"serialized_varlen_buffer", Type::VoidPtr}},
346  Type::Int32,
347  /*always_inline=*/false);
348 }
349 
350 llvm::Function* create_llvm_function(const Function* function, CgenState* cgen_state) {
351  AUTOMATIC_IR_METADATA(cgen_state);
352  auto& ctx = cgen_state->context_;
353  std::vector<llvm::Type*> parameter_types;
354  const auto& arg_types = function->arg_types();
355  for (const auto& named_arg : arg_types) {
356  CHECK(named_arg.type != Type::Void);
357  parameter_types.push_back(llvm_type(named_arg.type, ctx));
358  }
359  const auto func_type = llvm::FunctionType::get(
360  llvm_type(function->ret_type(), ctx), parameter_types, false);
361  const auto linkage = function->always_inline() ? llvm::Function::PrivateLinkage
362  : llvm::Function::ExternalLinkage;
363  auto func =
364  llvm::Function::Create(func_type, linkage, function->name(), cgen_state->module_);
365  const auto arg_it = func->arg_begin();
366  for (size_t i = 0; i < arg_types.size(); ++i) {
367  const auto arg = &*(arg_it + i);
368  arg->setName(arg_types[i].name);
369  }
370  if (function->always_inline()) {
372  }
373  return func;
374 }
375 
376 // Setup the reduction function and helpers declarations, create a module and a code
377 // generation state object.
379  ReductionCode reduction_code{};
380  reduction_code.ir_is_empty = setup_is_empty_entry(&reduction_code);
381  reduction_code.ir_reduce_one_entry = setup_reduce_one_entry(&reduction_code, hash_type);
382  reduction_code.ir_reduce_one_entry_idx = setup_reduce_one_entry_idx(&reduction_code);
383  reduction_code.ir_reduce_loop = setup_reduce_loop(&reduction_code);
384  return reduction_code;
385 }
386 
388  return hash_type == QueryDescriptionType::GroupByBaselineHash ||
391 }
392 
393 // Variable length sample fast path (no serialized variable length buffer).
394 void varlen_buffer_sample(int8_t* this_ptr1,
395  int8_t* this_ptr2,
396  const int8_t* that_ptr1,
397  const int8_t* that_ptr2,
398  const int64_t init_val) {
399  const auto rhs_proj_col = *reinterpret_cast<const int64_t*>(that_ptr1);
400  if (rhs_proj_col != init_val) {
401  *reinterpret_cast<int64_t*>(this_ptr1) = rhs_proj_col;
402  }
403  CHECK(this_ptr2 && that_ptr2);
404  *reinterpret_cast<int64_t*>(this_ptr2) = *reinterpret_cast<const int64_t*>(that_ptr2);
405 }
406 
407 } // namespace
408 
410  const void* serialized_varlen_buffer_handle,
411  int8_t* this_ptr1,
412  int8_t* this_ptr2,
413  const int8_t* that_ptr1,
414  const int8_t* that_ptr2,
415  const int64_t init_val,
416  const int64_t length_to_elems) {
417  if (!serialized_varlen_buffer_handle) {
418  varlen_buffer_sample(this_ptr1, this_ptr2, that_ptr1, that_ptr2, init_val);
419  return;
420  }
421  const auto& serialized_varlen_buffer =
422  *reinterpret_cast<const std::vector<std::string>*>(serialized_varlen_buffer_handle);
423  if (!serialized_varlen_buffer.empty()) {
424  const auto rhs_proj_col = *reinterpret_cast<const int64_t*>(that_ptr1);
425  CHECK_LT(static_cast<size_t>(rhs_proj_col), serialized_varlen_buffer.size());
426  const auto& varlen_bytes_str = serialized_varlen_buffer[rhs_proj_col];
427  const auto str_ptr = reinterpret_cast<const int8_t*>(varlen_bytes_str.c_str());
428  *reinterpret_cast<int64_t*>(this_ptr1) = reinterpret_cast<const int64_t>(str_ptr);
429  *reinterpret_cast<int64_t*>(this_ptr2) =
430  static_cast<int64_t>(varlen_bytes_str.size() / length_to_elems);
431  } else {
432  varlen_buffer_sample(this_ptr1, this_ptr2, that_ptr1, that_ptr2, init_val);
433  }
434 }
435 
436 // Wrappers to be called from the generated code, sharing implementation with the rest of
437 // the system.
438 
440  const int64_t new_set_handle,
441  const int64_t old_set_handle,
442  const void* that_qmd_handle,
443  const void* this_qmd_handle,
444  const int64_t target_logical_idx) {
445  const auto that_qmd = reinterpret_cast<const QueryMemoryDescriptor*>(that_qmd_handle);
446  const auto this_qmd = reinterpret_cast<const QueryMemoryDescriptor*>(this_qmd_handle);
447  const auto& new_count_distinct_desc =
448  that_qmd->getCountDistinctDescriptor(target_logical_idx);
449  const auto& old_count_distinct_desc =
450  this_qmd->getCountDistinctDescriptor(target_logical_idx);
451  CHECK(old_count_distinct_desc.impl_type_ != CountDistinctImplType::Invalid);
452  CHECK(old_count_distinct_desc.impl_type_ == new_count_distinct_desc.impl_type_);
454  new_set_handle, old_set_handle, new_count_distinct_desc, old_count_distinct_desc);
455 }
456 
457 extern "C" RUNTIME_EXPORT void approx_quantile_jit_rt(const int64_t new_set_handle,
458  const int64_t old_set_handle,
459  const void* that_qmd_handle,
460  const void* this_qmd_handle,
461  const int64_t target_logical_idx) {
462  auto* incoming = reinterpret_cast<quantile::TDigest*>(new_set_handle);
463  if (incoming->centroids().capacity()) {
464  auto* accumulator = reinterpret_cast<quantile::TDigest*>(old_set_handle);
465  accumulator->allocate();
466  accumulator->mergeTDigest(*incoming);
467  }
468 }
469 
471  int8_t* groups_buffer,
472  const int8_t* key,
473  const uint32_t key_count,
474  const void* this_qmd_handle,
475  const int8_t* that_buff,
476  const uint32_t that_entry_idx,
477  const uint32_t that_entry_count,
478  const uint32_t row_size_bytes,
479  int64_t** buff_out,
480  uint8_t* empty) {
481  const auto& this_qmd = *reinterpret_cast<const QueryMemoryDescriptor*>(this_qmd_handle);
482  const auto gvi =
483  result_set::get_group_value_reduction(reinterpret_cast<int64_t*>(groups_buffer),
484  this_qmd.getEntryCount(),
485  reinterpret_cast<const int64_t*>(key),
486  key_count,
487  this_qmd.getEffectiveKeyWidth(),
488  this_qmd,
489  reinterpret_cast<const int64_t*>(that_buff),
490  that_entry_idx,
491  that_entry_count,
492  row_size_bytes >> 3);
493  *buff_out = gvi.first;
494  *empty = gvi.second;
495 }
496 
497 extern "C" RUNTIME_EXPORT uint8_t check_watchdog_rt(const size_t sample_seed) {
498  if (UNLIKELY(g_enable_dynamic_watchdog && (sample_seed & 0x3F) == 0 &&
499  dynamic_watchdog())) {
500  return true;
501  }
502  return false;
503 }
504 
505 extern "C" uint8_t check_interrupt_rt(const size_t sample_seed) {
506  // this func is called iff we enable runtime query interrupt
507  if (UNLIKELY((sample_seed & 0xFFFF) == 0 && check_interrupt())) {
508  return true;
509  }
510  return false;
511 }
512 
514  const std::vector<TargetInfo>& targets,
515  const std::vector<int64_t>& target_init_vals,
516  const size_t executor_id)
517  : executor_id_(executor_id)
518  , query_mem_desc_(query_mem_desc)
519  , targets_(targets)
520  , target_init_vals_(target_init_vals) {}
521 
522 // The code generated for a reduction between two result set buffers is structured in
523 // several functions and their IR is stored in the 'ReductionCode' structure. At a high
524 // level, the pseudocode is:
525 //
526 // func is_empty_func(row_ptr):
527 // ...
528 //
529 // func reduce_func_baseline(this_ptr, that_ptr):
530 // if is_empty_func(that_ptr):
531 // return
532 // for each target in the row:
533 // reduce target from that_ptr into this_ptr
534 //
535 // func reduce_func_perfect_hash(this_ptr, that_ptr):
536 // if is_empty_func(that_ptr):
537 // return
538 // for each target in the row:
539 // reduce target from that_ptr into this_ptr
540 //
541 // func reduce_func_idx(this_buff, that_buff, that_entry_index):
542 // that_ptr = that_result_set[that_entry_index]
543 // # Retrieval of 'this_ptr' is different between perfect hash and baseline.
544 // this_ptr = this_result_set[that_entry_index]
545 // or
546 // get_row(key(that_row_ptr), this_result_setBuffer)
547 // reduce_func_[baseline|perfect_hash](this_ptr, that_ptr)
548 //
549 // func reduce_loop(this_buff, that_buff, start_entry_index, end_entry_index):
550 // for that_entry_index in [start_entry_index, end_entry_index):
551 // reduce_func_idx(this_buff, that_buff, that_entry_index)
552 
554  const auto hash_type = query_mem_desc_.getQueryDescriptionType();
556  return {};
557  }
558  auto reduction_code = setup_functions_ir(hash_type);
559  isEmpty(reduction_code);
563  reduceOneEntryNoCollisions(reduction_code);
564  reduceOneEntryNoCollisionsIdx(reduction_code);
565  break;
566  }
568  reduceOneEntryBaseline(reduction_code);
569  reduceOneEntryBaselineIdx(reduction_code);
570  break;
571  }
572  default: {
573  LOG(FATAL) << "Unexpected query description type";
574  }
575  }
576  reduceLoop(reduction_code);
577  // For small result sets, avoid native code generation and use the interpreter instead.
580  return reduction_code;
581  }
582  auto executor = Executor::getExecutor(executor_id_);
583  CodeCacheKey key{cacheKey()};
584  std::lock_guard<std::mutex> compilation_lock(executor->compilation_mutex_);
585  const auto compilation_context =
586  QueryEngine::getInstance()->s_code_accessor->get_or_wait(key);
587  if (compilation_context) {
588  reduction_code.func_ptr =
589  reinterpret_cast<ReductionCode::FuncPtr>(compilation_context->get()->func());
590  return reduction_code;
591  }
592  auto cgen_state_ = std::unique_ptr<CgenState>(new CgenState({}, false, executor.get()));
593  auto cgen_state = reduction_code.cgen_state = cgen_state_.get();
594  cgen_state->set_module_shallow_copy(executor->get_rt_module());
595  reduction_code.module = cgen_state->module_;
596 
597  AUTOMATIC_IR_METADATA(cgen_state);
598  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
599  auto ir_reduce_one_entry =
600  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
601  auto ir_reduce_one_entry_idx =
602  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
603  auto ir_reduce_loop =
604  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
605  std::unordered_map<const Function*, llvm::Function*> f;
606  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
607  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
608  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
609  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
610  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
612  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
613  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
614  ir_reduce_one_entry_idx,
615  reduction_code,
616  f);
618  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
619  reduction_code.llvm_reduce_loop = ir_reduce_loop;
621  reduction_code.cgen_state = nullptr;
623  reduction_code, ir_is_empty, ir_reduce_one_entry, ir_reduce_one_entry_idx, key);
624  return reduction_code;
625 }
626 
627 void ResultSetReductionJIT::isEmpty(const ReductionCode& reduction_code) const {
628  auto ir_is_empty = reduction_code.ir_is_empty.get();
631  Value* key{nullptr};
632  Value* empty_key_val{nullptr};
633  const auto keys_ptr = ir_is_empty->arg(0);
638  CHECK_LT(static_cast<size_t>(query_mem_desc_.getTargetIdxForKey()),
639  target_init_vals_.size());
640  const int64_t target_slot_off = result_set::get_byteoff_of_slot(
642  const auto slot_ptr = ir_is_empty->add<GetElementPtr>(
643  keys_ptr,
644  ir_is_empty->addConstant<ConstantInt>(target_slot_off, Type::Int32),
645  "is_empty_slot_ptr");
646  const auto compact_sz =
648  key = emit_read_int_from_buff(slot_ptr, compact_sz, ir_is_empty);
649  empty_key_val = ir_is_empty->addConstant<ConstantInt>(
651  } else {
653  case 4: {
656  key = emit_load_i32(keys_ptr, ir_is_empty);
657  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_32, Type::Int32);
658  break;
659  }
660  case 8: {
661  key = emit_load_i64(keys_ptr, ir_is_empty);
662  empty_key_val = ir_is_empty->addConstant<ConstantInt>(EMPTY_KEY_64, Type::Int64);
663  break;
664  }
665  default:
666  LOG(FATAL) << "Invalid key width";
667  }
668  }
669  const auto ret =
670  ir_is_empty->add<ICmp>(ICmp::Predicate::EQ, key, empty_key_val, "is_key_empty");
671  ir_is_empty->add<Ret>(ret);
672 }
673 
675  const ReductionCode& reduction_code) const {
676  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
677  const auto this_row_ptr = ir_reduce_one_entry->arg(0);
678  const auto that_row_ptr = ir_reduce_one_entry->arg(1);
679  const auto that_is_empty =
680  ir_reduce_one_entry->add<Call>(reduction_code.ir_is_empty.get(),
681  std::vector<const Value*>{that_row_ptr},
682  "that_is_empty");
683  ir_reduce_one_entry->add<ReturnEarly>(
684  that_is_empty, ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32), "");
685 
686  const auto key_bytes = get_key_bytes_rowwise(query_mem_desc_);
687  if (key_bytes) { // copy the key from right hand side
688  ir_reduce_one_entry->add<MemCpy>(
689  this_row_ptr,
690  that_row_ptr,
691  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes, Type::Int32));
692  }
693 
694  const auto key_bytes_with_padding = align_to_int64(key_bytes);
695  const auto key_bytes_lv =
696  ir_reduce_one_entry->addConstant<ConstantInt>(key_bytes_with_padding, Type::Int32);
697  const auto this_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
698  this_row_ptr, key_bytes_lv, "this_targets_start");
699  const auto that_targets_start_ptr = ir_reduce_one_entry->add<GetElementPtr>(
700  that_row_ptr, key_bytes_lv, "that_targets_start");
701 
703  ir_reduce_one_entry, this_targets_start_ptr, that_targets_start_ptr);
704 }
705 
707  Function* ir_reduce_one_entry,
708  Value* this_targets_start_ptr,
709  Value* that_targets_start_ptr) const {
710  const auto& col_slot_context = query_mem_desc_.getColSlotContext();
711  Value* this_targets_ptr = this_targets_start_ptr;
712  Value* that_targets_ptr = that_targets_start_ptr;
713  size_t init_agg_val_idx = 0;
714  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
715  ++target_logical_idx) {
716  const auto& target_info = targets_[target_logical_idx];
717  const auto& slots_for_col = col_slot_context.getSlotsForCol(target_logical_idx);
718  Value* this_ptr2{nullptr};
719  Value* that_ptr2{nullptr};
720 
721  bool two_slot_target{false};
722  if (target_info.is_agg &&
723  (target_info.agg_kind == kAVG ||
724  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
725  // Note that this assumes if one of the slot pairs in a given target is an array,
726  // all slot pairs are arrays. Currently this is true for all geo targets, but we
727  // should better codify and store this information in the future
728  two_slot_target = true;
729  }
730 
731  for (size_t target_slot_idx = slots_for_col.front();
732  target_slot_idx < slots_for_col.back() + 1;
733  target_slot_idx += 2) {
734  const auto slot_off_val = query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx);
735  const auto slot_off =
736  ir_reduce_one_entry->addConstant<ConstantInt>(slot_off_val, Type::Int32);
737  if (UNLIKELY(two_slot_target)) {
738  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
739  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
740  this_targets_ptr, slot_off, "this_" + desc);
741  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
742  that_targets_ptr, slot_off, "that_" + desc);
743  }
744  reduceOneSlot(this_targets_ptr,
745  this_ptr2,
746  that_targets_ptr,
747  that_ptr2,
748  target_info,
749  target_logical_idx,
750  target_slot_idx,
751  init_agg_val_idx,
752  slots_for_col.front(),
753  ir_reduce_one_entry);
754  auto increment_agg_val_idx_maybe =
755  [&init_agg_val_idx, &target_logical_idx, this](const int slot_count) {
757  query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
758  init_agg_val_idx += slot_count;
759  }
760  };
761  if (target_logical_idx + 1 == targets_.size() &&
762  target_slot_idx + 1 >= slots_for_col.back()) {
763  break;
764  }
765  const auto next_desc =
766  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
767  if (UNLIKELY(two_slot_target)) {
768  increment_agg_val_idx_maybe(2);
769  const auto two_slot_off = ir_reduce_one_entry->addConstant<ConstantInt>(
770  slot_off_val + query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx + 1),
771  Type::Int32);
772  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
773  this_targets_ptr, two_slot_off, "this_" + next_desc);
774  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
775  that_targets_ptr, two_slot_off, "that_" + next_desc);
776  } else {
777  increment_agg_val_idx_maybe(1);
778  this_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
779  this_targets_ptr, slot_off, "this_" + next_desc);
780  that_targets_ptr = ir_reduce_one_entry->add<GetElementPtr>(
781  that_targets_ptr, slot_off, "that_" + next_desc);
782  }
783  }
784  }
785  ir_reduce_one_entry->add<Ret>(
786  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
787 }
788 
790  const ReductionCode& reduction_code) const {
791  auto ir_reduce_one_entry = reduction_code.ir_reduce_one_entry.get();
792  const auto this_targets_ptr_arg = ir_reduce_one_entry->arg(0);
793  const auto that_targets_ptr_arg = ir_reduce_one_entry->arg(1);
794  Value* this_ptr1 = this_targets_ptr_arg;
795  Value* that_ptr1 = that_targets_ptr_arg;
796  size_t j = 0;
797  size_t init_agg_val_idx = 0;
798  for (size_t target_logical_idx = 0; target_logical_idx < targets_.size();
799  ++target_logical_idx) {
800  const auto& target_info = targets_[target_logical_idx];
801  Value* this_ptr2{nullptr};
802  Value* that_ptr2{nullptr};
803  if (target_info.is_agg &&
804  (target_info.agg_kind == kAVG ||
805  (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()))) {
806  const auto desc = "target_" + std::to_string(target_logical_idx) + "_second_slot";
807  const auto second_slot_rel_off =
808  ir_reduce_one_entry->addConstant<ConstantInt>(sizeof(int64_t), Type::Int32);
809  this_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
810  this_ptr1, second_slot_rel_off, "this_" + desc);
811  that_ptr2 = ir_reduce_one_entry->add<GetElementPtr>(
812  that_ptr1, second_slot_rel_off, "that_" + desc);
813  }
814  reduceOneSlot(this_ptr1,
815  this_ptr2,
816  that_ptr1,
817  that_ptr2,
818  target_info,
819  target_logical_idx,
820  j,
821  init_agg_val_idx,
822  j,
823  ir_reduce_one_entry);
824  if (target_logical_idx + 1 == targets_.size()) {
825  break;
826  }
828  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
829  } else {
830  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) < 0) {
831  init_agg_val_idx = advance_slot(init_agg_val_idx, target_info, false);
832  }
833  }
834  j = advance_slot(j, target_info, false);
835  const auto next_desc =
836  "target_" + std::to_string(target_logical_idx + 1) + "_first_slot";
837  auto next_slot_rel_off = ir_reduce_one_entry->addConstant<ConstantInt>(
838  init_agg_val_idx * sizeof(int64_t), Type::Int32);
839  this_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
840  this_targets_ptr_arg, next_slot_rel_off, next_desc);
841  that_ptr1 = ir_reduce_one_entry->add<GetElementPtr>(
842  that_targets_ptr_arg, next_slot_rel_off, next_desc);
843  }
844  ir_reduce_one_entry->add<Ret>(
845  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32));
846 }
847 
849  const ReductionCode& reduction_code) const {
850  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
855  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
856  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
857  const auto entry_idx = ir_reduce_one_entry_idx->arg(2);
858  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
859  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
860  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
861  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
863  const auto entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
864  Cast::CastOp::SExt, entry_idx, Type::Int64, "entry_idx_64");
865  const auto row_off_in_bytes = ir_reduce_one_entry_idx->add<BinaryOperator>(
866  BinaryOperator::BinaryOp::Mul, entry_idx_64, row_bytes, "row_off_in_bytes");
867  const auto this_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
868  this_buff, row_off_in_bytes, "this_row_ptr");
869  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
870  that_buff, row_off_in_bytes, "that_row_ptr");
871  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
872  reduction_code.ir_reduce_one_entry.get(),
873  std::vector<const Value*>{this_row_ptr,
874  that_row_ptr,
875  this_qmd_handle,
876  that_qmd_handle,
877  serialized_varlen_buffer_arg},
878  "");
879  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
880 }
881 
883  const ReductionCode& reduction_code) const {
884  auto ir_reduce_one_entry_idx = reduction_code.ir_reduce_one_entry_idx.get();
889  const auto this_buff = ir_reduce_one_entry_idx->arg(0);
890  const auto that_buff = ir_reduce_one_entry_idx->arg(1);
891  const auto that_entry_idx = ir_reduce_one_entry_idx->arg(2);
892  const auto that_entry_count = ir_reduce_one_entry_idx->arg(3);
893  const auto this_qmd_handle = ir_reduce_one_entry_idx->arg(4);
894  const auto that_qmd_handle = ir_reduce_one_entry_idx->arg(5);
895  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry_idx->arg(6);
896  const auto row_bytes = ir_reduce_one_entry_idx->addConstant<ConstantInt>(
898  const auto that_entry_idx_64 = ir_reduce_one_entry_idx->add<Cast>(
899  Cast::CastOp::SExt, that_entry_idx, Type::Int64, "that_entry_idx_64");
900  const auto that_row_off_in_bytes =
901  ir_reduce_one_entry_idx->add<BinaryOperator>(BinaryOperator::BinaryOp::Mul,
902  that_entry_idx_64,
903  row_bytes,
904  "that_row_off_in_bytes");
905  const auto that_row_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
906  that_buff, that_row_off_in_bytes, "that_row_ptr");
907  const auto that_is_empty =
908  ir_reduce_one_entry_idx->add<Call>(reduction_code.ir_is_empty.get(),
909  std::vector<const Value*>{that_row_ptr},
910  "that_is_empty");
911  ir_reduce_one_entry_idx->add<ReturnEarly>(
912  that_is_empty,
913  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
914  "");
915  const auto key_count = query_mem_desc_.getGroupbyColCount();
916  const auto one_element =
917  ir_reduce_one_entry_idx->addConstant<ConstantInt>(1, Type::Int32);
918  const auto this_targets_ptr_i64_ptr = ir_reduce_one_entry_idx->add<Alloca>(
919  Type::Int64Ptr, one_element, "this_targets_ptr_out");
920  const auto this_is_empty_ptr =
921  ir_reduce_one_entry_idx->add<Alloca>(Type::Int8, one_element, "this_is_empty_out");
922  ir_reduce_one_entry_idx->add<ExternalCall>(
923  "get_group_value_reduction_rt",
924  Type::Void,
925  std::vector<const Value*>{
926  this_buff,
927  that_row_ptr,
928  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_count, Type::Int32),
929  this_qmd_handle,
930  that_buff,
931  that_entry_idx,
932  that_entry_count,
933  row_bytes,
934  this_targets_ptr_i64_ptr,
935  this_is_empty_ptr},
936  "");
937  const auto this_targets_ptr_i64 = ir_reduce_one_entry_idx->add<Load>(
938  this_targets_ptr_i64_ptr, "this_targets_ptr_i64");
939  auto this_is_empty =
940  ir_reduce_one_entry_idx->add<Load>(this_is_empty_ptr, "this_is_empty");
941  this_is_empty = ir_reduce_one_entry_idx->add<Cast>(
942  Cast::CastOp::Trunc, this_is_empty, Type::Int1, "this_is_empty_bool");
943  ir_reduce_one_entry_idx->add<ReturnEarly>(
944  this_is_empty,
945  ir_reduce_one_entry_idx->addConstant<ConstantInt>(0, Type::Int32),
946  "");
947  const auto key_qw_count = get_slot_off_quad(query_mem_desc_);
948  const auto this_targets_ptr = ir_reduce_one_entry_idx->add<Cast>(
949  Cast::CastOp::BitCast, this_targets_ptr_i64, Type::Int8Ptr, "this_targets_ptr");
950  const auto key_byte_count = key_qw_count * sizeof(int64_t);
951  const auto key_byte_count_lv =
952  ir_reduce_one_entry_idx->addConstant<ConstantInt>(key_byte_count, Type::Int32);
953  const auto that_targets_ptr = ir_reduce_one_entry_idx->add<GetElementPtr>(
954  that_row_ptr, key_byte_count_lv, "that_targets_ptr");
955  const auto reduce_rc = ir_reduce_one_entry_idx->add<Call>(
956  reduction_code.ir_reduce_one_entry.get(),
957  std::vector<const Value*>{this_targets_ptr,
958  that_targets_ptr,
959  this_qmd_handle,
960  that_qmd_handle,
961  serialized_varlen_buffer_arg},
962  "");
963  ir_reduce_one_entry_idx->add<Ret>(reduce_rc);
964 }
965 
966 namespace {
967 
968 void generate_loop_body(For* for_loop,
969  Function* ir_reduce_loop,
970  Function* ir_reduce_one_entry_idx,
971  Value* this_buff,
972  Value* that_buff,
973  Value* start_index,
974  Value* that_entry_count,
975  Value* this_qmd_handle,
976  Value* that_qmd_handle,
977  Value* serialized_varlen_buffer) {
978  const auto that_entry_idx = for_loop->add<BinaryOperator>(
979  BinaryOperator::BinaryOp::Add, for_loop->iter(), start_index, "that_entry_idx");
980  const auto sample_seed =
981  for_loop->add<Cast>(Cast::CastOp::SExt, that_entry_idx, Type::Int64, "");
983  const auto checker_rt_name =
984  g_enable_dynamic_watchdog ? "check_watchdog_rt" : "check_interrupt_rt";
985  const auto error_code = g_enable_dynamic_watchdog ? WATCHDOG_ERROR : INTERRUPT_ERROR;
986  const auto checker_triggered = for_loop->add<ExternalCall>(
987  checker_rt_name, Type::Int8, std::vector<const Value*>{sample_seed}, "");
988  const auto interrupt_triggered_bool =
989  for_loop->add<ICmp>(ICmp::Predicate::NE,
990  checker_triggered,
991  ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int8),
992  "");
993  for_loop->add<ReturnEarly>(
994  interrupt_triggered_bool,
995  ir_reduce_loop->addConstant<ConstantInt>(error_code, Type::Int32),
996  "");
997  }
998  const auto reduce_rc =
999  for_loop->add<Call>(ir_reduce_one_entry_idx,
1000  std::vector<const Value*>{this_buff,
1001  that_buff,
1002  that_entry_idx,
1003  that_entry_count,
1004  this_qmd_handle,
1005  that_qmd_handle,
1006  serialized_varlen_buffer},
1007  "");
1008 
1009  auto reduce_rc_bool =
1010  for_loop->add<ICmp>(ICmp::Predicate::NE,
1011  reduce_rc,
1012  ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32),
1013  "");
1014  for_loop->add<ReturnEarly>(reduce_rc_bool, reduce_rc, "");
1015 }
1016 
1017 } // namespace
1018 
1019 void ResultSetReductionJIT::reduceLoop(const ReductionCode& reduction_code) const {
1020  auto ir_reduce_loop = reduction_code.ir_reduce_loop.get();
1021  const auto this_buff_arg = ir_reduce_loop->arg(0);
1022  const auto that_buff_arg = ir_reduce_loop->arg(1);
1023  const auto start_index_arg = ir_reduce_loop->arg(2);
1024  const auto end_index_arg = ir_reduce_loop->arg(3);
1025  const auto that_entry_count_arg = ir_reduce_loop->arg(4);
1026  const auto this_qmd_handle_arg = ir_reduce_loop->arg(5);
1027  const auto that_qmd_handle_arg = ir_reduce_loop->arg(6);
1028  const auto serialized_varlen_buffer_arg = ir_reduce_loop->arg(7);
1029  For* for_loop =
1030  static_cast<For*>(ir_reduce_loop->add<For>(start_index_arg, end_index_arg, ""));
1031  generate_loop_body(for_loop,
1032  ir_reduce_loop,
1033  reduction_code.ir_reduce_one_entry_idx.get(),
1034  this_buff_arg,
1035  that_buff_arg,
1036  start_index_arg,
1037  that_entry_count_arg,
1038  this_qmd_handle_arg,
1039  that_qmd_handle_arg,
1040  serialized_varlen_buffer_arg);
1041  ir_reduce_loop->add<Ret>(ir_reduce_loop->addConstant<ConstantInt>(0, Type::Int32));
1042 }
1043 
1045  Value* this_ptr2,
1046  Value* that_ptr1,
1047  Value* that_ptr2,
1048  const TargetInfo& target_info,
1049  const size_t target_logical_idx,
1050  const size_t target_slot_idx,
1051  const size_t init_agg_val_idx,
1052  const size_t first_slot_idx_for_target,
1053  Function* ir_reduce_one_entry) const {
1055  if (query_mem_desc_.getTargetGroupbyIndex(target_logical_idx) >= 0) {
1056  return;
1057  }
1058  }
1059  const bool float_argument_input = takes_float_argument(target_info);
1060  const auto chosen_bytes = result_set::get_width_for_slot(
1061  target_slot_idx, float_argument_input, query_mem_desc_);
1062  CHECK_LT(init_agg_val_idx, target_init_vals_.size());
1063  auto init_val = target_init_vals_[init_agg_val_idx];
1064  if (target_info.is_agg &&
1065  (target_info.agg_kind != kSINGLE_VALUE && target_info.agg_kind != kSAMPLE)) {
1066  reduceOneAggregateSlot(this_ptr1,
1067  this_ptr2,
1068  that_ptr1,
1069  that_ptr2,
1070  target_info,
1071  target_logical_idx,
1072  target_slot_idx,
1073  init_val,
1074  chosen_bytes,
1075  ir_reduce_one_entry);
1076  } else if (target_info.agg_kind == kSINGLE_VALUE) {
1077  const auto checked_rc = emit_checked_write_projection(
1078  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1079 
1080  auto checked_rc_bool = ir_reduce_one_entry->add<ICmp>(
1082  checked_rc,
1083  ir_reduce_one_entry->addConstant<ConstantInt>(0, Type::Int32),
1084  "");
1085 
1086  ir_reduce_one_entry->add<ReturnEarly>(checked_rc_bool, checked_rc, "");
1087 
1088  } else {
1090  this_ptr1, that_ptr1, init_val, chosen_bytes, ir_reduce_one_entry);
1091  if (target_info.agg_kind == kSAMPLE && target_info.sql_type.is_varlen()) {
1092  CHECK(this_ptr2 && that_ptr2);
1093  size_t length_to_elems{0};
1094  if (target_info.sql_type.is_geometry()) {
1095  // TODO: Assumes hard-coded sizes for geometry targets
1096  length_to_elems = target_slot_idx == first_slot_idx_for_target ? 1 : 4;
1097  } else {
1098  const auto& elem_ti = target_info.sql_type.get_elem_type();
1099  length_to_elems = target_info.sql_type.is_string() ? 1 : elem_ti.get_size();
1100  }
1101  const auto serialized_varlen_buffer_arg = ir_reduce_one_entry->arg(4);
1102  ir_reduce_one_entry->add<ExternalCall>(
1103  "serialized_varlen_buffer_sample",
1104  Type::Void,
1105  std::vector<const Value*>{
1106  serialized_varlen_buffer_arg,
1107  this_ptr1,
1108  this_ptr2,
1109  that_ptr1,
1110  that_ptr2,
1111  ir_reduce_one_entry->addConstant<ConstantInt>(init_val, Type::Int64),
1112  ir_reduce_one_entry->addConstant<ConstantInt>(length_to_elems,
1113  Type::Int64)},
1114  "");
1115  }
1116  }
1117 }
1118 
1120  Value* this_ptr2,
1121  Value* that_ptr1,
1122  Value* that_ptr2,
1123  const TargetInfo& target_info,
1124  const size_t target_logical_idx,
1125  const size_t target_slot_idx,
1126  const int64_t init_val,
1127  const int8_t chosen_bytes,
1128  Function* ir_reduce_one_entry) const {
1129  switch (target_info.agg_kind) {
1130  case kCOUNT:
1131  case kAPPROX_COUNT_DISTINCT: {
1132  if (is_distinct_target(target_info)) {
1133  CHECK_EQ(static_cast<size_t>(chosen_bytes), sizeof(int64_t));
1135  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1136  break;
1137  }
1138  CHECK_EQ(int64_t(0), init_val);
1139  emit_aggregate_one_count(this_ptr1, that_ptr1, chosen_bytes, ir_reduce_one_entry);
1140  break;
1141  }
1142  case kAPPROX_QUANTILE:
1143  CHECK_EQ(chosen_bytes, static_cast<int8_t>(sizeof(int64_t)));
1145  this_ptr1, that_ptr1, target_logical_idx, ir_reduce_one_entry);
1146  break;
1147  case kAVG: {
1148  // Ignore float argument compaction for count component for fear of its overflow
1149  emit_aggregate_one_count(this_ptr2,
1150  that_ptr2,
1151  query_mem_desc_.getPaddedSlotWidthBytes(target_slot_idx),
1152  ir_reduce_one_entry);
1153  }
1154  // fall thru
1155  case kSUM: {
1157  this_ptr1,
1158  that_ptr1,
1159  init_val,
1160  chosen_bytes,
1161  target_info,
1162  ir_reduce_one_entry);
1163  break;
1164  }
1165  case kMIN: {
1167  this_ptr1,
1168  that_ptr1,
1169  init_val,
1170  chosen_bytes,
1171  target_info,
1172  ir_reduce_one_entry);
1173  break;
1174  }
1175  case kMAX: {
1177  this_ptr1,
1178  that_ptr1,
1179  init_val,
1180  chosen_bytes,
1181  target_info,
1182  ir_reduce_one_entry);
1183  break;
1184  }
1185  default:
1186  LOG(FATAL) << "Invalid aggregate type";
1187  }
1188 }
1189 
1191  Value* this_ptr1,
1192  Value* that_ptr1,
1193  const size_t target_logical_idx,
1194  Function* ir_reduce_one_entry) const {
1196  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1197  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1198  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1199  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1200  ir_reduce_one_entry->add<ExternalCall>(
1201  "count_distinct_set_union_jit_rt",
1202  Type::Void,
1203  std::vector<const Value*>{
1204  new_set_handle,
1205  old_set_handle,
1206  that_qmd_arg,
1207  this_qmd_arg,
1208  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1209  "");
1210 }
1211 
1213  Value* this_ptr1,
1214  Value* that_ptr1,
1215  const size_t target_logical_idx,
1216  Function* ir_reduce_one_entry) const {
1218  const auto old_set_handle = emit_load_i64(this_ptr1, ir_reduce_one_entry);
1219  const auto new_set_handle = emit_load_i64(that_ptr1, ir_reduce_one_entry);
1220  const auto this_qmd_arg = ir_reduce_one_entry->arg(2);
1221  const auto that_qmd_arg = ir_reduce_one_entry->arg(3);
1222  ir_reduce_one_entry->add<ExternalCall>(
1223  "approx_quantile_jit_rt",
1224  Type::Void,
1225  std::vector<const Value*>{
1226  new_set_handle,
1227  old_set_handle,
1228  that_qmd_arg,
1229  this_qmd_arg,
1230  ir_reduce_one_entry->addConstant<ConstantInt>(target_logical_idx, Type::Int64)},
1231  "");
1232 }
1233 
1235  ReductionCode& reduction_code,
1236  const llvm::Function* ir_is_empty,
1237  const llvm::Function* ir_reduce_one_entry,
1238  const llvm::Function* ir_reduce_one_entry_idx,
1239  const CodeCacheKey& key) const {
1240  CompilationOptions co{
1242 #ifdef NDEBUG
1243  LOG(IR) << "Reduction Loop:\n"
1244  << serialize_llvm_object(reduction_code.llvm_reduce_loop);
1245  LOG(IR) << "Reduction Is Empty Func:\n" << serialize_llvm_object(ir_is_empty);
1246  LOG(IR) << "Reduction One Entry Func:\n" << serialize_llvm_object(ir_reduce_one_entry);
1247  LOG(IR) << "Reduction One Entry Idx Func:\n"
1248  << serialize_llvm_object(ir_reduce_one_entry_idx);
1249 #else
1250  LOG(IR) << serialize_llvm_object(reduction_code.module);
1251 #endif
1253  reduction_code.llvm_reduce_loop, {reduction_code.llvm_reduce_loop}, co);
1254  auto cpu_compilation_context = std::make_shared<CpuCompilationContext>(std::move(ee));
1255  cpu_compilation_context->setFunctionPointer(reduction_code.llvm_reduce_loop);
1256  reduction_code.func_ptr =
1257  reinterpret_cast<ReductionCode::FuncPtr>(cpu_compilation_context->func());
1258  CHECK(reduction_code.llvm_reduce_loop->getParent() == reduction_code.module);
1259  auto executor = Executor::getExecutor(executor_id_);
1260  QueryEngine::getInstance()->s_code_accessor->swap(key,
1261  std::move(cpu_compilation_context));
1262 }
1263 
1264 namespace {
1265 
1266 std::string target_info_key(const TargetInfo& target_info) {
1267  return std::to_string(target_info.is_agg) + "\n" +
1268  std::to_string(target_info.agg_kind) + "\n" +
1269  target_info.sql_type.get_type_name() + "\n" +
1270  std::to_string(target_info.sql_type.get_notnull()) + "\n" +
1271  target_info.agg_arg_type.get_type_name() + "\n" +
1272  std::to_string(target_info.agg_arg_type.get_notnull()) + "\n" +
1273  std::to_string(target_info.skip_null_val) + "\n" +
1274  std::to_string(target_info.is_distinct);
1275 }
1276 
1277 } // namespace
1278 
1279 std::string ResultSetReductionJIT::cacheKey() const {
1280  std::vector<std::string> target_init_vals_strings;
1282  target_init_vals_.end(),
1283  std::back_inserter(target_init_vals_strings),
1284  [](const int64_t v) { return std::to_string(v); });
1285  const auto target_init_vals_key =
1286  boost::algorithm::join(target_init_vals_strings, ", ");
1287  std::vector<std::string> targets_strings;
1289  targets_.begin(),
1290  targets_.end(),
1291  std::back_inserter(targets_strings),
1292  [](const TargetInfo& target_info) { return target_info_key(target_info); });
1293  const auto targets_key = boost::algorithm::join(targets_strings, ", ");
1294  return query_mem_desc_.reductionKey() + "\n" + target_init_vals_key + "\n" +
1295  targets_key;
1296 }
1297 
1299  const auto hash_type = query_mem_desc_.getQueryDescriptionType();
1300  auto reduction_code = setup_functions_ir(hash_type);
1302  isEmpty(reduction_code);
1303  reduceOneEntryNoCollisions(reduction_code);
1304  reduceOneEntryNoCollisionsIdx(reduction_code);
1305  reduceLoop(reduction_code);
1306  auto executor = Executor::getExecutor(executor_id_);
1307  auto cgen_state_ = std::unique_ptr<CgenState>(new CgenState({}, false, executor.get()));
1308  auto cgen_state = reduction_code.cgen_state = cgen_state_.get();
1309  // CHECK(executor->thread_id_ == logger::thread_id()); // do we need compilation mutex?
1310  cgen_state->set_module_shallow_copy(executor->get_rt_module());
1311  reduction_code.module = cgen_state->module_;
1312 
1313  AUTOMATIC_IR_METADATA(cgen_state);
1314  auto ir_is_empty = create_llvm_function(reduction_code.ir_is_empty.get(), cgen_state);
1315  auto ir_reduce_one_entry =
1316  create_llvm_function(reduction_code.ir_reduce_one_entry.get(), cgen_state);
1317  auto ir_reduce_one_entry_idx =
1318  create_llvm_function(reduction_code.ir_reduce_one_entry_idx.get(), cgen_state);
1319  auto ir_reduce_loop =
1320  create_llvm_function(reduction_code.ir_reduce_loop.get(), cgen_state);
1321  std::unordered_map<const Function*, llvm::Function*> f;
1322  f.emplace(reduction_code.ir_is_empty.get(), ir_is_empty);
1323  f.emplace(reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry);
1324  f.emplace(reduction_code.ir_reduce_one_entry_idx.get(), ir_reduce_one_entry_idx);
1325  f.emplace(reduction_code.ir_reduce_loop.get(), ir_reduce_loop);
1326  translate_function(reduction_code.ir_is_empty.get(), ir_is_empty, reduction_code, f);
1328  reduction_code.ir_reduce_one_entry.get(), ir_reduce_one_entry, reduction_code, f);
1329  translate_function(reduction_code.ir_reduce_one_entry_idx.get(),
1330  ir_reduce_one_entry_idx,
1331  reduction_code,
1332  f);
1334  reduction_code.ir_reduce_loop.get(), ir_reduce_loop, reduction_code, f);
1335  reduction_code.llvm_reduce_loop = ir_reduce_loop;
1336  reduction_code.cgen_state = nullptr;
1337  return reduction_code;
1338 }
GroupValueInfo get_group_value_reduction(int64_t *groups_buffer, const uint32_t groups_buffer_entry_count, const int64_t *key, const uint32_t key_count, const size_t key_width, const QueryMemoryDescriptor &query_mem_desc, const int64_t *that_buff_i64, const size_t that_entry_idx, const size_t that_entry_count, const uint32_t row_size_quad)
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:230
CgenState * cgen_state
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
bool is_aggregate_query(const QueryDescriptionType hash_type)
void count_distinct_set_union(const int64_t new_set_handle, const int64_t old_set_handle, const CountDistinctDescriptor &new_count_distinct_desc, const CountDistinctDescriptor &old_count_distinct_desc)
__device__ bool dynamic_watchdog()
#define EMPTY_KEY_64
const std::string & label() const
RUNTIME_EXPORT uint8_t check_watchdog_rt(const size_t sample_seed)
void reduceOneEntryNoCollisions(const ReductionCode &reduction_code) const
int64_t getTargetGroupbyIndex(const size_t target_idx) const
void varlen_buffer_sample(int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const int64_t init_val)
std::unique_ptr< Function > ir_reduce_loop
Value * emit_read_int_from_buff(Value *ptr, const int8_t compact_sz, Function *function)
void reduceOneEntryBaselineIdx(const ReductionCode &reduction_code) const
SQLTypeInfo sql_type
Definition: TargetInfo.h:52
#define LOG(tag)
Definition: Logger.h:216
void mark_function_always_inline(llvm::Function *func)
Calculate approximate median and general quantiles, based on &quot;Computing Extremely Accurate Quantiles ...
void reduceLoop(const ReductionCode &reduction_code) const
bool is_varlen() const
Definition: sqltypes.h:615
std::string join(T const &container, std::string const &delim)
llvm::Function * llvm_reduce_loop
void reduceOneEntryNoCollisionsIdx(const ReductionCode &reduction_code) const
#define CHECK_GE(x, y)
Definition: Logger.h:235
std::vector< std::string > CodeCacheKey
Definition: CodeCache.h:25
size_t get_slot_off_quad(const QueryMemoryDescriptor &query_mem_desc)
std::string cacheKey() const
size_t getEffectiveKeyWidth() const
std::unique_ptr< Function > ir_reduce_one_entry
bool g_enable_dynamic_watchdog
Definition: Execute.cpp:80
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
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:111
bool g_enable_non_kernel_time_query_interrupt
Definition: Execute.cpp:126
Value * add(Args &&...args)
bool skip_null_val
Definition: TargetInfo.h:54
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)
std::unique_ptr< Function > setup_reduce_one_entry_idx(ReductionCode *reduction_code)
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_
std::unique_ptr< Function > ir_is_empty
constexpr double f
Definition: Utm.h:31
std::string to_string(char const *&&v)
SQLTypeInfo agg_arg_type
Definition: TargetInfo.h:53
void translate_function(const Function *function, llvm::Function *llvm_function, const ReductionCode &reduction_code, const std::unordered_map< const Function *, llvm::Function * > &f)
void emit_aggregate_one_value(const std::string &agg_kind, Value *val_ptr, Value *other_ptr, const size_t chosen_bytes, const TargetInfo &agg_info, Function *ir_reduce_one_entry)
RUNTIME_EXPORT void serialized_varlen_buffer_sample(const void *serialized_varlen_buffer_handle, int8_t *this_ptr1, int8_t *this_ptr2, const int8_t *that_ptr1, const int8_t *that_ptr2, const int64_t init_val, const int64_t length_to_elems)
Value * emit_load_i32(Value *ptr, Function *function)
Definition: sqldefs.h:74
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
const SQLTypeInfo get_compact_type(const TargetInfo &target)
__device__ bool check_interrupt()
int8_t get_width_for_slot(const size_t target_slot_idx, const bool float_argument_input, const QueryMemoryDescriptor &query_mem_desc)
llvm::Module * module_
Definition: CgenState.h:430
llvm::LLVMContext & context_
Definition: CgenState.h:439
size_t get_byteoff_of_slot(const size_t slot_idx, const QueryMemoryDescriptor &query_mem_desc)
bool is_agg
Definition: TargetInfo.h:50
size_t advance_slot(const size_t j, const TargetInfo &target_info, const bool separate_varlen_storage)
void reduceOneCountDistinctSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
uint8_t check_interrupt_rt(const size_t sample_seed)
size_t getGroupbyColCount() const
size_t targetGroupbyIndicesSize() const
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)
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)
Definition: sqldefs.h:76
ReductionCode codegen() const override
bool is_distinct_target(const TargetInfo &target_info)
Definition: TargetInfo.h:107
std::string target_info_key(const TargetInfo &target_info)
OUTPUT transform(INPUT const &input, FUNC const &func)
Definition: misc.h:296
std::unique_ptr< Function > ir_reduce_one_entry_idx
const int8_t getPaddedSlotWidthBytes(const size_t slot_idx) const
ReductionCode setup_functions_ir(const QueryDescriptionType hash_type)
DEVICE void allocate()
Definition: quantile.h:601
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::unique_ptr< Function > setup_is_empty_entry(ReductionCode *reduction_code)
SQLAgg agg_kind
Definition: TargetInfo.h:51
size_t getCountDistinctDescriptorsSize() const
void reduceOneEntryTargetsNoCollisions(Function *ir_reduce_one_entry, Value *this_targets_start_ptr, Value *that_targets_start_ptr) const
QueryDescriptionType getQueryDescriptionType() const
#define AUTOMATIC_IR_METADATA_DONE()
#define UNLIKELY(x)
Definition: likely.h:25
void set_module_shallow_copy(const std::unique_ptr< llvm::Module > &module, bool always_clone=false)
Definition: CgenState.cpp:384
#define RUNTIME_EXPORT
llvm::Type * llvm_type(const Type type, llvm::LLVMContext &ctx)
virtual ReductionCode codegen() const
const CountDistinctDescriptor & getCountDistinctDescriptor(const size_t idx) const
llvm::Module * module
#define CHECK_LT(x, y)
Definition: Logger.h:232
std::string serialize_llvm_object(const T *llvm_obj)
size_t get_row_bytes(const QueryMemoryDescriptor &query_mem_desc)
RUNTIME_EXPORT void count_distinct_set_union_jit_rt(const int64_t new_set_handle, const int64_t old_set_handle, const void *that_qmd_handle, const void *this_qmd_handle, const int64_t target_logical_idx)
void 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
Definition: sqldefs.h:77
std::unique_ptr< Function > create_function(const std::string name, const std::vector< Function::NamedArg > &arg_types, const Type ret_type, const bool always_inline)
std::string get_type_name() const
Definition: sqltypes.h:503
const Value * iter() const
RUNTIME_EXPORT void approx_quantile_jit_rt(const int64_t new_set_handle, const int64_t old_set_handle, const void *that_qmd_handle, const void *this_qmd_handle, const int64_t target_logical_idx)
RUNTIME_EXPORT void get_group_value_reduction_rt(int8_t *groups_buffer, const int8_t *key, const uint32_t key_count, const void *this_qmd_handle, const int8_t *that_buff, const uint32_t that_entry_idx, const uint32_t that_entry_count, const uint32_t row_size_bytes, int64_t **buff_out, uint8_t *empty)
std::unique_ptr< Function > setup_reduce_one_entry(ReductionCode *reduction_code, const QueryDescriptionType hash_type)
void isEmpty(const ReductionCode &reduction_code) const
Value * emit_load_i64(Value *ptr, Function *function)
const ColSlotContext & getColSlotContext() const
#define CHECK(condition)
Definition: Logger.h:222
bool is_geometry() const
Definition: sqltypes.h:587
#define EMPTY_KEY_32
void reduceOneEntryBaseline(const ReductionCode &reduction_code) const
QueryDescriptionType
Definition: Types.h:29
static std::shared_ptr< QueryEngine > getInstance()
Definition: QueryEngine.h:81
Value * emit_load(Value *ptr, Type ptr_type, Function *function)
bool is_string() const
Definition: sqltypes.h:575
llvm::Function * create_llvm_function(const Function *function, CgenState *cgen_state)
ResultSetReductionJIT(const QueryMemoryDescriptor &query_mem_desc, const std::vector< TargetInfo > &targets, const std::vector< int64_t > &target_init_vals, const size_t executor_id)
string name
Definition: setup.in.py:72
bool is_distinct
Definition: TargetInfo.h:55
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:386
void emit_aggregate_one_count(Value *val_ptr, Value *other_ptr, const size_t chosen_bytes, Function *ir_reduce_one_entry)
Definition: sqldefs.h:75
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:956
Definition: sqldefs.h:73
void reduceOneApproxQuantileSlot(Value *this_ptr1, Value *that_ptr1, const size_t target_logical_idx, Function *ir_reduce_one_entry) const
std::unique_ptr< Function > setup_reduce_loop(ReductionCode *reduction_code)
size_t get_key_bytes_rowwise(const QueryMemoryDescriptor &query_mem_desc)
FORCE_INLINE HOST DEVICE T align_to_int64(T addr)
std::string reductionKey() const
const Executor * getExecutor() const
int32_t getTargetIdxForKey() const
const std::vector< TargetInfo > targets_