OmniSciDB  04ee39c94c
CgenState Struct Reference

#include <CgenState.h>

Classes

struct  FunctionOperValue
 
struct  HoistedLiteralLoadLocator
 

Public Types

using LiteralValue = 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 > >
 
using LiteralValues = std::vector< LiteralValue >
 

Public Member Functions

 CgenState (const std::vector< InputTableInfo > &query_infos, const bool contains_left_deep_outer_join)
 
size_t getOrAddLiteral (const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const int device_id)
 
const std::unordered_map< int, LiteralValues > & getLiterals () const
 
llvm::Value * addStringConstant (const std::string &str)
 
const InValuesBitmapaddInValuesBitmap (std::unique_ptr< InValuesBitmap > &in_values_bitmap)
 
llvm::Value * emitExternalCall (const std::string &fname, llvm::Type *ret_type, const std::vector< llvm::Value *> args, const std::vector< llvm::Attribute::AttrKind > &fnattrs={})
 
llvm::Value * emitCall (const std::string &fname, const std::vector< llvm::Value *> &args)
 
size_t getLiteralBufferUsage (const int device_id)
 
llvm::Value * castToTypeIn (llvm::Value *val, const size_t bit_width)
 
std::pair< llvm::ConstantInt *, llvm::ConstantInt * > inlineIntMaxMin (const size_t byte_width, const bool is_signed)
 
llvm::ConstantInt * inlineIntNull (const SQLTypeInfo &)
 
llvm::ConstantFP * inlineFpNull (const SQLTypeInfo &)
 
template<class T >
llvm::ConstantInt * llInt (const T v) const
 
llvm::ConstantFP * llFp (const float v) const
 
llvm::ConstantFP * llFp (const double v) const
 
llvm::ConstantInt * llBool (const bool v) const
 

Static Public Member Functions

static size_t literalBytes (const CgenState::LiteralValue &lit)
 
static size_t addAligned (const size_t off_in, const size_t alignment)
 

Public Attributes

llvm::Module * module_
 
llvm::Function * row_func_
 
std::vector< llvm::Function * > helper_functions_
 
llvm::LLVMContext & context_
 
llvm::ValueToValueMapTy vmap_
 
llvm::IRBuilder ir_builder_
 
std::unordered_map< int, std::vector< llvm::Value * > > fetch_cache_
 
std::vector< FunctionOperValueext_call_cache_
 
std::vector< llvm::Value * > group_by_expr_cache_
 
std::vector< llvm::Value * > str_constants_
 
std::vector< llvm::Value * > frag_offsets_
 
const bool contains_left_deep_outer_join_
 
std::vector< llvm::Value * > outer_join_match_found_per_level_
 
std::unordered_map< int, llvm::Value * > scan_idx_to_hash_pos_
 
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
 
const std::vector< InputTableInfo > & query_infos_
 
bool needs_error_check_
 
bool has_external_calls_
 
llvm::Function * query_func_
 
llvm::IRBuilder query_func_entry_ir_builder_
 
std::unordered_map< int, std::vector< llvm::Value * > > query_func_literal_loads_
 
std::unordered_map< llvm::Value *, HoistedLiteralLoadLocatorrow_func_hoisted_literals_
 

Private Member Functions

template<class T >
size_t getOrAddLiteral (const T &val, const int device_id)
 

Private Attributes

std::unordered_map< int, LiteralValuesliterals_
 
std::unordered_map< int, size_t > literal_bytes_
 

Detailed Description

Definition at line 30 of file CgenState.h.

Member Typedef Documentation

◆ LiteralValue

using CgenState::LiteralValue = 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> >

Definition at line 182 of file CgenState.h.

◆ LiteralValues

using CgenState::LiteralValues = std::vector<LiteralValue>

Definition at line 183 of file CgenState.h.

Constructor & Destructor Documentation

◆ CgenState()

CgenState::CgenState ( const std::vector< InputTableInfo > &  query_infos,
const bool  contains_left_deep_outer_join 
)
inline

Definition at line 32 of file CgenState.h.

