OmniSciDB  06b3bd477c
 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={}, const bool has_struct_return=false)
 
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
 
void emitErrorCheck (llvm::Value *condition, llvm::Value *errorCode, std::string label)
 

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

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

Definition at line 183 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  , needs_geos_(false)
43  , query_func_(nullptr)
std::vector< llvm::Value * > outer_join_match_found_per_level_
Definition: CgenState.h:330
const std::vector< InputTableInfo > & query_infos_
Definition: CgenState.h:333
llvm::Function * query_func_
Definition: CgenState.h:337
llvm::IRBuilder ir_builder_
Definition: CgenState.h:319
bool needs_geos_
Definition: CgenState.h:335
const bool contains_left_deep_outer_join_
Definition: CgenState.h:329
llvm::Function * row_func_
Definition: CgenState.h:315
llvm::Module * module_
Definition: CgenState.h:314
llvm::LLVMContext & context_
Definition: CgenState.h:317
bool needs_error_check_
Definition: CgenState.h:334
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:338
llvm::LLVMContext & getGlobalLLVMContext()

Member Function Documentation

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

Definition at line 378 of file CgenState.h.

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

378  {
379  size_t off = off_in;
380  if (off % alignment != 0) {
381  off += (alignment - off % alignment);
382  }
383  return off + alignment;
384  }

+ Here is the caller graph for this function:

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  if (in_values_bitmap->isEmpty()) {
199  return in_values_bitmap.get();
200  }
201  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
202  return in_values_bitmaps_.back().get();
203  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:332

+ Here is the caller graph for this function:

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:319
std::vector< llvm::Value * > str_constants_
Definition: CgenState.h:327
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
llvm::LLVMContext & context_
Definition: CgenState.h:317

+ 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 106 of file CgenState.cpp.

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

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

