OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CgenState.h
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 #pragma once
18 
19 #include "IRCodegenUtils.h"
20 #include "InValuesBitmap.h"
21 #include "InputMetadata.h"
22 #include "LLVMGlobalContext.h"
24 
25 #include "../Analyzer/Analyzer.h"
26 #include "../Shared/InsertionOrderedMap.h"
27 
28 #include <llvm/IR/Constants.h>
29 #include <llvm/IR/IRBuilder.h>
30 #include <llvm/Transforms/Utils/ValueMapper.h>
31 
33  llvm::Value* buffer;
34  llvm::Value* size;
35  llvm::Value* is_null;
36 };
37 
38 struct CgenState {
39  public:
40  CgenState(const size_t num_query_infos,
41  const bool contains_left_deep_outer_join,
42  Executor* executor);
43  CgenState(const size_t num_query_infos, const bool contains_left_deep_outer_join);
44  CgenState(llvm::LLVMContext& context);
45 
46  std::tuple<size_t, size_t> getOrAddLiteral(const Analyzer::Constant* constant,
47  const EncodingType enc_type,
48  const int dict_id,
49  const int device_id) {
50  const auto& ti = constant->get_type_info();
51  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
52  switch (type) {
53  case kBOOLEAN:
54  return getOrAddLiteral(constant->get_is_null()
55  ? int8_t(inline_int_null_val(ti))
56  : int8_t(constant->get_constval().boolval ? 1 : 0),
57  device_id);
58  case kTINYINT:
59  return getOrAddLiteral(constant->get_is_null()
60  ? int8_t(inline_int_null_val(ti))
61  : constant->get_constval().tinyintval,
62  device_id);
63  case kSMALLINT:
64  return getOrAddLiteral(constant->get_is_null()
65  ? int16_t(inline_int_null_val(ti))
66  : constant->get_constval().smallintval,
67  device_id);
68  case kINT:
69  return getOrAddLiteral(constant->get_is_null() ? int32_t(inline_int_null_val(ti))
70  : constant->get_constval().intval,
71  device_id);
72  case kBIGINT:
73  return getOrAddLiteral(constant->get_is_null()
74  ? int64_t(inline_int_null_val(ti))
75  : constant->get_constval().bigintval,
76  device_id);
77  case kFLOAT:
78  return getOrAddLiteral(constant->get_is_null()
79  ? float(inline_fp_null_val(ti))
80  : constant->get_constval().floatval,
81  device_id);
82  case kDOUBLE:
83  return getOrAddLiteral(constant->get_is_null()
84  ? inline_fp_null_val(ti)
85  : constant->get_constval().doubleval,
86  device_id);
87  case kCHAR:
88  case kTEXT:
89  case kVARCHAR:
90  if (enc_type == kENCODING_DICT) {
91  if (constant->get_is_null()) {
92  return getOrAddLiteral(int32_t(inline_int_null_val(ti)), device_id);
93  }
94  return getOrAddLiteral(
95  std::make_pair(*constant->get_constval().stringval, dict_id), device_id);
96  }
97  CHECK_EQ(kENCODING_NONE, enc_type);
98  if (constant->get_is_null()) {
99  throw std::runtime_error(
100  "CHAR / VARCHAR NULL literal not supported in this context"); // TODO(alex):
101  // support
102  // null
103  }
104  return getOrAddLiteral(*constant->get_constval().stringval, device_id);
105  case kTIME:
106  case kTIMESTAMP:
107  case kDATE:
108  case kINTERVAL_DAY_TIME:
110  // TODO(alex): support null
111  return getOrAddLiteral(constant->get_constval().bigintval, device_id);
112  case kARRAY: {
113  if (enc_type == kENCODING_NONE) {
114  if (ti.get_subtype() == kDOUBLE) {
115  std::vector<double> double_array_literal;
116  for (const auto& value : constant->get_value_list()) {
117  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
118  CHECK(c);
119  double d = c->get_constval().doubleval;
120  double_array_literal.push_back(d);
121  }
122  return getOrAddLiteral(double_array_literal, device_id);
123  }
124  if (ti.get_subtype() == kINT) {
125  std::vector<int32_t> int32_array_literal;
126  for (const auto& value : constant->get_value_list()) {
127  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
128  CHECK(c);
129  int32_t i = c->get_constval().intval;
130  int32_array_literal.push_back(i);
131  }
132  return getOrAddLiteral(int32_array_literal, device_id);
133  }
134  if (ti.get_subtype() == kTINYINT) {
135  std::vector<int8_t> int8_array_literal;
136  for (const auto& value : constant->get_value_list()) {
137  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
138  CHECK(c);
139  int8_t i = c->get_constval().tinyintval;
140  int8_array_literal.push_back(i);
141  }
142  if (ti.get_comp_param() == 64) {
143  return getOrAddLiteral(std::make_pair(int8_array_literal, 64), device_id);
144  }
145  return getOrAddLiteral(int8_array_literal, device_id);
146  }
147  throw std::runtime_error("Unsupported literal array");
148  }
149  if (enc_type == kENCODING_GEOINT) {
150  if (ti.get_subtype() == kTINYINT) {
151  std::vector<int8_t> int8_array_literal;
152  for (const auto& value : constant->get_value_list()) {
153  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
154  CHECK(c);
155  int8_t i = c->get_constval().tinyintval;
156  int8_array_literal.push_back(i);
157  }
158  if (ti.get_comp_param() == 32) {
159  return getOrAddLiteral(std::make_pair(int8_array_literal, 32), device_id);
160  }
161  return getOrAddLiteral(int8_array_literal, device_id);
162  }
163  }
164  throw std::runtime_error("Encoded literal arrays are not supported");
165  }
166  default:
167  abort();
168  }
169  }
170 
171  using LiteralValue = boost::variant<int8_t,
172  int16_t,
173  int32_t,
174  int64_t,
175  float,
176  double,
177  std::pair<std::string, int>,
178  std::string,
179  std::vector<double>,
180  std::vector<int32_t>,
181  std::vector<int8_t>,
182  std::pair<std::vector<int8_t>, int>>;
183  using LiteralValues = std::vector<LiteralValue>;
184 
185  const std::unordered_map<int, LiteralValues>& getLiterals() const { return literals_; }
186 
187  llvm::Value* addStringConstant(const std::string& str) {
188  llvm::Value* str_lv = ir_builder_.CreateGlobalString(
189  str, "str_const_" + std::to_string(std::hash<std::string>()(str)));
190  auto i8_ptr = llvm::PointerType::get(get_int_type(8, context_), 0);
191  str_constants_.push_back(str_lv);
192  str_lv = ir_builder_.CreateBitCast(str_lv, i8_ptr);
193  return str_lv;
194  }
195 
197  std::unique_ptr<const StringDictionaryTranslationMgr>&& str_dict_translation_mgr) {
198  str_dict_translation_mgrs_.emplace_back(std::move(str_dict_translation_mgr));
199  return str_dict_translation_mgrs_.back().get();
200  }
201 
203  std::unique_ptr<InValuesBitmap>& in_values_bitmap) {
204  if (in_values_bitmap->isEmpty()) {
205  return in_values_bitmap.get();
206  }
207  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
208  return in_values_bitmaps_.back().get();
209  }
210  void moveInValuesBitmap(std::unique_ptr<const InValuesBitmap>& in_values_bitmap) {
211  if (!in_values_bitmap->isEmpty()) {
212  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
213  }
214  }
215  // look up a runtime function based on the name, return type and type of
216  // the arguments and call it; x64 only, don't call from GPU codegen
217  llvm::Value* emitExternalCall(
218  const std::string& fname,
219  llvm::Type* ret_type,
220  const std::vector<llvm::Value*> args,
221  const std::vector<llvm::Attribute::AttrKind>& fnattrs = {},
222  const bool has_struct_return = false) {
223  std::vector<llvm::Type*> arg_types;
224  for (const auto arg : args) {
225  CHECK(arg);
226  arg_types.push_back(arg->getType());
227  }
228  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
229  llvm::AttributeList attrs;
230  if (!fnattrs.empty()) {
231  std::vector<std::pair<unsigned, llvm::Attribute>> indexedAttrs;
232  indexedAttrs.reserve(fnattrs.size());
233  for (auto attr : fnattrs) {
234  indexedAttrs.emplace_back(llvm::AttributeList::FunctionIndex,
235  llvm::Attribute::get(context_, attr));
236  }
237  attrs = llvm::AttributeList::get(context_,
238  {&indexedAttrs.front(), indexedAttrs.size()});
239  }
240 
241  auto func_p = module_->getOrInsertFunction(fname, func_ty, attrs);
242  CHECK(func_p);
243  auto callee = func_p.getCallee();
244  llvm::Function* func{nullptr};
245  if (auto callee_cast = llvm::dyn_cast<llvm::ConstantExpr>(callee)) {
246  // Get or insert function automatically adds a ConstantExpr cast if the return type
247  // of the existing function does not match the supplied return type.
248  CHECK(callee_cast->isCast());
249  CHECK_EQ(callee_cast->getNumOperands(), size_t(1));
250  func = llvm::dyn_cast<llvm::Function>(callee_cast->getOperand(0));
251  } else {
252  func = llvm::dyn_cast<llvm::Function>(callee);
253  }
254  CHECK(func);
255  llvm::FunctionType* func_type = func_p.getFunctionType();
256  CHECK(func_type);
257  if (has_struct_return) {
258  const auto arg_ti = func_type->getParamType(0);
259  CHECK(arg_ti->isPointerTy() && arg_ti->getPointerElementType()->isStructTy());
260  auto attr_list = func->getAttributes();
261 #if 14 <= LLVM_VERSION_MAJOR
262  llvm::AttrBuilder arr_arg_builder(context_, attr_list.getParamAttrs(0));
263 #else
264  llvm::AttrBuilder arr_arg_builder(attr_list.getParamAttributes(0));
265 #endif
266  arr_arg_builder.addAttribute(llvm::Attribute::StructRet);
267  func->addParamAttrs(0, arr_arg_builder);
268  }
269  const size_t arg_start = has_struct_return ? 1 : 0;
270  for (size_t i = arg_start; i < func->arg_size(); i++) {
271  const auto arg_ti = func_type->getParamType(i);
272  if (arg_ti->isPointerTy() && arg_ti->getPointerElementType()->isStructTy()) {
273  auto attr_list = func->getAttributes();
274 #if 14 <= LLVM_VERSION_MAJOR
275  llvm::AttrBuilder arr_arg_builder(context_, attr_list.getParamAttrs(i));
276 #else
277  llvm::AttrBuilder arr_arg_builder(attr_list.getParamAttributes(i));
278 #endif
279  arr_arg_builder.addByValAttr(arg_ti->getPointerElementType());
280  func->addParamAttrs(i, arr_arg_builder);
281  }
282  }
283  llvm::Value* result = ir_builder_.CreateCall(func_p, args);
284  // check the assumed type
285  CHECK_EQ(result->getType(), ret_type);
286  return result;
287  }
288 
289  llvm::Value* emitCall(const std::string& fname, const std::vector<llvm::Value*>& args);
290  llvm::Value* emitEntryCall(const std::string& fname,
291  const std::vector<llvm::Value*>& args);
292 
293  size_t getLiteralBufferUsage(const int device_id) { return literal_bytes_[device_id]; }
294 
295  llvm::Value* castToTypeIn(llvm::Value* val, const size_t bit_width);
296 
297  std::pair<llvm::ConstantInt*, llvm::ConstantInt*> inlineIntMaxMin(
298  const size_t byte_width,
299  const bool is_signed);
300 
301  llvm::ConstantInt* inlineIntNull(const SQLTypeInfo&);
302  llvm::ConstantFP* inlineFpNull(const SQLTypeInfo&);
303  llvm::Constant* inlineNull(const SQLTypeInfo&);
304 
305  template <class T>
306  llvm::ConstantInt* llInt(const T v) const {
308  }
309 
310  llvm::ConstantFP* llFp(const float v) const {
311  return static_cast<llvm::ConstantFP*>(
312  llvm::ConstantFP::get(llvm::Type::getFloatTy(context_), v));
313  }
314 
315  llvm::ConstantFP* llFp(const double v) const {
316  return static_cast<llvm::ConstantFP*>(
317  llvm::ConstantFP::get(llvm::Type::getDoubleTy(context_), v));
318  }
319 
320  llvm::ConstantInt* llBool(const bool v) const { return ::ll_bool(v, context_); }
321 
322  void emitErrorCheck(llvm::Value* condition, llvm::Value* errorCode, std::string label);
323 
324  std::vector<std::string> gpuFunctionsToReplace(llvm::Function* fn);
325 
326  void replaceFunctionForGpu(const std::string& fcn_to_replace, llvm::Function* fn);
327 
328  std::shared_ptr<Executor> getExecutor() const;
329  llvm::LLVMContext& getExecutorContext() const;
330  void set_module_shallow_copy(const std::unique_ptr<llvm::Module>& module,
331  bool always_clone = false);
332 
333  size_t executor_id_;
334 
335  /*
336  Managing LLVM modules
337  ---------------------
338 
339  Quoting https://groups.google.com/g/llvm-dev/c/kuil5XjasUs/m/7PBpOWZFDAAJ :
340  """
341  The state of Module/Context ownership is very muddled in the
342  codebase. As you have discovered: LLVMContext’s notionally own
343  their modules (via raw pointers deleted upon destruction of the
344  context), however in practice we always hold llvm Modules by
345  unique_ptr. Since the Module destructor removes the raw pointer
346  from the Context, this doesn’t usually blow up. It’s pretty broken
347  though.
348 
349  I would argue that you should use unique_ptr and ignore
350  LLVMContext ownership.
351  """
352 
353  Here we follow the last argument only partially for reasons
354  explained below.
355 
356  HeavyDB supports concurrent query executions. For that, a global
357  cache of Executor instances is used. Each instance is able to
358  generate LLVM code, compile it to machine code (with code
359  caching), and execute the code --- all that concurrently with
360  other Executor instances.
361 
362  Each Executor instance holds as set of extension modules (LLVM
363  Module instances) that are either loaded at Executor construction
364  time (template module from RuntimeFunctions.bc, rt_geos from
365  GeosRuntime.bc, rt_libdevice from libdevice.10.bc, udf_cpu/gpu
366  modules from LLVM IR file), or at run-time (rt_udf_cpu/gpu modules
367  from LLVM IR string). All these extension modules are owned by
368  the Executor instance via unique_ptr. Since Executor also owns the
369  LLVM Context instance that technically also owns these extension
370  modules, then the LLVM Context-Module ownership can be ignored
371  (see the quote above).
372 
373  Code generation is a process that compiles
374  (generated/user-provided) LLVM IR code into machine code that can
375  be executed on a CPU or GPU.
376 
377  Typically, a copy of the template module (let's call this copy as
378  a worker module) is used as an input to code generation that is
379  updated with generated/user-provided LLVM Functions and with other
380  extension modules being linked in. The worker module is created by
381  set_module_shallow_copy and is owned by an Executor instance as a
382  raw pointer (via cgen_state member). Notice that
383  set_module_shallow_copy clones the template module and then
384  releases unique_ptr as a raw pointer. This means that Executor is
385  now responsible of deleting the worker module after the
386  compilation process completes.
387 
388  The reason why the worker module is stored via raw pointer value
389  (rather than using unique_ptr as suggested in the quote above) is
390  as follows. First, the code generation in HeavyDB can be a
391  recursive process (e.g. in the case of multi-step
392  multi-subqueries) that involves temporary "shelving" of parent
393  compilation processes (the corresponding worker modules are put on
394  hold). In addition, the Executor may trigger threaded compilations
395  that involve "resetting" the worker module for different threads
396  (btw, these compilations cannot be concurrent because LLVM Context
397  is not threadsafe. The shelving and resetting of worker modules
398  makes the scope of a worker module dynamic (only one worker module
399  instance can be in scope while other worker modules are on hold)
400  that contradicts with the purpose of unique_ptr (out-of-scope
401  worker modules can be destroyed) and would make managing all
402  worker modules very painful if these would be stored as unique_ptr
403  instances.
404 
405  An entry point to the code generation is Executor::compileWorkUnit
406  method. Its scope includes creating an Executor::CgenStateManager
407  instance that uses RAII pattern to manage the CgenState instance
408  held by an Executor instance. In addition, the CgenStateManager
409  locks other compilations within the same Executor instance. The
410  compilation lock enables the threaded compilation feature.
411 
412  Construction of CgenStateManager (i) stores the existing CgenState
413  instance held by the Executor instance, and (ii) creates an new
414  CgenState instance with un-instantiated worker module. The worker
415  module is instantiated after the construction (unless
416  QueryMustRunOnCpu is thrown) via set_module_shallow_copy, followed
417  by updating the worker module according to the given query and
418  compiling it to machine code. Destruction of CgenStateManager
419  (read: when leaving the compileWorkUnit method) will delete the
420  instantiated worker module and restores the previous CgenState
421  instance. This CgenState management enables the recursive
422  compilation feature.
423 
424  Finally, we note that the worker module compilation caches the
425  compilation results using the full LLVM IR as the cache
426  key. Caching compilation results is especially effective for CUDA
427  target due to a considerable overhead from the CUDA compilation.
428  */
429 
430  llvm::Module* module_;
431  llvm::Function* row_func_;
432  llvm::Function* filter_func_;
433  llvm::Function* current_func_;
434  llvm::BasicBlock* row_func_bb_;
435  llvm::BasicBlock* filter_func_bb_;
436  llvm::CallInst* row_func_call_;
437  llvm::CallInst* filter_func_call_;
438  std::vector<llvm::Function*> helper_functions_;
439  llvm::LLVMContext& context_; // LLVMContext instance is held by an Executor instance.
440  llvm::ValueToValueMapTy vmap_; // used for cloning the runtime module
441  llvm::IRBuilder<> ir_builder_;
442  std::unordered_map<size_t, std::vector<llvm::Value*>> fetch_cache_;
445  llvm::Value* lv;
446  };
447  std::vector<FunctionOperValue> ext_call_cache_;
448  std::vector<llvm::Value*> group_by_expr_cache_;
449  std::vector<llvm::Value*> str_constants_;
450  std::vector<llvm::Value*> frag_offsets_;
452  std::vector<llvm::Value*> outer_join_match_found_per_level_;
453  std::unordered_map<int, llvm::Value*> scan_idx_to_hash_pos_;
455  std::vector<std::unique_ptr<const InValuesBitmap>> in_values_bitmaps_;
456  std::vector<std::unique_ptr<const StringDictionaryTranslationMgr>>
458  std::map<std::pair<llvm::Value*, llvm::Value*>, ArrayLoadCodegen>
459  array_load_cache_; // byte stream to array info
460  std::unordered_map<std::string, llvm::Value*> geo_target_cache_;
463 
464  llvm::Function* query_func_;
465  llvm::IRBuilder<> query_func_entry_ir_builder_;
466  std::unordered_map<int, std::vector<llvm::Value*>> query_func_literal_loads_;
467 
471  };
472  std::unordered_map<llvm::Value*, HoistedLiteralLoadLocator> row_func_hoisted_literals_;
473 
474  static size_t literalBytes(const CgenState::LiteralValue& lit) {
475  switch (lit.which()) {
476  case 0:
477  return 1; // int8_t
478  case 1:
479  return 2; // int16_t
480  case 2:
481  return 4; // int32_t
482  case 3:
483  return 8; // int64_t
484  case 4:
485  return 4; // float
486  case 5:
487  return 8; // double
488  case 6:
489  return 4; // std::pair<std::string, int>
490  case 7:
491  return 4; // std::string
492  case 8:
493  return 4; // std::vector<double>
494  case 9:
495  return 4; // std::vector<int32_t>
496  case 10:
497  return 4; // std::vector<int8_t>
498  case 11:
499  return 4; // std::pair<std::vector<int8_t>, int>
500  default:
501  abort();
502  }
503  }
504 
505  static size_t addAligned(const size_t off_in, const size_t alignment) {
506  size_t off = off_in;
507  if (off % alignment != 0) {
508  off += (alignment - off % alignment);
509  }
510  return off + alignment;
511  }
512 
513  void maybeCloneFunctionRecursive(llvm::Function* fn);
514 
515  private:
516  template <class T>
517  std::tuple<size_t, size_t> getOrAddLiteral(const T& val, const int device_id) {
518  const LiteralValue var_val(val);
519  size_t literal_found_off{0};
520  auto& literals = literals_[device_id];
521  for (const auto& literal : literals) {
522  const auto lit_bytes = literalBytes(literal);
523  literal_found_off = addAligned(literal_found_off, lit_bytes);
524  if (literal == var_val) {
525  return {literal_found_off - lit_bytes, lit_bytes};
526  }
527  }
528  literals.emplace_back(val);
529  const auto lit_bytes = literalBytes(var_val);
530  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
531  return {literal_bytes_[device_id] - lit_bytes, lit_bytes};
532  }
533 
534  std::unordered_map<int, LiteralValues> literals_;
535  std::unordered_map<int, size_t> literal_bytes_;
536 };
537 
std::vector< llvm::Function * > helper_functions_
Definition: CgenState.h:438
int8_t tinyintval
Definition: sqltypes.h:232
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:345
#define CHECK_EQ(x, y)
Definition: Logger.h:230
llvm::Value * castToTypeIn(llvm::Value *val, const size_t bit_width)
Definition: CgenState.cpp:152
llvm::Value * emitEntryCall(const std::string &fname, const std::vector< llvm::Value * > &args)
Definition: CgenState.cpp:231
std::vector< llvm::Value * > outer_join_match_found_per_level_
Definition: CgenState.h:452
std::unordered_map< size_t, std::vector< llvm::Value * > > fetch_cache_
Definition: CgenState.h:442
Definition: sqltypes.h:63
llvm::LLVMContext & getExecutorContext() const
Definition: CgenState.cpp:380
std::shared_ptr< Executor > getExecutor() const
Definition: CgenState.cpp:375
std::map< std::pair< llvm::Value *, llvm::Value * >, ArrayLoadCodegen > array_load_cache_
Definition: CgenState.h:459
const Analyzer::FunctionOper * foper
Definition: CgenState.h:444
llvm::Value * addStringConstant(const std::string &str)
Definition: CgenState.h:187
void maybeCloneFunctionRecursive(llvm::Function *fn)
Definition: CgenState.cpp:183
llvm::Value * emitExternalCall(const std::string &fname, llvm::Type *ret_type, const std::vector< llvm::Value * > args, const std::vector< llvm::Attribute::AttrKind > &fnattrs={}, const bool has_struct_return=false)
Definition: CgenState.h:217
llvm::Function * query_func_
Definition: CgenState.h:464
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
std::unordered_map< llvm::Value *, HoistedLiteralLoadLocator > row_func_hoisted_literals_
Definition: CgenState.h:472
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
int8_t boolval
Definition: sqltypes.h:231
bool get_is_null() const
Definition: Analyzer.h:342
void moveInValuesBitmap(std::unique_ptr< const InValuesBitmap > &in_values_bitmap)
Definition: CgenState.h:210
std::vector< llvm::Value * > str_constants_
Definition: CgenState.h:449
llvm::ConstantInt * llBool(const bool v) const
Definition: CgenState.h:320
std::unordered_map< int, std::vector< llvm::Value * > > query_func_literal_loads_
Definition: CgenState.h:466
bool needs_geos_
Definition: CgenState.h:462
InsertionOrderedMap filter_func_args_
Definition: CgenState.h:454
const bool contains_left_deep_outer_join_
Definition: CgenState.h:451
llvm::Value * buffer
Definition: CgenState.h:33
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
const std::unordered_map< int, LiteralValues > & getLiterals() const
Definition: CgenState.h:185
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
int32_t intval
Definition: sqltypes.h:234
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
Definition: CgenState.h:460
llvm::ConstantFP * llFp(const double v) const
Definition: CgenState.h:315
std::string to_string(char const *&&v)
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:474
std::vector< FunctionOperValue > ext_call_cache_
Definition: CgenState.h:447
llvm::Function * row_func_
Definition: CgenState.h:431
float floatval
Definition: sqltypes.h:236
std::vector< llvm::Value * > group_by_expr_cache_
Definition: CgenState.h:448
boost::variant< int8_t, int16_t, int32_t, int64_t, float, double, std::pair< std::string, int >, std::string, std::vector< double >, std::vector< int32_t >, std::vector< int8_t >, std::pair< std::vector< int8_t >, int >> LiteralValue
Definition: CgenState.h:182
EncodingType
Definition: sqltypes.h:253
llvm::Module * module_
Definition: CgenState.h:430
size_t executor_id_
Definition: CgenState.h:333
llvm::LLVMContext & context_
Definition: CgenState.h:439
llvm::Function * current_func_
Definition: CgenState.h:433
static size_t addAligned(const size_t off_in, const size_t alignment)
Definition: CgenState.h:505
llvm::CallInst * filter_func_call_
Definition: CgenState.h:437
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:64
int64_t bigintval
Definition: sqltypes.h:235
std::vector< LiteralValue > LiteralValues
Definition: CgenState.h:183
const InValuesBitmap * addInValuesBitmap(std::unique_ptr< InValuesBitmap > &in_values_bitmap)
Definition: CgenState.h:202
void replaceFunctionForGpu(const std::string &fcn_to_replace, llvm::Function *fn)
Definition: CgenState.cpp:331
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:535
int16_t smallintval
Definition: sqltypes.h:233
std::unordered_map< int, llvm::Value * > scan_idx_to_hash_pos_
Definition: CgenState.h:453
bool needs_error_check_
Definition: CgenState.h:461
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:310
std::vector< std::string > gpuFunctionsToReplace(llvm::Function *fn)
Definition: CgenState.cpp:308
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:465
llvm::BasicBlock * filter_func_bb_
Definition: CgenState.h:435
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value * > &args)
Definition: CgenState.cpp:219
std::string * stringval
Definition: sqltypes.h:240
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:499
llvm::Constant * inlineNull(const SQLTypeInfo &)
Definition: CgenState.cpp:118
void set_module_shallow_copy(const std::unique_ptr< llvm::Module > &module, bool always_clone=false)
Definition: CgenState.cpp:384
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:455
Definition: sqltypes.h:66
Definition: sqltypes.h:67
llvm::Function * filter_func_
Definition: CgenState.h:432
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:534
std::vector< llvm::Value * > frag_offsets_
Definition: CgenState.h:450
llvm::Value * is_null
Definition: CgenState.h:35
size_t getLiteralBufferUsage(const int device_id)
Definition: CgenState.h:293
Datum get_constval() const
Definition: Analyzer.h:343
void emitErrorCheck(llvm::Value *condition, llvm::Value *errorCode, std::string label)
Definition: CgenState.cpp:243
Definition: sqltypes.h:55
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:306
#define CHECK(condition)
Definition: Logger.h:222
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:440
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
llvm::ConstantInt * ll_bool(const bool v, llvm::LLVMContext &context)
const StringDictionaryTranslationMgr * moveStringDictionaryTranslationMgr(std::unique_ptr< const StringDictionaryTranslationMgr > &&str_dict_translation_mgr)
Definition: CgenState.h:196
Definition: sqltypes.h:59
std::vector< std::unique_ptr< const StringDictionaryTranslationMgr > > str_dict_translation_mgrs_
Definition: CgenState.h:457
std::tuple< size_t, size_t > getOrAddLiteral(const T &val, const int device_id)
Definition: CgenState.h:517
llvm::Value * size
Definition: CgenState.h:34
std::tuple< size_t, size_t > getOrAddLiteral(const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const int device_id)
Definition: CgenState.h:46
llvm::CallInst * row_func_call_
Definition: CgenState.h:436
CgenState(const size_t num_query_infos, const bool contains_left_deep_outer_join, Executor *executor)
Definition: CgenState.cpp:25
std::pair< llvm::ConstantInt *, llvm::ConstantInt * > inlineIntMaxMin(const size_t byte_width, const bool is_signed)
Definition: CgenState.cpp:123
double doubleval
Definition: sqltypes.h:237
llvm::BasicBlock * row_func_bb_
Definition: CgenState.h:434
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:106