OmniSciDB  04ee39c94c
anonymous_namespace{ResultSetReductionJIT.cpp} Namespace Reference

Functions

std::unique_ptr< llvm::Module > runtime_module_shallow_copy (CgenState *cgen_state)
 
llvm::Value * emit_load (llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
 
llvm::Value * emit_load_i32 (llvm::Value *ptr, CgenState *cgen_state)
 
llvm::Value * emit_load_i64 (llvm::Value *ptr, CgenState *cgen_state)
 
llvm::Value * emit_read_int_from_buff (llvm::Value *ptr, const int8_t compact_sz, CgenState *cgen_state)
 
void emit_aggregate_one_value (const std::string &agg_kind, llvm::Value *val_ptr, llvm::Value *other_ptr, const size_t chosen_bytes, const TargetInfo &agg_info, CgenState *cgen_state)
 
void emit_aggregate_one_nullable_value (const std::string &agg_kind, llvm::Value *val_ptr, llvm::Value *other_ptr, const int64_t init_val, const size_t chosen_bytes, const TargetInfo &agg_info, CgenState *cgen_state)
 
void emit_aggregate_one_count (llvm::Value *val_ptr, llvm::Value *other_ptr, const size_t chosen_bytes, CgenState *cgen_state)
 
void emit_write_projection (llvm::Value *slot_pi8, llvm::Value *other_pi8, const int64_t init_val, const size_t chosen_bytes, CgenState *cgen_state)
 
llvm::Function * setup_is_empty_entry (const CgenState *cgen_state)
 
llvm::Function * setup_reduce_one_entry (const CgenState *cgen_state, const QueryDescriptionType hash_type)
 
llvm::Function * setup_reduce_one_entry_idx (const CgenState *cgen_state)
 
llvm::Function * setup_reduce_loop (const CgenState *cgen_state)
 
ReductionCode setup_functions_ir (const QueryDescriptionType hash_type)
 
ExecutionEngineWrapper create_interpreter_engine (llvm::Function *func)
 
bool is_group_query (const QueryDescriptionType hash_type)
 
void return_early (llvm::Value *cond, const ReductionCode &reduction_code, llvm::Function *func, int error_code)
 
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)
 
llvm::BasicBlock * generate_loop_body (const ReductionCode &reduction_code, llvm::Value *this_buff, llvm::Value *that_buff, llvm::Value *iterator, llvm::Value *start_index, llvm::Value *that_entry_count, llvm::Value *this_qmd_handle, llvm::Value *that_qmd_handle, llvm::Value *serialized_varlen_buffer, bool emit_watchdog_check)
 

Variables

const int32_t WATCHDOG_ERROR {-1}
 
const size_t INTERP_THRESHOLD {50}
 

Function Documentation

◆ create_interpreter_engine()

ExecutionEngineWrapper anonymous_namespace{ResultSetReductionJIT.cpp}::create_interpreter_engine ( llvm::Function *  func)

Definition at line 399 of file ResultSetReductionJIT.cpp.

References CHECK.

Referenced by ResultSetReductionJIT::finalizeReductionCode().