106  {
107  auto src_bits = val->getType()->getScalarSizeInBits();
108  if (src_bits == dst_bits) {
109  return val;
110  }
111  if (val->getType()->isIntegerTy()) {
112  return ir_builder_.CreateIntCast(
113  val, get_int_type(dst_bits, context_), src_bits != 1);
114  }
115  // real (not dictionary-encoded) strings; store the pointer to the payload
116  if (val->getType()->isPointerTy()) {
117  return ir_builder_.CreatePointerCast(val, get_int_type(dst_bits, context_));
118  }
119 
120  CHECK(val->getType()->isFloatTy() || val->getType()->isDoubleTy());
121 
122  llvm::Type* dst_type = nullptr;
123  switch (dst_bits) {
124  case 64:
125  dst_type = llvm::Type::getDoubleTy(context_);
126  break;
127  case 32:
128  dst_type = llvm::Type::getFloatTy(context_);
129  break;
130  default:
131  CHECK(false);
132  }
133 
134  return ir_builder_.CreateFPCast(val, dst_type);
135 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:319
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:317
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 137 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::codegenCastBetweenTimestamps(), 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().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CgenState::emitErrorCheck ( llvm::Value *  condition,
llvm::Value *  errorCode,
std::string  label 
)

Definition at line 161 of file CgenState.cpp.

References context_, ir_builder_, needs_error_check_, and row_func_.

163  {
164  needs_error_check_ = true;
165  auto check_ok = llvm::BasicBlock::Create(context_, label + "_ok", row_func_);
166  auto check_fail = llvm::BasicBlock::Create(context_, label + "_fail", row_func_);
167  ir_builder_.CreateCondBr(condition, check_ok, check_fail);
168  ir_builder_.SetInsertPoint(check_fail);
169  ir_builder_.CreateRet(errorCode);
170  ir_builder_.SetInsertPoint(check_ok);
171 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:319
llvm::Function * row_func_
Definition: CgenState.h:315
llvm::LLVMContext & context_
Definition: CgenState.h:317
bool needs_error_check_
Definition: CgenState.h:334
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 = {},
const bool  has_struct_return = false 
)
inline

Definition at line 206 of file CgenState.h.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenIsNull(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenVariableLengthStringColVar(), and Executor::groupByColumnCodegen().

210  {},
211  const bool has_struct_return = false) {
212  std::vector<llvm::Type*> arg_types;
213  for (const auto arg : args) {
214  arg_types.push_back(arg->getType());
215  }
216  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
217  llvm::AttributeList attrs;
218  if (!fnattrs.empty()) {
219  std::vector<std::pair<unsigned, llvm::Attribute>> indexedAttrs;
220  indexedAttrs.reserve(fnattrs.size());
221  for (auto attr : fnattrs) {
222  indexedAttrs.emplace_back(llvm::AttributeList::FunctionIndex,
223  llvm::Attribute::get(context_, attr));
224  }
225  attrs = llvm::AttributeList::get(context_,
226  {&indexedAttrs.front(), indexedAttrs.size()});
227  }
228 
229  auto func_p = module_->getOrInsertFunction(fname, func_ty, attrs);
230  CHECK(func_p);
231 #if LLVM_VERSION_MAJOR > 8
232  auto callee = func_p.getCallee();
233 #else
234  auto callee = func_p;
235 #endif
236  llvm::Function* func{nullptr};
237  if (auto callee_cast = llvm::dyn_cast<llvm::ConstantExpr>(callee)) {
238  // Get or insert function automatically adds a ConstantExpr cast if the return type
239  // of the existing function does not match the supplied return type.
240  CHECK(callee_cast->isCast());
241  CHECK_EQ(callee_cast->getNumOperands(), size_t(1));
242  func = llvm::dyn_cast<llvm::Function>(callee_cast->getOperand(0));
243  } else {
244  func = llvm::dyn_cast<llvm::Function>(callee);
245  }
246  CHECK(func);
247 #if LLVM_VERSION_MAJOR > 8
248  llvm::FunctionType* func_type = func_p.getFunctionType();
249 #else
250  llvm::FunctionType* func_type = func->getFunctionType();
251 #endif
252  CHECK(func_type);
253  if (has_struct_return) {
254  const auto arg_ti = func_type->getParamType(0);
255  CHECK(arg_ti->isPointerTy() && arg_ti->getPointerElementType()->isStructTy());
256  auto attr_list = func->getAttributes();
257  llvm::AttrBuilder arr_arg_builder(attr_list.getParamAttributes(0));
258  arr_arg_builder.addAttribute(llvm::Attribute::StructRet);
259  func->addParamAttrs(0, arr_arg_builder);
260  }
261  const size_t arg_start = has_struct_return ? 1 : 0;
262  for (size_t i = arg_start; i < func->arg_size(); i++) {
263  const auto arg_ti = func_type->getParamType(i);
264  if (arg_ti->isPointerTy() && arg_ti->getPointerElementType()->isStructTy()) {
265  auto attr_list = func->getAttributes();
266  llvm::AttrBuilder arr_arg_builder(attr_list.getParamAttributes(i));
267 #if LLVM_VERSION_MAJOR > 8
268  arr_arg_builder.addByValAttr(arg_ti->getPointerElementType());
269 #else
270  arr_arg_builder.addAttribute(llvm::Attribute::ByVal);
271 #endif
272  func->addParamAttrs(i, arr_arg_builder);
273  }
274  }
275  llvm::Value* result = ir_builder_.CreateCall(func_p, args);
276  // check the assumed type
277  CHECK_EQ(result->getType(), ret_type);
278  return result;
279  }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
llvm::IRBuilder ir_builder_
Definition: CgenState.h:319
llvm::Module * module_
Definition: CgenState.h:314
llvm::LLVMContext & context_
Definition: CgenState.h:317
CHECK(cgen_state)

+ Here is the caller graph for this function:

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 283 of file CgenState.h.

References literal_bytes_.

283 { return literal_bytes_[device_id]; }
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:406
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:405
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, 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().

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  }
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:338
#define CHECK_EQ(x, y)
Definition: Logger.h:205
Definition: sqltypes.h:50
bool get_is_null() const
Definition: Analyzer.h:335
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:46
CHECK(cgen_state)
int64_t bigintval
Definition: sqltypes.h:137
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
std::string * stringval
Definition: sqltypes.h:142
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:311
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Datum get_constval() const
Definition: Analyzer.h:336
Definition: sqltypes.h:42
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:46

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

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

388  {
389  const LiteralValue var_val(val);
390  size_t literal_found_off{0};
391  auto& literals = literals_[device_id];
392  for (const auto& literal : literals) {
393  const auto lit_bytes = literalBytes(literal);
394  literal_found_off = addAligned(literal_found_off, lit_bytes);
395  if (literal == var_val) {
396  return literal_found_off - lit_bytes;
397  }
398  }
399  literals.emplace_back(val);
400  const auto lit_bytes = literalBytes(var_val);
401  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
402  return literal_bytes_[device_id] - lit_bytes;
403  }
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:347
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
static size_t addAligned(const size_t off_in, const size_t alignment)
Definition: CgenState.h:378
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:406
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:405
const int8_t * literals

