OmniSciDB  0fdbebe030
 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_
 
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:329
const std::vector< InputTableInfo > & query_infos_
Definition: CgenState.h:332
llvm::Function * query_func_
Definition: CgenState.h:335
llvm::IRBuilder ir_builder_
Definition: CgenState.h:318
const bool contains_left_deep_outer_join_
Definition: CgenState.h:328
llvm::Function * row_func_
Definition: CgenState.h:314
llvm::Module * module_
Definition: CgenState.h:313
llvm::LLVMContext & context_
Definition: CgenState.h:316
bool needs_error_check_
Definition: CgenState.h:333
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:336
llvm::LLVMContext & getGlobalLLVMContext()

Member Function Documentation

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

Definition at line 376 of file CgenState.h.

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

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

+ 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:331

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

+ 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:318
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:316
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::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().

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

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

References context_, ir_builder_, needs_error_check_, and row_func_.

160  {
161  needs_error_check_ = true;
162  auto check_ok = llvm::BasicBlock::Create(context_, label + "_ok", row_func_);
163  auto check_fail = llvm::BasicBlock::Create(context_, label + "_fail", row_func_);
164  ir_builder_.CreateCondBr(condition, check_ok, check_fail);
165  ir_builder_.SetInsertPoint(check_fail);
166  ir_builder_.CreateRet(errorCode);
167  ir_builder_.SetInsertPoint(check_ok);
168 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:318
llvm::Function * row_func_
Definition: CgenState.h:314
llvm::LLVMContext & context_
Definition: CgenState.h:316
bool needs_error_check_
Definition: CgenState.h:333
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 205 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::codegenIsNull(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenVariableLengthStringColVar(), and Executor::groupByColumnCodegen().

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

+ Here is the caller graph for this function:

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 282 of file CgenState.h.

References literal_bytes_.

282 { return literal_bytes_[device_id]; }
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:404
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:403
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:205
Definition: sqltypes.h:50
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:127
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
std::string * stringval
Definition: sqltypes.h:132
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:299
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Datum get_constval() const
Definition: Analyzer.h:329
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 386 of file CgenState.h.

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

386  {
387  const LiteralValue var_val(val);
388  size_t literal_found_off{0};
389  auto& literals = literals_[device_id];
390  for (const auto& literal : literals) {
391  const auto lit_bytes = literalBytes(literal);
392  literal_found_off = addAligned(literal_found_off, lit_bytes);
393  if (literal == var_val) {
394  return literal_found_off - lit_bytes;
395  }
396  }
397  literals.emplace_back(val);
398  const auto lit_bytes = literalBytes(var_val);
399  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
400  return literal_bytes_[device_id] - lit_bytes;
401  }
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:345
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:376
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:404
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:403
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(), 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(), 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 }
#define NULL_DOUBLE
Definition: sqltypes.h:175
bool is_fp() const
Definition: sqltypes.h:403
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:248
CHECK(cgen_state)
#define NULL_FLOAT
Definition: sqltypes.h:174
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:299

+ 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:205
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:316
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(), 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(), 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:50
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:248
CHECK(cgen_state)
Definition: sqltypes.h:54
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:256
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:295
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:46
bool is_string() const
Definition: sqltypes.h:399

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 309 of file CgenState.h.

References context_, and ll_bool().

Referenced by Executor::buildIsDeletedCb().

309 { return ::ll_bool(v, context_); }
llvm::LLVMContext & context_
Definition: CgenState.h:316
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 299 of file CgenState.h.

References context_.

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

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

+ Here is the caller graph for this function:

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

Definition at line 304 of file CgenState.h.

References context_.

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

Definition at line 295 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::codegenGeoExpr(), 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().

295  {
297  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:316

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

llvm::LLVMContext& CgenState::context_

Definition at line 316 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::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(), and CodeGenerator::posArg().

std::vector<FunctionOperValue> CgenState::ext_call_cache_

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

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

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

Definition at line 325 of file CgenState.h.

Referenced by CodeGenerator::resolveGroupedColumnReference().

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

Definition at line 315 of file CgenState.h.

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

Definition at line 331 of file CgenState.h.

Referenced by addInValuesBitmap().

llvm::IRBuilder CgenState::ir_builder_

Definition at line 318 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildIsDeletedCb(), 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::codegenGeoLineStringArgs(), CodeGenerator::codegenGeoMultiPolygonArgs(), CodeGenerator::codegenGeoPointArgs(), CodeGenerator::codegenGeoPolygonArgs(), 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::posArg(), and CodeGenerator::toBool().

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

Definition at line 404 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

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

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

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

Definition at line 336 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

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

Definition at line 337 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstants().

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

Definition at line 332 of file CgenState.h.

Referenced by CodeGenerator::checkExpressionRanges().

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

Definition at line 343 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

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

Definition at line 330 of file CgenState.h.

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

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

Definition at line 326 of file CgenState.h.

Referenced by addStringConstant().

llvm::ValueToValueMapTy CgenState::vmap_

Definition at line 317 of file CgenState.h.

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


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