34  : module_(nullptr)
35  , row_func_(nullptr)
38  , contains_left_deep_outer_join_(contains_left_deep_outer_join)
39  , outer_join_match_found_per_level_(std::max(query_infos.size(), size_t(1)) - 1)
40  , query_infos_(query_infos)
41  , needs_error_check_(false)
42  , has_external_calls_(false)
43  , query_func_(nullptr)
std::vector< llvm::Value * > outer_join_match_found_per_level_
Definition: CgenState.h:279
const std::vector< InputTableInfo > & query_infos_
Definition: CgenState.h:282
llvm::Function * query_func_
Definition: CgenState.h:287
bool has_external_calls_
Definition: CgenState.h:285
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
const bool contains_left_deep_outer_join_
Definition: CgenState.h:278
llvm::Function * row_func_
Definition: CgenState.h:264
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
bool needs_error_check_
Definition: CgenState.h:283
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:288
llvm::LLVMContext & getGlobalLLVMContext()

Member Function Documentation

◆ addAligned()

static size_t CgenState::addAligned ( const size_t  off_in,
const size_t  alignment 
)
inlinestatic

Definition at line 328 of file CgenState.h.

Referenced by getOrAddLiteral(), and Executor::serializeLiterals().

328  {
329  size_t off = off_in;
330  if (off % alignment != 0) {
331  off += (alignment - off % alignment);
332  }
333  return off + alignment;
334  }
+ Here is the caller graph for this function:

◆ addInValuesBitmap()

const InValuesBitmap* CgenState::addInValuesBitmap ( std::unique_ptr< InValuesBitmap > &  in_values_bitmap)
inline

Definition at line 196 of file CgenState.h.

References in_values_bitmaps_.

Referenced by CodeGenerator::codegen().