+ Here is the call graph for this function:

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

Definition at line 65 of file CgenState.cpp.

References CHECK(), SQLTypeInfo::get_type(), SQLTypeInfo::is_fp(), kDOUBLE, kFLOAT, llFp(), NULL_DOUBLE, and NULL_FLOAT.

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

65  {
66  CHECK(type_info.is_fp());
67  switch (type_info.get_type()) {
68  case kFLOAT:
69  return llFp(NULL_FLOAT);
70  case kDOUBLE:
71  return llFp(NULL_DOUBLE);
72  default:
73  abort();
74  }
75 }
#define NULL_DOUBLE
Definition: sqltypes.h:185
bool is_fp() const
Definition: sqltypes.h:419
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
CHECK(cgen_state)
#define NULL_FLOAT
Definition: sqltypes.h:184
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:300

+ 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 77 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().

79  {
80  int64_t max_int{0}, min_int{0};
81  if (is_signed) {
82  std::tie(max_int, min_int) = inline_int_max_min(byte_width);
83  } else {
84  uint64_t max_uint{0}, min_uint{0};
85  std::tie(max_uint, min_uint) = inline_uint_max_min(byte_width);
86  max_int = static_cast<int64_t>(max_uint);
87  CHECK_EQ(uint64_t(0), min_uint);
88  }
89  switch (byte_width) {
90  case 1:
91  return std::make_pair(::ll_int(static_cast<int8_t>(max_int), context_),
92  ::ll_int(static_cast<int8_t>(min_int), context_));
93  case 2:
94  return std::make_pair(::ll_int(static_cast<int16_t>(max_int), context_),
95  ::ll_int(static_cast<int16_t>(min_int), context_));
96  case 4:
97  return std::make_pair(::ll_int(static_cast<int32_t>(max_int), context_),
98  ::ll_int(static_cast<int32_t>(min_int), context_));
99  case 8:
100  return std::make_pair(::ll_int(max_int, context_), ::ll_int(min_int, context_));
101  default:
102  abort();
103  }
104 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:317
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 27 of file CgenState.cpp.

References CHECK(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_type(), inline_int_null_val(), SQLTypeInfo::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(), CodeGenerator::endArgsNullcheck(), and CodeGenerator::NullCheckCodegen::NullCheckCodegen().

27  {
28  auto type = type_info.get_type();
29  if (type_info.is_string()) {
30  switch (type_info.get_compression()) {
31  case kENCODING_DICT:
32  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
33  case kENCODING_NONE:
34  return llInt(int64_t(0));
35  default:
36  CHECK(false);
37  }
38  }
39  switch (type) {
40  case kBOOLEAN:
41  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
42  case kTINYINT:
43  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
44  case kSMALLINT:
45  return llInt(static_cast<int16_t>(inline_int_null_val(type_info)));
46  case kINT:
47  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
48  case kBIGINT:
49  case kTIME:
50  case kTIMESTAMP:
51  case kDATE:
52  case kINTERVAL_DAY_TIME:
54  return llInt(inline_int_null_val(type_info));
55  case kDECIMAL:
56  case kNUMERIC:
57  return llInt(inline_int_null_val(type_info));
58  case kARRAY:
59  return llInt(int64_t(0));
60  default:
61  abort();
62  }
63 }
Definition: sqltypes.h:50
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
CHECK(cgen_state)
Definition: sqltypes.h:54
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:296
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:46
bool is_string() const
Definition: sqltypes.h:415

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

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

347  {
348  switch (lit.which()) {
349  case 0:
350  return 1; // int8_t
351  case 1:
352  return 2; // int16_t
353  case 2:
354  return 4; // int32_t
355  case 3:
356  return 8; // int64_t
357  case 4:
358  return 4; // float
359  case 5:
360  return 8; // double
361  case 6:
362  return 4; // std::pair<std::string, int>
363  case 7:
364  return 4; // std::string
365  case 8:
366  return 4; // std::vector<double>
367  case 9:
368  return 4; // std::vector<int32_t>
369  case 10:
370  return 4; // std::vector<int8_t>
371  case 11:
372  return 4; // std::pair<std::vector<int8_t>, int>
373  default:
374  abort();
375  }
376  }

+ Here is the caller graph for this function:

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

Definition at line 310 of file CgenState.h.

References context_, and ll_bool().

Referenced by Executor::buildIsDeletedCb(), Executor::buildJoinLoops(), CodeGenerator::codegenGeosConstructorCall(), and CodeGenerator::codegenGeosPredicateCall().

310 { return ::ll_bool(v, context_); }
llvm::LLVMContext & context_
Definition: CgenState.h:317
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:

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

Definition at line 300 of file CgenState.h.

References context_.

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

300  {
301  return static_cast<llvm::ConstantFP*>(
302  llvm::ConstantFP::get(llvm::Type::getFloatTy(context_), v));
303  }
llvm::LLVMContext & context_
Definition: CgenState.h:317

+ Here is the caller graph for this function:

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

Definition at line 305 of file CgenState.h.

References context_.

305  {
306  return static_cast<llvm::ConstantFP*>(
307  llvm::ConstantFP::get(llvm::Type::getDoubleTy(context_), v));
308  }
llvm::LLVMContext & context_
Definition: CgenState.h:317
template<class T >
llvm::ConstantInt* CgenState::llInt ( const T  v) const
inline

Definition at line 296 of file CgenState.h.

References context_, and ll_int().

Referenced by Executor::buildIsDeletedCb(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCompression(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeoBinOper(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenGeoUOper(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIntConst(), Executor::codegenJoinLoops(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWindowPosition(), CodeGenerator::codgenAdjustFixedEncNull(), Executor::groupByColumnCodegen(), and inlineIntNull().

296  {
298  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:317

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

llvm::LLVMContext& CgenState::context_

Definition at line 317 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildIsDeletedCb(), CodeGenerator::castArrayPointer(), castToTypeIn(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayArgs(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFixedLengthColVar(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeoBinOper(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenGeoUOper(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIsNull(), Executor::codegenJoinLoops(), 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(), emitErrorCheck(), CodeGenerator::endArgsNullcheck(), anonymous_namespace{TableFunctionCompilationContext.cpp}::generate_entry_point(), anonymous_namespace{ExtensionsIR.cpp}::get_arr_struct_type(), Executor::groupByColumnCodegen(), inlineIntMaxMin(), llBool(), llFp(), llInt(), CodeGenerator::NullCheckCodegen::NullCheckCodegen(), and CodeGenerator::posArg().

std::vector<FunctionOperValue> CgenState::ext_call_cache_

Definition at line 325 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 328 of file CgenState.h.

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

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

Definition at line 326 of file CgenState.h.

Referenced by CodeGenerator::resolveGroupedColumnReference().

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

Definition at line 316 of file CgenState.h.

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

Definition at line 332 of file CgenState.h.

Referenced by addInValuesBitmap().

llvm::IRBuilder CgenState::ir_builder_

Definition at line 319 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildIsDeletedCb(), Executor::buildJoinLoops(), 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::codegenCastToFp(), CodeGenerator::codegenColVar(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVar(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeoLineStringArgs(), CodeGenerator::codegenGeoMultiPolygonArgs(), CodeGenerator::codegenGeoPointArgs(), CodeGenerator::codegenGeoPolygonArgs(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIsNullNumber(), Executor::codegenJoinLoops(), 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(), emitErrorCheck(), CodeGenerator::endArgsNullcheck(), Executor::groupByColumnCodegen(), CodeGenerator::NullCheckCodegen::NullCheckCodegen(), CodeGenerator::posArg(), and CodeGenerator::toBool().

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

Definition at line 406 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

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

Definition at line 405 of file CgenState.h.

Referenced by getLiterals(), and getOrAddLiteral().

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

Definition at line 337 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

Definition at line 338 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

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

Definition at line 339 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstants().

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

Definition at line 333 of file CgenState.h.

Referenced by CodeGenerator::checkExpressionRanges().

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

Definition at line 345 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

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

Definition at line 331 of file CgenState.h.

Referenced by Executor::addJoinLoopIterator(), and CodeGenerator::posArg().

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

Definition at line 327 of file CgenState.h.

Referenced by addStringConstant().

llvm::ValueToValueMapTy CgenState::vmap_

Definition at line 318 of file CgenState.h.

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


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