399  {
400  auto module = func->getParent();
401 
402  llvm::ExecutionEngine* execution_engine{nullptr};
403 
404  std::string err_str;
405  std::unique_ptr<llvm::Module> owner(module);
406  llvm::EngineBuilder eb(std::move(owner));
407  eb.setErrorStr(&err_str);
408  eb.setEngineKind(llvm::EngineKind::Interpreter);
409  execution_engine = eb.create();
410  CHECK(execution_engine);
411 
412  return ExecutionEngineWrapper(execution_engine);
413 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ emit_aggregate_one_count()

void anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count ( llvm::Value *  val_ptr,
llvm::Value *  other_ptr,
const size_t  chosen_bytes,
CgenState cgen_state 
)

Definition at line 212 of file ResultSetReductionJIT.cpp.

References CHECK_EQ, CgenState::context_, emit_load(), CgenState::emitCall(), and CgenState::ir_builder_.

Referenced by ResultSetReductionJIT::reduceOneAggregateSlot().

215  {
216  const auto dest_name = "count_dest";
217  if (chosen_bytes == sizeof(int32_t)) {
218  const auto pi32_type = llvm::Type::getInt32PtrTy(cgen_state->context_);
219  const auto agg = cgen_state->ir_builder_.CreateBitCast(val_ptr, pi32_type, dest_name);
220  const auto val = emit_load(other_ptr, pi32_type, cgen_state);
221  cgen_state->emitCall("agg_sum_int32", {agg, val});
222  } else {
223  CHECK_EQ(chosen_bytes, sizeof(int64_t));
224  const auto pi64_type = llvm::Type::getInt64PtrTy(cgen_state->context_);
225  const auto agg = cgen_state->ir_builder_.CreateBitCast(val_ptr, pi64_type, dest_name);
226  const auto val = emit_load(other_ptr, pi64_type, cgen_state);
227  cgen_state->emitCall("agg_sum", {agg, val});
228  }
229 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Value * emit_load(llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
llvm::LLVMContext & context_
Definition: CgenState.h:266
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value *> &args)
Definition: CgenState.cpp:134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_aggregate_one_nullable_value()

void anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value ( const std::string &  agg_kind,
llvm::Value *  val_ptr,
llvm::Value *  other_ptr,
const int64_t  init_val,
const size_t  chosen_bytes,
const TargetInfo agg_info,
CgenState cgen_state 
)

Definition at line 155 of file ResultSetReductionJIT.cpp.

References CHECK_EQ, CgenState::context_, emit_aggregate_one_value(), emit_load(), CgenState::emitCall(), get_compact_type(), CgenState::ir_builder_, CgenState::llFp(), CgenState::llInt(), and TargetInfo::skip_null_val.

Referenced by ResultSetReductionJIT::reduceOneAggregateSlot().

161  {
162  const auto dest_name = agg_kind + "_dest";
163  if (agg_info.skip_null_val) {
164  const auto pi32_type = llvm::Type::getInt32PtrTy(cgen_state->context_);
165  const auto pi64_type = llvm::Type::getInt64PtrTy(cgen_state->context_);
166  const auto pf32_type = llvm::Type::getFloatPtrTy(cgen_state->context_);
167  const auto pf64_type = llvm::Type::getDoublePtrTy(cgen_state->context_);
168  const auto sql_type = get_compact_type(agg_info);
169  if (sql_type.is_fp()) {
170  if (chosen_bytes == sizeof(float)) {
171  const auto agg =
172  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi32_type, dest_name);
173  const auto val = emit_load(other_ptr, pf32_type, cgen_state);
174  const auto init_val_lv =
175  cgen_state->llFp(*reinterpret_cast<const float*>(may_alias_ptr(&init_val)));
176  cgen_state->emitCall("agg_" + agg_kind + "_float_skip_val",
177  {agg, val, init_val_lv});
178  } else {
179  CHECK_EQ(chosen_bytes, sizeof(double));
180  const auto agg =
181  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi64_type, dest_name);
182  const auto val = emit_load(other_ptr, pf64_type, cgen_state);
183  const auto init_val_lv =
184  cgen_state->llFp(*reinterpret_cast<const double*>(may_alias_ptr(&init_val)));
185  cgen_state->emitCall("agg_" + agg_kind + "_double_skip_val",
186  {agg, val, init_val_lv});
187  }
188  } else {
189  if (chosen_bytes == sizeof(int32_t)) {
190  const auto agg =
191  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi32_type, dest_name);
192  const auto val = emit_load(other_ptr, pi32_type, cgen_state);
193  const auto init_val_lv = cgen_state->llInt<int32_t>(init_val);
194  cgen_state->emitCall("agg_" + agg_kind + "_int32_skip_val",
195  {agg, val, init_val_lv});
196  } else {
197  CHECK_EQ(chosen_bytes, sizeof(int64_t));
198  const auto agg =
199  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi64_type, dest_name);
200  const auto val = emit_load(other_ptr, pi64_type, cgen_state);
201  const auto init_val_lv = cgen_state->llInt<int64_t>(init_val);
202  cgen_state->emitCall("agg_" + agg_kind + "_skip_val", {agg, val, init_val_lv});
203  }
204  }
205  } else {
207  agg_kind, val_ptr, other_ptr, chosen_bytes, agg_info, cgen_state);
208  }
209 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:251
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
bool skip_null_val
Definition: TargetInfo.h:44
llvm::Value * emit_load(llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
const SQLTypeInfo get_compact_type(const TargetInfo &target)
llvm::LLVMContext & context_
Definition: CgenState.h:266
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value *> &args)
Definition: CgenState.cpp:134
void emit_aggregate_one_value(const std::string &agg_kind, llvm::Value *val_ptr, llvm::Value *other_ptr, const size_t chosen_bytes, const TargetInfo &agg_info, CgenState *cgen_state)
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:247
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_aggregate_one_value()

void anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value ( const std::string &  agg_kind,
llvm::Value *  val_ptr,
llvm::Value *  other_ptr,
const size_t  chosen_bytes,
const TargetInfo agg_info,
CgenState cgen_state 
)

Definition at line 113 of file ResultSetReductionJIT.cpp.

References CHECK_EQ, CgenState::context_, emit_load(), CgenState::emitCall(), get_compact_type(), and CgenState::ir_builder_.

Referenced by emit_aggregate_one_nullable_value().

118  {
119  const auto sql_type = get_compact_type(agg_info);
120  const auto pi32_type = llvm::Type::getInt32PtrTy(cgen_state->context_);
121  const auto pi64_type = llvm::Type::getInt64PtrTy(cgen_state->context_);
122  const auto pf32_type = llvm::Type::getFloatPtrTy(cgen_state->context_);
123  const auto pf64_type = llvm::Type::getDoublePtrTy(cgen_state->context_);
124  const auto dest_name = agg_kind + "_dest";
125  if (sql_type.is_fp()) {
126  if (chosen_bytes == sizeof(float)) {
127  const auto agg =
128  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi32_type, dest_name);
129  const auto val = emit_load(other_ptr, pf32_type, cgen_state);
130  cgen_state->emitCall("agg_" + agg_kind + "_float", {agg, val});
131  } else {
132  CHECK_EQ(chosen_bytes, sizeof(double));
133  const auto agg =
134  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi64_type, dest_name);
135  const auto val = emit_load(other_ptr, pf64_type, cgen_state);
136  cgen_state->emitCall("agg_" + agg_kind + "_double", {agg, val});
137  }
138  } else {
139  if (chosen_bytes == sizeof(int32_t)) {
140  const auto agg =
141  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi32_type, dest_name);
142  const auto val = emit_load(other_ptr, pi32_type, cgen_state);
143  cgen_state->emitCall("agg_" + agg_kind + "_int32", {agg, val});
144  } else {
145  CHECK_EQ(chosen_bytes, sizeof(int64_t));
146  const auto agg =
147  cgen_state->ir_builder_.CreateBitCast(val_ptr, pi64_type, dest_name);
148  const auto val = emit_load(other_ptr, pi64_type, cgen_state);
149  cgen_state->emitCall("agg_" + agg_kind, {agg, val});
150  }
151  }
152 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Value * emit_load(llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
const SQLTypeInfo get_compact_type(const TargetInfo &target)
llvm::LLVMContext & context_
Definition: CgenState.h:266
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value *> &args)
Definition: CgenState.cpp:134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_load()

llvm::Value* anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load ( llvm::Value *  ptr,
llvm::Type *  loaded_type,
CgenState cgen_state 
)

Definition at line 72 of file ResultSetReductionJIT.cpp.

References CgenState::ir_builder_.

Referenced by emit_aggregate_one_count(), emit_aggregate_one_nullable_value(), emit_aggregate_one_value(), emit_load_i32(), and emit_load_i64().

