OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_
 
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
*, HoistedLiteralLoadLocator
row_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,
LiteralValues
literals_
 
std::unordered_map< int, size_t > literal_bytes_
 

Detailed Description

Definition at line 30 of file CgenState.h.

Member Typedef Documentation

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 181 of file CgenState.h.

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

Definition at line 182 of file CgenState.h.

Constructor & Destructor Documentation

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  , query_func_(nullptr)
std::vector< llvm::Value * > outer_join_match_found_per_level_
Definition: CgenState.h:280
const std::vector< InputTableInfo > & query_infos_
Definition: CgenState.h:283
llvm::Function * query_func_
Definition: CgenState.h:286
llvm::IRBuilder ir_builder_
Definition: CgenState.h:269
const bool contains_left_deep_outer_join_
Definition: CgenState.h:279
llvm::Function * row_func_
Definition: CgenState.h:265
llvm::Module * module_
Definition: CgenState.h:264
llvm::LLVMContext & context_
Definition: CgenState.h:267
bool needs_error_check_
Definition: CgenState.h:284
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:287
llvm::LLVMContext & getGlobalLLVMContext()

Member Function Documentation

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

Definition at line 327 of file CgenState.h.

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

327  {
328  size_t off = off_in;
329  if (off % alignment != 0) {
330  off += (alignment - off % alignment);
331  }
332  return off + alignment;
333  }

+ Here is the caller graph for this function:

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

Definition at line 195 of file CgenState.h.

References in_values_bitmaps_.

Referenced by CodeGenerator::codegen().