197  {
198  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
199  return in_values_bitmaps_.back().get();
200  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:281
+ Here is the caller graph for this function:

◆ addStringConstant()

llvm::Value* CgenState::addStringConstant ( const std::string &  str)
inline

Definition at line 187 of file CgenState.h.

References context_, get_int_type(), ir_builder_, str_constants_, and to_string().

Referenced by CodeGenerator::codegen().

187  {
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  }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
std::vector< llvm::Value * > str_constants_
Definition: CgenState.h:276
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
llvm::LLVMContext & context_
Definition: CgenState.h:266
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ castToTypeIn()

llvm::Value * CgenState::castToTypeIn ( llvm::Value *  val,
const size_t  bit_width 
)

Definition at line 103 of file CgenState.cpp.

References CHECK, context_, get_int_type(), and ir_builder_.

Referenced by CodeGenerator::codegenCast(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), getLiteralBufferUsage(), and Executor::groupByColumnCodegen().

103  {
104  auto src_bits = val->getType()->getScalarSizeInBits();
105  if (src_bits == dst_bits) {
106  return val;
107  }
108  if (val->getType()->isIntegerTy()) {
109  return ir_builder_.CreateIntCast(
110  val, get_int_type(dst_bits, context_), src_bits != 1);
111  }
112  // real (not dictionary-encoded) strings; store the pointer to the payload
113  if (val->getType()->isPointerTy()) {
114  return ir_builder_.CreatePointerCast(val, get_int_type(dst_bits, context_));
115  }
116 
117  CHECK(val->getType()->isFloatTy() || val->getType()->isDoubleTy());
118 
119  llvm::Type* dst_type = nullptr;
120  switch (dst_bits) {
121  case 64:
122  dst_type = llvm::Type::getDoubleTy(context_);
123  break;
124  case 32:
125  dst_type = llvm::Type::getFloatTy(context_);
126  break;
127  default:
128  CHECK(false);
129  }
130 
131  return ir_builder_.CreateFPCast(val, dst_type);
132 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:266
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ emitCall()

llvm::Value * CgenState::emitCall ( const std::string &  fname,
const std::vector< llvm::Value *> &  args 
)

Definition at line 134 of file CgenState.cpp.

References CHECK, g_rt_module, ir_builder_, module_, and vmap_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenLogical(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection(), emitExternalCall(), and Executor::groupByColumnCodegen().

135  {
136  // Get the implementation from the runtime module.
137  auto func_impl = g_rt_module->getFunction(fname);
138  CHECK(func_impl);
139  // Get the function reference from the query module.
140  auto func = module_->getFunction(fname);
141  CHECK(func);
142  // If the function called isn't external, clone the implementation from the runtime
143  // module.
144  if (func->isDeclaration() && !func_impl->isDeclaration()) {
145  auto DestI = func->arg_begin();
146  for (auto arg_it = func_impl->arg_begin(); arg_it != func_impl->arg_end(); ++arg_it) {
147  DestI->setName(arg_it->getName());
148  vmap_[&*arg_it] = &*DestI++;
149  }
150 
151  llvm::SmallVector<llvm::ReturnInst*, 8> Returns; // Ignore returns cloned.
152  llvm::CloneFunctionInto(func, func_impl, vmap_, /*ModuleLevelChanges=*/true, Returns);
153  }
154 
155  return ir_builder_.CreateCall(func, args);
156 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Module * module_
Definition: CgenState.h:263
std::unique_ptr< llvm::Module > g_rt_module
#define CHECK(condition)
Definition: Logger.h:187
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:267
+ Here is the caller graph for this function:

◆ emitExternalCall()

llvm::Value* CgenState::emitExternalCall ( const std::string &  fname,
llvm::Type *  ret_type,
const std::vector< llvm::Value *>  args,
const std::vector< llvm::Attribute::AttrKind > &  fnattrs = {} 
)
inline

Definition at line 203 of file CgenState.h.

References CHECK, CHECK_EQ, context_, emitCall(), has_external_calls_, ir_builder_, module_, and run-benchmark-import::result.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenIsNull(), CodeGenerator::codegenQualifierCmp(), and Executor::groupByColumnCodegen().

207  {}) {
208  has_external_calls_ = true;
209  std::vector<llvm::Type*> arg_types;
210  for (const auto arg : args) {
211  arg_types.push_back(arg->getType());
212  }
213  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
214  llvm::AttributeList attrs;
215  if (!fnattrs.empty()) {
216  std::vector<std::pair<unsigned, llvm::Attribute>> indexedAttrs;
217  indexedAttrs.reserve(fnattrs.size());
218  for (auto attr : fnattrs)
219  indexedAttrs.emplace_back(llvm::AttributeList::FunctionIndex,
220  llvm::Attribute::get(context_, attr));
221  attrs = llvm::AttributeList::get(context_,
222  {&indexedAttrs.front(), indexedAttrs.size()});
223  }
224  auto func_p = module_->getOrInsertFunction(fname, func_ty, attrs);
225  CHECK(func_p);
226  llvm::Value* result = ir_builder_.CreateCall(func_p, args);
227  // check the assumed type
228  CHECK_EQ(result->getType(), ret_type);
229  return result;
230  }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
bool has_external_calls_
Definition: CgenState.h:285
llvm::IRBuilder ir_builder_
Definition: CgenState.h:268
llvm::Module * module_
Definition: CgenState.h:263
llvm::LLVMContext & context_
Definition: CgenState.h:266
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLiteralBufferUsage()

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 234 of file CgenState.h.

References castToTypeIn(), inlineFpNull(), inlineIntMaxMin(), inlineIntNull(), and literal_bytes_.

234 { return literal_bytes_[device_id]; }
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:356
+ Here is the call graph for this function:

◆ getLiterals()

const std::unordered_map<int, LiteralValues>& CgenState::getLiterals ( ) const
inline

Definition at line 185 of file CgenState.h.

References literals_.

185 { return literals_; }
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:355

◆ getOrAddLiteral() [1/2]

size_t CgenState::getOrAddLiteral ( const Analyzer::Constant constant,
const EncodingType  enc_type,
const int  dict_id,
const int  device_id 
)
inline

Definition at line 46 of file CgenState.h.

References Datum::bigintval, Datum::boolval, anonymous_namespace{ExecuteTest.cpp}::c(), CHECK, CHECK_EQ, anonymous_namespace{ImportTest.cpp}::d(), decimal_to_int_type(), Datum::doubleval, Datum::floatval, Analyzer::Constant::get_constval(), Analyzer::Constant::get_is_null(), Analyzer::Expr::get_type_info(), Analyzer::Constant::get_value_list(), inline_fp_null_val(), inline_int_null_val(), Datum::intval, kARRAY, kBIGINT, kBOOLEAN, kCHAR, kDATE, kDOUBLE, kENCODING_DICT, kENCODING_GEOINT, kENCODING_NONE, kFLOAT, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kSMALLINT, kTEXT, kTIME, kTIMESTAMP, kTINYINT, kVARCHAR, Datum::smallintval, Datum::stringval, Datum::tinyintval, and run-benchmark-import::type.

Referenced by CodeGenerator::codegenHoistedConstants().

49  {
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  }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Definition: sqltypes.h:51
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:330
void c(const std::string &query_string, const ExecutorDeviceType device_type)
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
Datum get_constval() const
Definition: Analyzer.h:328
size_t getOrAddLiteral(const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const int device_id)
Definition: CgenState.h:46
int64_t bigintval
Definition: sqltypes.h:126
std::string * stringval
Definition: sqltypes.h:131
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:268
bool get_is_null() const
Definition: Analyzer.h:327
Definition: sqltypes.h:54
Definition: sqltypes.h:55
Definition: sqltypes.h:43
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
#define CHECK(condition)
Definition: Logger.h:187
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrAddLiteral() [2/2]

template<class T >
size_t CgenState::getOrAddLiteral ( const T &  val,
const int  device_id 
)
inlineprivate

Definition at line 338 of file CgenState.h.

References addAligned(), literal_bytes_, literalBytes(), literals, and literals_.

338  {
339  const LiteralValue var_val(val);
340  size_t literal_found_off{0};
341  auto& literals = literals_[device_id];
342  for (const auto& literal : literals) {
343  const auto lit_bytes = literalBytes(literal);
344  literal_found_off = addAligned(literal_found_off, lit_bytes);
345  if (literal == var_val) {
346  return literal_found_off - lit_bytes;
347  }
348  }
349  literals.emplace_back(val);
350  const auto lit_bytes = literalBytes(var_val);
351  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
352  return literal_bytes_[device_id] - lit_bytes;
353  }
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:297
static size_t addAligned(const size_t off_in, const size_t alignment)
Definition: CgenState.h:328
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:356
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:355
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
const int8_t * literals
+ Here is the call graph for this function:

◆ inlineFpNull()

llvm::ConstantFP * CgenState::inlineFpNull ( const SQLTypeInfo type_info)

Definition at line 62 of file CgenState.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_fp(), kDOUBLE, kFLOAT, llFp(), NULL_DOUBLE, and NULL_FLOAT.

Referenced by CodeGenerator::codegenArrayAt(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenUMinus(), CodeGenerator::endArgsNullcheck(), and getLiteralBufferUsage().

62  {
63  CHECK(type_info.is_fp());
64  switch (type_info.get_type()) {
65  case kFLOAT:
66  return llFp(NULL_FLOAT);
67  case kDOUBLE:
68  return llFp(NULL_DOUBLE);
69  default:
70  abort();
71  }
72 }
#define NULL_DOUBLE
Definition: sqltypes.h:176
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:251
bool is_fp() const
Definition: sqltypes.h:454
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
#define NULL_FLOAT
Definition: sqltypes.h:175
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inlineIntMaxMin()

std::pair< llvm::ConstantInt *, llvm::ConstantInt * > CgenState::inlineIntMaxMin ( const size_t  byte_width,
const bool  is_signed 
)

Definition at line 74 of file CgenState.cpp.

References CHECK_EQ, context_, inline_int_max_min(), inline_uint_max_min(), and ll_int().

Referenced by CodeGenerator::codegenAdd(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenDiv(), CodeGenerator::codegenMul(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), and getLiteralBufferUsage().

76  {
77  int64_t max_int{0}, min_int{0};
78  if (is_signed) {
79  std::tie(max_int, min_int) = inline_int_max_min(byte_width);
80  } else {
81  uint64_t max_uint{0}, min_uint{0};
82  std::tie(max_uint, min_uint) = inline_uint_max_min(byte_width);
83  max_int = static_cast<int64_t>(max_uint);
84  CHECK_EQ(uint64_t(0), min_uint);
85  }
86  switch (byte_width) {
87  case 1:
88  return std::make_pair(::ll_int(static_cast<int8_t>(max_int), context_),
89  ::ll_int(static_cast<int8_t>(min_int), context_));
90  case 2:
91  return std::make_pair(::ll_int(static_cast<int16_t>(max_int), context_),
92  ::ll_int(static_cast<int16_t>(min_int), context_));
93  case 4:
94  return std::make_pair(::ll_int(static_cast<int32_t>(max_int), context_),
95  ::ll_int(static_cast<int32_t>(min_int), context_));
96  case 8:
97  return std::make_pair(::ll_int(max_int, context_), ::ll_int(min_int, context_));
98  default:
99  abort();
100  }
101 }
#define CHECK_EQ(x, y)
Definition: Logger.h:195
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:266
std::pair< uint64_t, uint64_t > inline_uint_max_min(const size_t byte_width)
std::pair< int64_t, int64_t > inline_int_max_min(const size_t byte_width)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inlineIntNull()

llvm::ConstantInt * CgenState::inlineIntNull ( const SQLTypeInfo type_info)

Definition at line 24 of file CgenState.cpp.

References CHECK, SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), inline_int_null_val(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kENCODING_DICT, kENCODING_NONE, kINT, kINTERVAL_DAY_TIME, kINTERVAL_YEAR_MONTH, kNUMERIC, kSMALLINT, kTIME, kTIMESTAMP, kTINYINT, llInt(), and run-benchmark-import::type.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenIntConst(), CodeGenerator::codegenIsNullNumber(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenUMinus(), CodeGenerator::endArgsNullcheck(), and getLiteralBufferUsage().

24  {
25  auto type = type_info.get_type();
26  if (type_info.is_string()) {
27  switch (type_info.get_compression()) {
28  case kENCODING_DICT:
29  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
30  case kENCODING_NONE:
31  return llInt(int64_t(0));
32  default:
33  CHECK(false);
34  }
35  }
36  switch (type) {
37  case kBOOLEAN:
38  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
39  case kTINYINT:
40  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
41  case kSMALLINT:
42  return llInt(static_cast<int16_t>(inline_int_null_val(type_info)));
43  case kINT:
44  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
45  case kBIGINT:
46  case kTIME:
47  case kTIMESTAMP:
48  case kDATE:
49  case kINTERVAL_DAY_TIME:
51  return llInt(inline_int_null_val(type_info));
52  case kDECIMAL:
53  case kNUMERIC:
54  return llInt(inline_int_null_val(type_info));
55  case kARRAY:
56  return llInt(int64_t(0));
57  default:
58  abort();
59  }
60 }
Definition: sqltypes.h:51
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:331
Definition: sqltypes.h:55
#define CHECK(condition)
Definition: Logger.h:187
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:47
bool is_string() const
Definition: sqltypes.h:450
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:

◆ literalBytes()

static size_t CgenState::literalBytes ( const CgenState::LiteralValue lit)
inlinestatic

Definition at line 297 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads(), getOrAddLiteral(), and Executor::serializeLiterals().

297  {
298  switch (lit.which()) {
299  case 0:
300  return 1; // int8_t
301  case 1:
302  return 2; // int16_t
303  case 2:
304  return 4; // int32_t
305  case 3:
306  return 8; // int64_t
307  case 4:
308  return 4; // float
309  case 5:
310  return 8; // double
311  case 6:
312  return 4; // std::pair<std::string, int>
313  case 7:
314  return 4; // std::string
315  case 8:
316  return 4; // std::vector<double>
317  case 9:
318  return 4; // std::vector<int32_t>
319  case 10:
320  return 4; // std::vector<int8_t>
321  case 11:
322  return 4; // std::pair<std::vector<int8_t>, int>
323  default:
324  abort();
325  }
326  }
+ Here is the caller graph for this function:

◆ llBool()

llvm::ConstantInt* CgenState::llBool ( const bool  v) const
inline

Definition at line 261 of file CgenState.h.

References context_, and ll_bool().

Referenced by Executor::buildIsDeletedCb(), and Executor::buildJoinLoops().

llvm::LLVMContext & context_
Definition: CgenState.h:266
T v(const TargetValue &r)
llvm::ConstantInt * ll_bool(const bool v, llvm::LLVMContext &context)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ llFp() [1/2]

llvm::ConstantFP* CgenState::llFp ( const float  v) const
inline

Definition at line 251 of file CgenState.h.

References context_.

Referenced by CodeGenerator::codegenCmp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenIsNullNumber(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), and inlineFpNull().

251  {
252  return static_cast<llvm::ConstantFP*>(
253  llvm::ConstantFP::get(llvm::Type::getFloatTy(context_), v));
254  }
llvm::LLVMContext & context_
Definition: CgenState.h:266
T v(const TargetValue &r)
+ Here is the caller graph for this function:

◆ llFp() [2/2]

llvm::ConstantFP* CgenState::llFp ( const double  v) const
inline

Definition at line 256 of file CgenState.h.

References context_.

256  {
257  return static_cast<llvm::ConstantFP*>(
258  llvm::ConstantFP::get(llvm::Type::getDoubleTy(context_), v));
259  }
llvm::LLVMContext & context_
Definition: CgenState.h:266
T v(const TargetValue &r)

◆ llInt()

template<class T >
llvm::ConstantInt* CgenState::llInt ( const T  v) const
inline

Definition at line 247 of file CgenState.h.

References context_, and ll_int().

Referenced by Executor::buildIsDeletedCb(), Executor::buildJoinLoops(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCmp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIntConst(), Executor::codegenJoinLoops(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection(), Executor::groupByColumnCodegen(), and inlineIntNull().

247  {
249  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:266
T v(const TargetValue &r)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ contains_left_deep_outer_join_

const bool CgenState::contains_left_deep_outer_join_

Definition at line 278 of file CgenState.h.

◆ context_

llvm::LLVMContext& CgenState::context_

Definition at line 266 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildIsDeletedCb(), CodeGenerator::castArrayPointer(), castToTypeIn(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIsNull(), Executor::codegenJoinLoops(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i32(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load_i64(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff(), emitExternalCall(), CodeGenerator::endArgsNullcheck(), CodeGenerator::generatePTX(), Executor::groupByColumnCodegen(), inlineIntMaxMin(), llBool(), llFp(), llInt(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_is_empty_entry(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_loop(), anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry(), and anonymous_namespace{ResultSetReductionJIT.cpp}::setup_reduce_one_entry_idx().

◆ ext_call_cache_

std::vector<FunctionOperValue> CgenState::ext_call_cache_

Definition at line 274 of file CgenState.h.

Referenced by CodeGenerator::codegenFunctionOper().

◆ fetch_cache_

std::unordered_map<int, std::vector<llvm::Value*> > CgenState::fetch_cache_

Definition at line 269 of file CgenState.h.

◆ frag_offsets_

std::vector<llvm::Value*> CgenState::frag_offsets_

Definition at line 277 of file CgenState.h.

◆ group_by_expr_cache_

std::vector<llvm::Value*> CgenState::group_by_expr_cache_

Definition at line 275 of file CgenState.h.

Referenced by Executor::groupByColumnCodegen().

◆ has_external_calls_

bool CgenState::has_external_calls_

Definition at line 285 of file CgenState.h.

Referenced by emitExternalCall(), and ResultSetReductionJIT::useInterpreter().

◆ helper_functions_

std::vector<llvm::Function*> CgenState::helper_functions_

Definition at line 265 of file CgenState.h.

◆ in_values_bitmaps_

std::vector<std::unique_ptr<const InValuesBitmap> > CgenState::in_values_bitmaps_

Definition at line 281 of file CgenState.h.

Referenced by addInValuesBitmap().

◆ ir_builder_

llvm::IRBuilder CgenState::ir_builder_

Definition at line 268 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildIsDeletedCb(), Executor::buildJoinLoops(), CodeGenerator::castArrayPointer(), castToTypeIn(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIsNullNumber(), Executor::codegenJoinLoops(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_count(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_nullable_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_aggregate_one_value(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_load(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_read_int_from_buff(), emitCall(), emitExternalCall(), CodeGenerator::endArgsNullcheck(), Executor::groupByColumnCodegen(), and CodeGenerator::toBool().

◆ literal_bytes_

std::unordered_map<int, size_t> CgenState::literal_bytes_
private

Definition at line 356 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

◆ literals_

std::unordered_map<int, LiteralValues> CgenState::literals_
private

Definition at line 355 of file CgenState.h.

Referenced by getLiterals(), and getOrAddLiteral().

◆ module_

◆ needs_error_check_

◆ outer_join_match_found_per_level_

std::vector<llvm::Value*> CgenState::outer_join_match_found_per_level_

Definition at line 279 of file CgenState.h.

Referenced by Executor::buildJoinLoops().

◆ query_func_

llvm::Function* CgenState::query_func_

Definition at line 287 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

◆ query_func_entry_ir_builder_

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

Definition at line 288 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

◆ query_func_literal_loads_

std::unordered_map<int, std::vector<llvm::Value*> > CgenState::query_func_literal_loads_

Definition at line 289 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstants().

◆ query_infos_

const std::vector<InputTableInfo>& CgenState::query_infos_

Definition at line 282 of file CgenState.h.

Referenced by CodeGenerator::checkExpressionRanges().

◆ row_func_

◆ row_func_hoisted_literals_

std::unordered_map<llvm::Value*, HoistedLiteralLoadLocator> CgenState::row_func_hoisted_literals_

Definition at line 295 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

◆ scan_idx_to_hash_pos_

std::unordered_map<int, llvm::Value*> CgenState::scan_idx_to_hash_pos_

Definition at line 280 of file CgenState.h.

Referenced by Executor::addJoinLoopIterator().

◆ str_constants_

std::vector<llvm::Value*> CgenState::str_constants_

Definition at line 276 of file CgenState.h.

Referenced by addStringConstant().

◆ vmap_


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