72  {
73  return cgen_state->ir_builder_.CreateLoad(
74  cgen_state->ir_builder_.CreateBitCast(ptr, loaded_type),
75  ptr->getName() + "_loaded");
76 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
+ Here is the caller graph for this function:

◆ emit_load_i32()

llvm::Value* anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i32 ( llvm::Value *  ptr,
CgenState cgen_state 
)

Definition at line 79 of file ResultSetReductionJIT.cpp.

References CgenState::context_, and emit_load().

Referenced by emit_read_int_from_buff(), emit_write_projection(), and ResultSetReductionJIT::isEmpty().

79  {
80  const auto pi32_type = llvm::Type::getInt32PtrTy(cgen_state->context_);
81  return emit_load(ptr, pi32_type, cgen_state);
82 }
llvm::Value * emit_load(llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_load_i64()

llvm::Value* anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64 ( llvm::Value *  ptr,
CgenState cgen_state 
)

Definition at line 85 of file ResultSetReductionJIT.cpp.

References CgenState::context_, and emit_load().

Referenced by emit_read_int_from_buff(), emit_write_projection(), ResultSetReductionJIT::isEmpty(), and ResultSetReductionJIT::reduceOneCountDistinctSlot().

85  {
86  const auto pi64_type = llvm::Type::getInt64PtrTy(cgen_state->context_);
87  return emit_load(ptr, pi64_type, cgen_state);
88 }
llvm::Value * emit_load(llvm::Value *ptr, llvm::Type *loaded_type, CgenState *cgen_state)
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_read_int_from_buff()

llvm::Value* anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff ( llvm::Value *  ptr,
const int8_t  compact_sz,
CgenState cgen_state 
)

Definition at line 91 of file ResultSetReductionJIT.cpp.

References CgenState::context_, emit_load_i32(), emit_load_i64(), logger::FATAL, get_int_type(), CgenState::ir_builder_, and LOG.

Referenced by ResultSetReductionJIT::isEmpty().

93  {
94  switch (compact_sz) {
95  case 8: {
96  return emit_load_i64(ptr, cgen_state);
97  }
98  case 4: {
99  const auto loaded_val = emit_load_i32(ptr, cgen_state);
100  auto& ctx = cgen_state->context_;
101  const auto i64_type = get_int_type(64, ctx);
102  return cgen_state->ir_builder_.CreateSExt(loaded_val, i64_type);
103  }
104  default: {
105  LOG(FATAL) << "Invalid byte width: " << compact_sz;
106  return nullptr;
107  }
108  }
109 }
#define LOG(tag)
Definition: Logger.h:182
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Value * emit_load_i32(llvm::Value *ptr, CgenState *cgen_state)
llvm::LLVMContext & context_
Definition: CgenState.h:266
llvm::Value * emit_load_i64(llvm::Value *ptr, CgenState *cgen_state)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emit_write_projection()

void anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection ( llvm::Value *  slot_pi8,
llvm::Value *  other_pi8,
const int64_t  init_val,
const size_t  chosen_bytes,
CgenState cgen_state 
)

Definition at line 234 of file ResultSetReductionJIT.cpp.

References CHECK_EQ, emit_load_i32(), emit_load_i64(), CgenState::emitCall(), CgenState::llInt(), and to_string().

Referenced by ResultSetReductionJIT::reduceOneSlot().

238  {
239  const auto func_name = "write_projection_int" + std::to_string(chosen_bytes * 8);
240  if (chosen_bytes == sizeof(int32_t)) {
241  const auto proj_val = emit_load_i32(other_pi8, cgen_state);
242  cgen_state->emitCall(func_name,
243  {slot_pi8, proj_val, cgen_state->llInt<int64_t>(init_val)});
244  } else {
245  CHECK_EQ(chosen_bytes, sizeof(int64_t));
246  const auto proj_val = emit_load_i64(other_pi8, cgen_state);
247  cgen_state->emitCall(func_name,
248  {slot_pi8, proj_val, cgen_state->llInt<int64_t>(init_val)});
249  }
250 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
std::string to_string(char const *&&v)
llvm::Value * emit_load_i32(llvm::Value *ptr, CgenState *cgen_state)
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value *> &args)
Definition: CgenState.cpp:134
llvm::Value * emit_load_i64(llvm::Value *ptr, CgenState *cgen_state)
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:247
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generate_loop_body()

llvm::BasicBlock* anonymous_namespace{ResultSetReductionJIT.cpp}::generate_loop_body ( const ReductionCode reduction_code,
llvm::Value *  this_buff,
llvm::Value *  that_buff,
llvm::Value *  iterator,
llvm::Value *  start_index,
llvm::Value *  that_entry_count,
llvm::Value *  this_qmd_handle,
llvm::Value *  that_qmd_handle,
llvm::Value *  serialized_varlen_buffer,
bool  emit_watchdog_check 
)

Definition at line 940 of file ResultSetReductionJIT.cpp.

References ReductionCode::cgen_state, get_int_type(), ReductionCode::ir_reduce_loop, ReductionCode::ir_reduce_one_entry_idx, return_early(), and WATCHDOG_ERROR.

Referenced by ResultSetReductionJIT::reduceLoop().

949  {
950  auto cgen_state = reduction_code.cgen_state.get();
951  auto& ir_builder = cgen_state->ir_builder_;
952  auto& ctx = cgen_state->context_;
953  const auto loop_body_bb = llvm::BasicBlock::Create(
954  ctx, ".loop_body", ir_builder.GetInsertBlock()->getParent());
955  ir_builder.SetInsertPoint(loop_body_bb);
956  const auto loop_iter =
957  ir_builder.CreateTrunc(iterator, get_int_type(32, ctx), "relative_entry_idx");
958  const auto that_entry_idx =
959  ir_builder.CreateAdd(loop_iter, start_index, "that_entry_idx");
960  if (emit_watchdog_check) {
961  const auto watchdog_sample_seed =
962  ir_builder.CreateSExt(that_entry_idx, get_int_type(64, ctx));
963  const auto watchdog_triggered = cgen_state->emitExternalCall(
964  "check_watchdog_rt", get_int_type(8, ctx), {watchdog_sample_seed});
965  const auto watchdog_triggered_bool = cgen_state->ir_builder_.CreateICmpNE(
966  watchdog_triggered, cgen_state->llInt<int8_t>(0));
967  return_early(watchdog_triggered_bool,
968  reduction_code,
969  reduction_code.ir_reduce_loop,
971  }
972  ir_builder.CreateCall(reduction_code.ir_reduce_one_entry_idx,
973  {this_buff,
974  that_buff,
975  that_entry_idx,
976  that_entry_count,
977  this_qmd_handle,
978  that_qmd_handle,
979  serialized_varlen_buffer});
980  return loop_body_bb;
981 }
std::unique_ptr< CgenState > cgen_state
void return_early(llvm::Value *cond, const ReductionCode &reduction_code, llvm::Function *func, int error_code)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Function * ir_reduce_one_entry_idx
llvm::Function * ir_reduce_loop
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_group_query()

bool anonymous_namespace{ResultSetReductionJIT.cpp}::is_group_query ( const QueryDescriptionType  hash_type)

Definition at line 415 of file ResultSetReductionJIT.cpp.

References GroupByBaselineHash, and GroupByPerfectHash.

Referenced by ResultSetReductionJIT::codegen(), and ResultSetReductionJIT::isEmpty().

+ Here is the caller graph for this function:

◆ return_early()

void anonymous_namespace{ResultSetReductionJIT.cpp}::return_early ( llvm::Value *  cond,
const ReductionCode reduction_code,
llvm::Function *  func,
int  error_code 
)

Definition at line 424 of file ResultSetReductionJIT.cpp.

References ReductionCode::cgen_state.

Referenced by generate_loop_body(), ResultSetReductionJIT::reduceOneEntryBaselineIdx(), and ResultSetReductionJIT::reduceOneEntryNoCollisions().

427  {
428  auto cgen_state = reduction_code.cgen_state.get();
429  auto& ctx = cgen_state->context_;
430  const auto early_return = llvm::BasicBlock::Create(ctx, ".early_return", func, 0);
431  const auto do_reduction = llvm::BasicBlock::Create(ctx, ".do_reduction", func, 0);
432  cgen_state->ir_builder_.CreateCondBr(cond, early_return, do_reduction);
433  cgen_state->ir_builder_.SetInsertPoint(early_return);
434  if (func->getReturnType()->isVoidTy()) {
435  cgen_state->ir_builder_.CreateRetVoid();
436  } else {
437  cgen_state->ir_builder_.CreateRet(cgen_state->llInt<int32_t>(error_code));
438  }
439  cgen_state->ir_builder_.SetInsertPoint(do_reduction);
440 }
std::unique_ptr< CgenState > cgen_state
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t uint32_t const int64_t int32_t * error_code
+ Here is the caller graph for this function:

◆ runtime_module_shallow_copy()

std::unique_ptr<llvm::Module> anonymous_namespace{ResultSetReductionJIT.cpp}::runtime_module_shallow_copy ( CgenState cgen_state)

Definition at line 53 of file ResultSetReductionJIT.cpp.

References g_rt_module, and CgenState::vmap_.

Referenced by setup_functions_ir().

53  {
54  return llvm::CloneModule(
55 #if LLVM_VERSION_MAJOR >= 7
56  *g_rt_module.get(),
57 #else
58  g_rt_module.get(),
59 #endif
60  cgen_state->vmap_,
61  [](const llvm::GlobalValue* gv) {
62  auto func = llvm::dyn_cast<llvm::Function>(gv);
63  if (!func) {
64  return true;
65  }
66  return (func->getLinkage() == llvm::GlobalValue::LinkageTypes::PrivateLinkage ||
67  func->getLinkage() == llvm::GlobalValue::LinkageTypes::InternalLinkage);
68  });
69 }
std::unique_ptr< llvm::Module > g_rt_module
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:267
+ Here is the caller graph for this function:

◆ setup_functions_ir()

ReductionCode anonymous_namespace{ResultSetReductionJIT.cpp}::setup_functions_ir ( const QueryDescriptionType  hash_type)

Definition at line 383 of file ResultSetReductionJIT.cpp.

References ReductionCode::cgen_state, runtime_module_shallow_copy(), setup_is_empty_entry(), setup_reduce_loop(), setup_reduce_one_entry(), and setup_reduce_one_entry_idx().

Referenced by ResultSetReductionJIT::codegen().

383  {
384  ReductionCode reduction_code{};
385  reduction_code.cgen_state.reset(new CgenState({}, false));
386  auto cgen_state = reduction_code.cgen_state.get();
387  std::unique_ptr<llvm::Module> module(runtime_module_shallow_copy(cgen_state));
388  cgen_state->module_ = module.get();
389  reduction_code.ir_is_empty = setup_is_empty_entry(cgen_state);
390  reduction_code.ir_reduce_one_entry = setup_reduce_one_entry(cgen_state, hash_type);
391  reduction_code.ir_reduce_one_entry_idx = setup_reduce_one_entry_idx(cgen_state);
392  reduction_code.ir_reduce_loop = setup_reduce_loop(cgen_state);
393  reduction_code.module = std::move(module);
394  return reduction_code;
395 }
std::unique_ptr< CgenState > cgen_state
llvm::Function * setup_reduce_one_entry(const CgenState *cgen_state, const QueryDescriptionType hash_type)
std::unique_ptr< llvm::Module > runtime_module_shallow_copy(CgenState *cgen_state)
llvm::Function * setup_is_empty_entry(const CgenState *cgen_state)
llvm::Function * setup_reduce_loop(const CgenState *cgen_state)
llvm::Function * setup_reduce_one_entry_idx(const CgenState *cgen_state)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_is_empty_entry()

llvm::Function* anonymous_namespace{ResultSetReductionJIT.cpp}::setup_is_empty_entry ( const CgenState cgen_state)

Definition at line 254 of file ResultSetReductionJIT.cpp.

References CgenState::context_, get_int_type(), mark_function_always_inline(), and CgenState::module_.

Referenced by setup_functions_ir().

254  {
255  auto& ctx = cgen_state->context_;
256  const auto pi8_type = llvm::PointerType::get(get_int_type(8, ctx), 0);
257  const auto func_type = llvm::FunctionType::get(get_int_type(1, ctx), {pi8_type}, false);
258  auto func = llvm::Function::Create(
259  func_type, llvm::Function::PrivateLinkage, "is_empty_entry", cgen_state->module_);
260  const auto arg_it = func->arg_begin();
261  const auto row_ptr_arg = &*arg_it;
262  row_ptr_arg->setName("row_ptr");
264  return func;
265 }
void mark_function_always_inline(llvm::Function *func)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_reduce_loop()

llvm::Function* anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_loop ( const CgenState cgen_state)

Definition at line 344 of file ResultSetReductionJIT.cpp.

References CgenState::context_, get_int_type(), and CgenState::module_.

Referenced by setup_functions_ir().

344  {
345  auto& ctx = cgen_state->context_;
346  const auto pi8_type = llvm::PointerType::get(get_int_type(8, ctx), 0);
347  const auto i32_type = get_int_type(32, ctx);
348  const auto pvoid_type = llvm::PointerType::get(llvm::Type::getVoidTy(ctx), 0);
349  const auto func_type = llvm::FunctionType::get(i32_type,
350  {pi8_type,
351  pi8_type,
352  i32_type,
353  i32_type,
354  i32_type,
355  pvoid_type,
356  pvoid_type,
357  pvoid_type},
358  false);
359  auto func = llvm::Function::Create(
360  func_type, llvm::Function::ExternalLinkage, "reduce_loop", cgen_state->module_);
361  const auto arg_it = func->arg_begin();
362  const auto this_buff_arg = &*arg_it;
363  const auto that_buff_arg = &*(arg_it + 1);
364  const auto start_index_arg = &*(arg_it + 2);
365  const auto end_index_arg = &*(arg_it + 3);
366  const auto that_entry_count_arg = &*(arg_it + 4);
367  const auto this_qmd_handle_arg = &*(arg_it + 5);
368  const auto that_qmd_handle_arg = &*(arg_it + 6);
369  const auto serialized_varlen_buffer_arg = &*(arg_it + 7);
370  this_buff_arg->setName("this_buff");
371  that_buff_arg->setName("that_buff");
372  start_index_arg->setName("start_index");
373  end_index_arg->setName("end_index");
374  that_entry_count_arg->setName("that_entry_count");
375  this_qmd_handle_arg->setName("this_qmd_handle");
376  that_qmd_handle_arg->setName("that_qmd_handle");
377  serialized_varlen_buffer_arg->setName("serialized_varlen_buffer");
378  return func;
379 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_reduce_one_entry()

llvm::Function* anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry ( const CgenState cgen_state,
const QueryDescriptionType  hash_type 
)

Definition at line 268 of file ResultSetReductionJIT.cpp.

References CgenState::context_, logger::FATAL, get_int_type(), GroupByBaselineHash, GroupByPerfectHash, LOG, mark_function_always_inline(), and CgenState::module_.

Referenced by setup_functions_ir().

269  {
270  auto& ctx = cgen_state->context_;
271  const auto pi8_type = llvm::PointerType::get(get_int_type(8, ctx), 0);
272  const auto pvoid_type = llvm::PointerType::get(llvm::Type::getVoidTy(ctx), 0);
273  const auto func_type =
274  llvm::FunctionType::get(llvm::Type::getVoidTy(ctx),
275  {pi8_type, pi8_type, pvoid_type, pvoid_type, pvoid_type},
276  false);
277  const auto func = llvm::Function::Create(
278  func_type, llvm::Function::PrivateLinkage, "reduce_one_entry", cgen_state->module_);
279  const auto arg_it = func->arg_begin();
280  switch (hash_type) {
282  const auto this_targets_ptr_arg = &*arg_it;
283  const auto that_targets_ptr_arg = &*(arg_it + 1);
284  this_targets_ptr_arg->setName("this_targets_ptr");
285  that_targets_ptr_arg->setName("that_targets_ptr");
286  break;
287  }
289  const auto this_row_ptr_arg = &*arg_it;
290  const auto that_row_ptr_arg = &*(arg_it + 1);
291  this_row_ptr_arg->setName("this_row_ptr");
292  that_row_ptr_arg->setName("that_row_ptr");
293  break;
294  }
295  default: {
296  LOG(FATAL) << "Unexpected query description type";
297  }
298  }
299  const auto this_qmd_arg = &*(arg_it + 2);
300  const auto that_qmd_arg = &*(arg_it + 3);
301  const auto serialized_varlen_buffer_arg = &*(arg_it + 4);
302  this_qmd_arg->setName("this_qmd");
303  that_qmd_arg->setName("that_qmd");
304  serialized_varlen_buffer_arg->setName("serialized_varlen_buffer_arg");
306  return func;
307 }
#define LOG(tag)
Definition: Logger.h:182
void mark_function_always_inline(llvm::Function *func)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setup_reduce_one_entry_idx()

llvm::Function* anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry_idx ( const CgenState cgen_state)

Definition at line 310 of file ResultSetReductionJIT.cpp.

References CgenState::context_, get_int_type(), mark_function_always_inline(), and CgenState::module_.

Referenced by setup_functions_ir().

310  {
311  auto& ctx = cgen_state->context_;
312  const auto pi8_type = llvm::PointerType::get(get_int_type(8, ctx), 0);
313  const auto i32_type = get_int_type(32, ctx);
314  const auto pvoid_type = llvm::PointerType::get(llvm::Type::getVoidTy(ctx), 0);
315  const auto func_type = llvm::FunctionType::get(
316  llvm::Type::getVoidTy(ctx),
317  {pi8_type, pi8_type, i32_type, i32_type, pvoid_type, pvoid_type, pvoid_type},
318  false);
319  auto func = llvm::Function::Create(func_type,
320  llvm::Function::PrivateLinkage,
321  "reduce_one_entry_idx",
322  cgen_state->module_);
323  const auto arg_it = func->arg_begin();
324  const auto this_buff_arg = &*arg_it;
325  const auto that_buff_arg = &*(arg_it + 1);
326  const auto that_entry_idx_arg = &*(arg_it + 2);
327  const auto that_entry_count_arg = &*(arg_it + 3);
328  const auto this_qmd_handle_arg = &*(arg_it + 4);
329  const auto that_qmd_handle_arg = &*(arg_it + 5);
330  const auto serialized_varlen_buffer_arg = &*(arg_it + 6);
331  this_buff_arg->setName("this_buff");
332  that_buff_arg->setName("that_buff");
333  that_entry_idx_arg->setName("that_entry_idx");
334  that_entry_count_arg->setName("that_entry_count");
335  this_qmd_handle_arg->setName("this_qmd_handle");
336  that_qmd_handle_arg->setName("that_qmd_handle");
337  serialized_varlen_buffer_arg->setName("serialized_varlen_buffer");
339  return func;
340 }
void mark_function_always_inline(llvm::Function *func)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ varlen_buffer_sample()

void anonymous_namespace{ResultSetReductionJIT.cpp}::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 
)

Definition at line 443 of file ResultSetReductionJIT.cpp.

References CHECK.

Referenced by serialized_varlen_buffer_sample().

447  {
448  const auto rhs_proj_col = *reinterpret_cast<const int64_t*>(that_ptr1);
449  if (rhs_proj_col != init_val) {
450  *reinterpret_cast<int64_t*>(this_ptr1) = rhs_proj_col;
451  }
452  CHECK(this_ptr2 && that_ptr2);
453  *reinterpret_cast<int64_t*>(this_ptr2) = *reinterpret_cast<const int64_t*>(that_ptr2);
454 }
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

Variable Documentation

◆ INTERP_THRESHOLD

const size_t anonymous_namespace{ResultSetReductionJIT.cpp}::INTERP_THRESHOLD {50}

Definition at line 49 of file ResultSetReductionJIT.cpp.

Referenced by ResultSetReductionJIT::useInterpreter().

◆ WATCHDOG_ERROR

const int32_t anonymous_namespace{ResultSetReductionJIT.cpp}::WATCHDOG_ERROR {-1}

Definition at line 46 of file ResultSetReductionJIT.cpp.

Referenced by generate_loop_body().