196  {
197  if (in_values_bitmap->isEmpty()) {
198  return in_values_bitmap.get();
199  }
200  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
201  return in_values_bitmaps_.back().get();
202  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:282

+ Here is the caller graph for this function:

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

Definition at line 186 of file CgenState.h.

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

Referenced by CodeGenerator::codegen().

186  {
187  llvm::Value* str_lv = ir_builder_.CreateGlobalString(
188  str, "str_const_" + std::to_string(std::hash<std::string>()(str)));
189  auto i8_ptr = llvm::PointerType::get(get_int_type(8, context_), 0);
190  str_constants_.push_back(str_lv);
191  str_lv = ir_builder_.CreateBitCast(str_lv, i8_ptr);
192  return str_lv;
193  }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:269
std::vector< llvm::Value * > str_constants_
Definition: CgenState.h:277
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
llvm::LLVMContext & context_
Definition: CgenState.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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(), and CodeGenerator::codegenLogicalShortCircuit().

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:269
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:267
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenLogical(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWindowPosition(), and CodeGenerator::codgenAdjustFixedEncNull().

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:269
llvm::Module * module_
Definition: CgenState.h:264
CHECK(cgen_state)
std::unique_ptr< llvm::Module > g_rt_module
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:268

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 205 of file CgenState.h.

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 CodeGenerator::codegenVariableLengthStringColVar().

209  {}) {
210  std::vector<llvm::Type*> arg_types;
211  for (const auto arg : args) {
212  arg_types.push_back(arg->getType());
213  }
214  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
215  llvm::AttributeList attrs;
216  if (!fnattrs.empty()) {
217  std::vector<std::pair<unsigned, llvm::Attribute>> indexedAttrs;
218  indexedAttrs.reserve(fnattrs.size());
219  for (auto attr : fnattrs)
220  indexedAttrs.emplace_back(llvm::AttributeList::FunctionIndex,
221  llvm::Attribute::get(context_, attr));
222  attrs = llvm::AttributeList::get(context_,
223  {&indexedAttrs.front(), indexedAttrs.size()});
224  }
225  auto func_p = module_->getOrInsertFunction(fname, func_ty, attrs);
226  CHECK(func_p);
227  llvm::Value* result = ir_builder_.CreateCall(func_p, args);
228  // check the assumed type
229  CHECK_EQ(result->getType(), ret_type);
230  return result;
231  }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
llvm::IRBuilder ir_builder_
Definition: CgenState.h:269
llvm::Module * module_
Definition: CgenState.h:264
llvm::LLVMContext & context_
Definition: CgenState.h:267
CHECK(cgen_state)

+ Here is the caller graph for this function:

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 235 of file CgenState.h.

References literal_bytes_.

235 { return literal_bytes_[device_id]; }
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:355
const std::unordered_map<int, LiteralValues>& CgenState::getLiterals ( ) const
inline

Definition at line 184 of file CgenState.h.

References literals_.

184 { return literals_; }
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:354
size_t CgenState::getOrAddLiteral ( const Analyzer::Constant constant,
const EncodingType  enc_type,
const int  dict_id,
const int  device_id 
)
inline

Definition at line 45 of file CgenState.h.

References Datum::bigintval, Datum::boolval, CHECK(), CHECK_EQ, 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().

48  {
49  const auto& ti = constant->get_type_info();
50  const auto type = ti.is_decimal() ? decimal_to_int_type(ti) : ti.get_type();
51  switch (type) {
52  case kBOOLEAN:
53  return getOrAddLiteral(constant->get_is_null()
54  ? int8_t(inline_int_null_val(ti))
55  : int8_t(constant->get_constval().boolval ? 1 : 0),
56  device_id);
57  case kTINYINT:
58  return getOrAddLiteral(constant->get_is_null()
59  ? int8_t(inline_int_null_val(ti))
60  : constant->get_constval().tinyintval,
61  device_id);
62  case kSMALLINT:
63  return getOrAddLiteral(constant->get_is_null()
64  ? int16_t(inline_int_null_val(ti))
65  : constant->get_constval().smallintval,
66  device_id);
67  case kINT:
68  return getOrAddLiteral(constant->get_is_null() ? int32_t(inline_int_null_val(ti))
69  : constant->get_constval().intval,
70  device_id);
71  case kBIGINT:
72  return getOrAddLiteral(constant->get_is_null()
73  ? int64_t(inline_int_null_val(ti))
74  : constant->get_constval().bigintval,
75  device_id);
76  case kFLOAT:
77  return getOrAddLiteral(constant->get_is_null()
78  ? float(inline_fp_null_val(ti))
79  : constant->get_constval().floatval,
80  device_id);
81  case kDOUBLE:
82  return getOrAddLiteral(constant->get_is_null()
83  ? inline_fp_null_val(ti)
84  : constant->get_constval().doubleval,
85  device_id);
86  case kCHAR:
87  case kTEXT:
88  case kVARCHAR:
89  if (enc_type == kENCODING_DICT) {
90  if (constant->get_is_null()) {
91  return getOrAddLiteral(int32_t(inline_int_null_val(ti)), device_id);
92  }
93  return getOrAddLiteral(
94  std::make_pair(*constant->get_constval().stringval, dict_id), device_id);
95  }
96  CHECK_EQ(kENCODING_NONE, enc_type);
97  if (constant->get_is_null()) {
98  throw std::runtime_error(
99  "CHAR / VARCHAR NULL literal not supported in this context"); // TODO(alex):
100  // support
101  // null
102  }
103  return getOrAddLiteral(*constant->get_constval().stringval, device_id);
104  case kTIME:
105  case kTIMESTAMP:
106  case kDATE:
107  case kINTERVAL_DAY_TIME:
109  // TODO(alex): support null
110  return getOrAddLiteral(constant->get_constval().bigintval, device_id);
111  case kARRAY: {
112  if (enc_type == kENCODING_NONE) {
113  if (ti.get_subtype() == kDOUBLE) {
114  std::vector<double> double_array_literal;
115  for (const auto& value : constant->get_value_list()) {
116  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
117  CHECK(c);
118  double d = c->get_constval().doubleval;
119  double_array_literal.push_back(d);
120  }
121  return getOrAddLiteral(double_array_literal, device_id);
122  }
123  if (ti.get_subtype() == kINT) {
124  std::vector<int32_t> int32_array_literal;
125  for (const auto& value : constant->get_value_list()) {
126  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
127  CHECK(c);
128  int32_t i = c->get_constval().intval;
129  int32_array_literal.push_back(i);
130  }
131  return getOrAddLiteral(int32_array_literal, device_id);
132  }
133  if (ti.get_subtype() == kTINYINT) {
134  std::vector<int8_t> int8_array_literal;
135  for (const auto& value : constant->get_value_list()) {
136  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
137  CHECK(c);
138  int8_t i = c->get_constval().tinyintval;
139  int8_array_literal.push_back(i);
140  }
141  if (ti.get_comp_param() == 64) {
142  return getOrAddLiteral(std::make_pair(int8_array_literal, 64), device_id);
143  }
144  return getOrAddLiteral(int8_array_literal, device_id);
145  }
146  throw std::runtime_error("Unsupported literal array");
147  }
148  if (enc_type == kENCODING_GEOINT) {
149  if (ti.get_subtype() == kTINYINT) {
150  std::vector<int8_t> int8_array_literal;
151  for (const auto& value : constant->get_value_list()) {
152  const auto c = dynamic_cast<const Analyzer::Constant*>(value.get());
153  CHECK(c);
154  int8_t i = c->get_constval().tinyintval;
155  int8_array_literal.push_back(i);
156  }
157  if (ti.get_comp_param() == 32) {
158  return getOrAddLiteral(std::make_pair(int8_array_literal, 32), device_id);
159  }
160  return getOrAddLiteral(int8_array_literal, device_id);
161  }
162  }
163  throw std::runtime_error("Encoded literal arrays are not supported");
164  }
165  default:
166  abort();
167  }
168  }
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:331
#define CHECK_EQ(x, y)
Definition: Logger.h:198
Definition: sqltypes.h:52
bool get_is_null() const
Definition: Analyzer.h:328
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
size_t getOrAddLiteral(const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const int device_id)
Definition: CgenState.h:45
CHECK(cgen_state)
int64_t bigintval
Definition: sqltypes.h:129
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
std::string * stringval
Definition: sqltypes.h:134
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:268
Definition: sqltypes.h:55
Definition: sqltypes.h:56
Datum get_constval() const
Definition: Analyzer.h:329
Definition: sqltypes.h:44
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 337 of file CgenState.h.

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

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

+ Here is the call graph for this function:

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::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenUMinus(), and CodeGenerator::endArgsNullcheck().

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 }
bool is_fp() const
Definition: sqltypes.h:481
#define NULL_DOUBLE
Definition: sqltypes.h:179
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
#define NULL_FLOAT
Definition: sqltypes.h:178
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:252

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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(), and CodeGenerator::codegenUMinus().

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:198
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:267
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:

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::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenIntConst(), CodeGenerator::codegenIsNullNumber(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenUMinus(), CodeGenerator::codgenAdjustFixedEncNull(), and CodeGenerator::endArgsNullcheck().

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:52
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
CHECK(cgen_state)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
Definition: sqltypes.h:56
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:248
bool is_string() const
Definition: sqltypes.h:477
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 296 of file CgenState.h.

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

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

+ Here is the caller graph for this function:

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

Definition at line 262 of file CgenState.h.

References context_, and ll_bool().

262 { return ::ll_bool(v, context_); }
llvm::LLVMContext & context_
Definition: CgenState.h:267
llvm::ConstantInt * ll_bool(const bool v, llvm::LLVMContext &context)

+ Here is the call graph for this function:

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

Definition at line 252 of file CgenState.h.

References context_.

Referenced by CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenIsNullNumber(), and inlineFpNull().

252  {
253  return static_cast<llvm::ConstantFP*>(
254  llvm::ConstantFP::get(llvm::Type::getFloatTy(context_), v));
255  }
llvm::LLVMContext & context_
Definition: CgenState.h:267

+ Here is the caller graph for this function:

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

Definition at line 257 of file CgenState.h.

References context_.

257  {
258  return static_cast<llvm::ConstantFP*>(
259  llvm::ConstantFP::get(llvm::Type::getDoubleTy(context_), v));
260  }
llvm::LLVMContext & context_
Definition: CgenState.h:267
template<class T >
llvm::ConstantInt* CgenState::llInt ( const T  v) const
inline

Definition at line 248 of file CgenState.h.

References context_, and ll_int().

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoExpr(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIntConst(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWindowPosition(), CodeGenerator::codgenAdjustFixedEncNull(), and inlineIntNull().

248  {
250  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:267

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const bool CgenState::contains_left_deep_outer_join_

Definition at line 279 of file CgenState.h.

llvm::LLVMContext& CgenState::context_

Definition at line 267 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), CodeGenerator::castArrayPointer(), castToTypeIn(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayArgs(), 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::codegenFixedLengthColVar(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIsNull(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenOuterJoinNullPlaceholder(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenVariableLengthStringColVar(), CodeGenerator::codgenAdjustFixedEncNull(), CodeGenerator::colByteStream(), anonymous_namespace{ResultSetReductionCodegen.cpp}::create_entry_block(), anonymous_namespace{ResultSetReductionJIT.cpp}::create_llvm_function(), anonymous_namespace{ResultSetReductionInterpreterStubs.cpp}::create_stub_function(), CodeGenerator::endArgsNullcheck(), anonymous_namespace{TableFunctionCompilationContext.cpp}::generate_entry_point(), inlineIntMaxMin(), llBool(), llFp(), llInt(), and CodeGenerator::posArg().

std::vector<FunctionOperValue> CgenState::ext_call_cache_

Definition at line 275 of file CgenState.h.

Referenced by CodeGenerator::codegenFunctionOper().

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

Definition at line 278 of file CgenState.h.

Referenced by CodeGenerator::codegenColVar(), and CodeGenerator::codegenRowId().

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

Definition at line 276 of file CgenState.h.

Referenced by CodeGenerator::resolveGroupedColumnReference().

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

Definition at line 266 of file CgenState.h.

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

Definition at line 282 of file CgenState.h.

Referenced by addInValuesBitmap().

llvm::IRBuilder CgenState::ir_builder_

Definition at line 269 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), CodeGenerator::castArrayPointer(), castToTypeIn(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayArgs(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenColVar(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVar(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoLineStringArgs(), CodeGenerator::codegenGeoPointArgs(), CodeGenerator::codegenGeoPolygonArgs(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIsNullNumber(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenOuterJoinNullPlaceholder(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codgenAdjustFixedEncNull(), ScalarCodeGenerator::compile(), anonymous_namespace{ResultSetReductionCodegen.cpp}::create_entry_block(), anonymous_namespace{ResultSetReductionInterpreterStubs.cpp}::create_stub_function(), emitCall(), CodeGenerator::endArgsNullcheck(), CodeGenerator::posArg(), and CodeGenerator::toBool().

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

Definition at line 355 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

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

Definition at line 354 of file CgenState.h.

Referenced by getLiterals(), and getOrAddLiteral().

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

Definition at line 286 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

Definition at line 287 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

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

Definition at line 288 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstants().

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

Definition at line 283 of file CgenState.h.

Referenced by CodeGenerator::checkExpressionRanges().

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

Definition at line 294 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

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

Definition at line 281 of file CgenState.h.

Referenced by CodeGenerator::posArg().

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

Definition at line 277 of file CgenState.h.

Referenced by addStringConstant().

llvm::ValueToValueMapTy CgenState::vmap_

Definition at line 268 of file CgenState.h.

Referenced by emitCall(), and CodeGenerator::link_udf_module().


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