OmniSciDB  ca0c39ec8f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CgenState Struct Reference

#include <CgenState.h>

+ Collaboration diagram for CgenState:

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 size_t num_query_infos, const bool contains_left_deep_outer_join, Executor *executor)
 
 CgenState (const size_t num_query_infos, const bool contains_left_deep_outer_join)
 
 CgenState (llvm::LLVMContext &context)
 
std::tuple< size_t, 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
StringDictionaryTranslationMgr
moveStringDictionaryTranslationMgr (std::unique_ptr< const StringDictionaryTranslationMgr > &&str_dict_translation_mgr)
 
const InValuesBitmapaddInValuesBitmap (std::unique_ptr< InValuesBitmap > &in_values_bitmap)
 
void moveInValuesBitmap (std::unique_ptr< const 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)
 
llvm::Value * emitEntryCall (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 &)
 
llvm::Constant * inlineNull (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)
 
std::vector< std::string > gpuFunctionsToReplace (llvm::Function *fn)
 
void replaceFunctionForGpu (const std::string &fcn_to_replace, llvm::Function *fn)
 
std::shared_ptr< ExecutorgetExecutor () const
 
llvm::LLVMContext & getExecutorContext () const
 
void set_module_shallow_copy (const std::unique_ptr< llvm::Module > &module, bool always_clone=false)
 
void maybeCloneFunctionRecursive (llvm::Function *fn)
 

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

size_t executor_id_
 
llvm::Module * module_
 
llvm::Function * row_func_
 
llvm::Function * filter_func_
 
llvm::Function * current_func_
 
llvm::BasicBlock * row_func_bb_
 
llvm::BasicBlock * filter_func_bb_
 
llvm::CallInst * row_func_call_
 
llvm::CallInst * filter_func_call_
 
std::vector< llvm::Function * > helper_functions_
 
llvm::LLVMContext & context_
 
llvm::ValueToValueMapTy vmap_
 
llvm::IRBuilder ir_builder_
 
std::unordered_map< size_t,
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_
 
InsertionOrderedMap filter_func_args_
 
std::vector< std::unique_ptr
< const InValuesBitmap > > 
in_values_bitmaps_
 
std::vector< std::unique_ptr
< const
StringDictionaryTranslationMgr > > 
str_dict_translation_mgrs_
 
std::map< std::pair
< llvm::Value *, llvm::Value * >
, ArrayLoadCodegen
array_load_cache_
 
std::unordered_map
< std::string, llvm::Value * > 
geo_target_cache_
 
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 >
std::tuple< size_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 38 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 size_t  num_query_infos,
const bool  contains_left_deep_outer_join,
Executor executor 
)

Definition at line 25 of file CgenState.cpp.

28  : executor_id_(executor->getExecutorId())
29  , module_(nullptr)
30  , row_func_(nullptr)
31  , filter_func_(nullptr)
32  , current_func_(nullptr)
33  , row_func_bb_(nullptr)
34  , filter_func_bb_(nullptr)
35  , row_func_call_(nullptr)
36  , filter_func_call_(nullptr)
37  , context_(executor->getContext())
39  , contains_left_deep_outer_join_(contains_left_deep_outer_join)
40  , outer_join_match_found_per_level_(std::max(num_query_infos, size_t(1)) - 1)
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:452
llvm::Function * query_func_
Definition: CgenState.h:464
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
bool needs_geos_
Definition: CgenState.h:462
const bool contains_left_deep_outer_join_
Definition: CgenState.h:451
llvm::Function * row_func_
Definition: CgenState.h:431
llvm::Module * module_
Definition: CgenState.h:430
size_t executor_id_
Definition: CgenState.h:333
llvm::LLVMContext & context_
Definition: CgenState.h:439
llvm::Function * current_func_
Definition: CgenState.h:433
llvm::CallInst * filter_func_call_
Definition: CgenState.h:437
bool needs_error_check_
Definition: CgenState.h:461
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:465
llvm::BasicBlock * filter_func_bb_
Definition: CgenState.h:435
llvm::Function * filter_func_
Definition: CgenState.h:432
llvm::CallInst * row_func_call_
Definition: CgenState.h:436
llvm::BasicBlock * row_func_bb_
Definition: CgenState.h:434
CgenState::CgenState ( const size_t  num_query_infos,
const bool  contains_left_deep_outer_join 
)

Definition at line 46 of file CgenState.cpp.

48  : CgenState(num_query_infos,
49  contains_left_deep_outer_join,
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
CgenState(const size_t num_query_infos, const bool contains_left_deep_outer_join, Executor *executor)
Definition: CgenState.cpp:25
static const ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:376
CgenState::CgenState ( llvm::LLVMContext &  context)

Definition at line 52 of file CgenState.cpp.

54  , module_(nullptr)
55  , row_func_(nullptr)
56  , context_(context)
59  , needs_error_check_(false)
60  , needs_geos_(false)
61  , query_func_(nullptr)
llvm::Function * query_func_
Definition: CgenState.h:464
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
bool needs_geos_
Definition: CgenState.h:462
const bool contains_left_deep_outer_join_
Definition: CgenState.h:451
llvm::Function * row_func_
Definition: CgenState.h:431
llvm::Module * module_
Definition: CgenState.h:430
size_t executor_id_
Definition: CgenState.h:333
llvm::LLVMContext & context_
Definition: CgenState.h:439
bool needs_error_check_
Definition: CgenState.h:461
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:465
static const ExecutorId INVALID_EXECUTOR_ID
Definition: Execute.h:377

Member Function Documentation

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

Definition at line 505 of file CgenState.h.

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

505  {
506  size_t off = off_in;
507  if (off % alignment != 0) {
508  off += (alignment - off % alignment);
509  }
510  return off + alignment;
511  }

+ Here is the caller graph for this function:

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

Definition at line 202 of file CgenState.h.

References in_values_bitmaps_.

Referenced by CodeGenerator::codegen().

203  {
204  if (in_values_bitmap->isEmpty()) {
205  return in_values_bitmap.get();
206  }
207  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
208  return in_values_bitmaps_.back().get();
209  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:455

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

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

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

Referenced by CodeGenerator::codegenCast(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), and anonymous_namespace{WindowFunctionIR.cpp}::get_null_value_by_size_with_encoding().

152  {
153  auto src_bits = val->getType()->getScalarSizeInBits();
154  if (src_bits == dst_bits) {
155  return val;
156  }
157  if (val->getType()->isIntegerTy()) {
158  return ir_builder_.CreateIntCast(
159  val, get_int_type(dst_bits, context_), src_bits != 1);
160  }
161  // real (not dictionary-encoded) strings; store the pointer to the payload
162  if (val->getType()->isPointerTy()) {
163  return ir_builder_.CreatePointerCast(val, get_int_type(dst_bits, context_));
164  }
165 
166  CHECK(val->getType()->isFloatTy() || val->getType()->isDoubleTy());
167 
168  llvm::Type* dst_type = nullptr;
169  switch (dst_bits) {
170  case 64:
171  dst_type = llvm::Type::getDoubleTy(context_);
172  break;
173  case 32:
174  dst_type = llvm::Type::getFloatTy(context_);
175  break;
176  default:
177  CHECK(false);
178  }
179 
180  return ir_builder_.CreateFPCast(val, dst_type);
181 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:439
#define CHECK(condition)
Definition: Logger.h:222

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

References CHECK, ir_builder_, maybeCloneFunctionRecursive(), and module_.

Referenced by spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmp(), CodeGenerator::codegenConstantWidthBucketExpr(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenLogical(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWidthBucketExpr(), CodeGenerator::codegenWindowPosition(), and CodeGenerator::codgenAdjustFixedEncNull().

220  {
221  // Get the function reference from the query module.
222  auto func = module_->getFunction(fname);
223  CHECK(func);
224  // If the function called isn't external, clone the implementation from the runtime
225  // module.
227 
228  return ir_builder_.CreateCall(func, args);
229 }
void maybeCloneFunctionRecursive(llvm::Function *fn)
Definition: CgenState.cpp:183
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
llvm::Module * module_
Definition: CgenState.h:430
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 231 of file CgenState.cpp.

References CHECK, maybeCloneFunctionRecursive(), module_, and query_func_entry_ir_builder_.

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

232  {
233  // Get the function reference from the query module.
234  auto func = module_->getFunction(fname);
235  CHECK(func);
236  // If the function called isn't external, clone the implementation from the runtime
237  // module.
239 
240  return query_func_entry_ir_builder_.CreateCall(func, args);
241 }
void maybeCloneFunctionRecursive(llvm::Function *fn)
Definition: CgenState.cpp:183
llvm::Module * module_
Definition: CgenState.h:430
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:465
#define CHECK(condition)
Definition: Logger.h:222

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

References context_, current_func_, ir_builder_, and needs_error_check_.

245  {
246  needs_error_check_ = true;
247  auto check_ok = llvm::BasicBlock::Create(context_, label + "_ok", current_func_);
248  auto check_fail = llvm::BasicBlock::Create(context_, label + "_fail", current_func_);
249  ir_builder_.CreateCondBr(condition, check_ok, check_fail);
250  ir_builder_.SetInsertPoint(check_fail);
251  ir_builder_.CreateRet(errorCode);
252  ir_builder_.SetInsertPoint(check_ok);
253 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
llvm::LLVMContext & context_
Definition: CgenState.h:439
llvm::Function * current_func_
Definition: CgenState.h:433
bool needs_error_check_
Definition: CgenState.h:461
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 217 of file CgenState.h.

Referenced by spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeoArrayLoadAndNullcheck(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenIsNull(), CodeGenerator::codegenPerRowStringOper(), CodeGenerator::codegenQualifierCmp(), and CodeGenerator::codegenVariableLengthStringColVar().

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

+ Here is the caller graph for this function:

std::shared_ptr< Executor > CgenState::getExecutor ( ) const

Definition at line 375 of file CgenState.cpp.

References CHECK, executor_id_, Executor::getExecutor(), and Executor::INVALID_EXECUTOR_ID.

Referenced by getExecutorContext(), and maybeCloneFunctionRecursive().

375  {
378 }
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
Definition: Execute.cpp:477
size_t executor_id_
Definition: CgenState.h:333
static const ExecutorId INVALID_EXECUTOR_ID
Definition: Execute.h:377
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::LLVMContext & CgenState::getExecutorContext ( ) const

Definition at line 380 of file CgenState.cpp.

References getExecutor().

380  {
381  return getExecutor()->getContext();
382 }
std::shared_ptr< Executor > getExecutor() const
Definition: CgenState.cpp:375

+ Here is the call graph for this function:

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 293 of file CgenState.h.

References literal_bytes_.

293 { return literal_bytes_[device_id]; }
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:535
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:534
std::tuple<size_t, 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:345
#define CHECK_EQ(x, y)
Definition: Logger.h:230
Definition: sqltypes.h:64
bool get_is_null() const
Definition: Analyzer.h:342
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
int64_t bigintval
Definition: Datum.h:49
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
std::string * stringval
Definition: Datum.h:54
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
Definition: Datum.cpp:559
Definition: sqltypes.h:67
Definition: sqltypes.h:68
Datum get_constval() const
Definition: Analyzer.h:343
Definition: sqltypes.h:56
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:60
std::tuple< size_t, size_t > getOrAddLiteral(const Analyzer::Constant *constant, const EncodingType enc_type, const int dict_id, const int device_id)
Definition: CgenState.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 517 of file CgenState.h.

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

517  {
518  const LiteralValue var_val(val);
519  size_t literal_found_off{0};
520  auto& literals = literals_[device_id];
521  for (const auto& literal : literals) {
522  const auto lit_bytes = literalBytes(literal);
523  literal_found_off = addAligned(literal_found_off, lit_bytes);
524  if (literal == var_val) {
525  return {literal_found_off - lit_bytes, lit_bytes};
526  }
527  }
528  literals.emplace_back(val);
529  const auto lit_bytes = literalBytes(var_val);
530  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
531  return {literal_bytes_[device_id] - lit_bytes, lit_bytes};
532  }
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:474
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:505
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:535
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:534

+ Here is the call graph for this function:

std::vector< std::string > CgenState::gpuFunctionsToReplace ( llvm::Function *  fn)

Definition at line 308 of file CgenState.cpp.

References CHECK, and anonymous_namespace{CgenState.cpp}::gpu_replacement_functions.

Referenced by spatial_type::Transform::codegen().

308  {
309  std::vector<std::string> ret;
310 
311  CHECK(fn);
312  CHECK(!fn->isDeclaration());
313 
314  for (auto& basic_block : *fn) {
315  auto& inst_list = basic_block.getInstList();
316  for (auto inst_itr = inst_list.begin(); inst_itr != inst_list.end(); ++inst_itr) {
317  if (auto call_inst = llvm::dyn_cast<llvm::CallInst>(inst_itr)) {
318  auto called_fcn = call_inst->getCalledFunction();
319  CHECK(called_fcn);
320 
321  if (gpu_replacement_functions.find(called_fcn->getName().str()) !=
323  ret.emplace_back(called_fcn->getName());
324  }
325  }
326  }
327  }
328  return ret;
329 }
static const std::unordered_map< std::string, std::shared_ptr< GpuFunctionDefinition > > gpu_replacement_functions
Definition: CgenState.cpp:293
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

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

Definition at line 106 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::codegenWidthBucketExpr(), CodeGenerator::endArgsNullcheck(), inlineNull(), and CodeGenerator::NullCheckCodegen::NullCheckCodegen().

106  {
107  CHECK(type_info.is_fp());
108  switch (type_info.get_type()) {
109  case kFLOAT:
110  return llFp(NULL_FLOAT);
111  case kDOUBLE:
112  return llFp(NULL_DOUBLE);
113  default:
114  abort();
115  }
116 }
#define NULL_DOUBLE
#define NULL_FLOAT
bool is_fp() const
Definition: sqltypes.h:579
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:310
#define CHECK(condition)
Definition: Logger.h:222

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

125  {
126  int64_t max_int{0}, min_int{0};
127  if (is_signed) {
128  std::tie(max_int, min_int) = inline_int_max_min(byte_width);
129  } else {
130  uint64_t max_uint{0}, min_uint{0};
131  std::tie(max_uint, min_uint) = inline_uint_max_min(byte_width);
132  max_int = static_cast<int64_t>(max_uint);
133  CHECK_EQ(uint64_t(0), min_uint);
134  }
135  switch (byte_width) {
136  case 1:
137  return std::make_pair(::ll_int(static_cast<int8_t>(max_int), context_),
138  ::ll_int(static_cast<int8_t>(min_int), context_));
139  case 2:
140  return std::make_pair(::ll_int(static_cast<int16_t>(max_int), context_),
141  ::ll_int(static_cast<int16_t>(min_int), context_));
142  case 4:
143  return std::make_pair(::ll_int(static_cast<int32_t>(max_int), context_),
144  ::ll_int(static_cast<int32_t>(min_int), context_));
145  case 8:
146  return std::make_pair(::ll_int(max_int, context_), ::ll_int(min_int, context_));
147  default:
148  abort();
149  }
150 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:439
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 64 of file CgenState.cpp.

References CHECK, SQLTypeInfo::get_compression(), SQLTypeInfo::get_type(), inline_fixed_encoding_null_val(), inline_int_null_val(), SQLTypeInfo::is_string(), kARRAY, kBIGINT, kBOOLEAN, kDATE, kDECIMAL, kENCODING_DICT, kENCODING_FIXED, 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::codegenCastTimestampToTime(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenExtractHighPrecisionTimestamps(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIntConst(), CodeGenerator::codegenIsNullNumber(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenUMinus(), CodeGenerator::codgenAdjustFixedEncNull(), CodeGenerator::endArgsNullcheck(), inlineNull(), and CodeGenerator::NullCheckCodegen::NullCheckCodegen().

64  {
65  auto type = type_info.get_type();
66  if (type_info.is_string()) {
67  switch (type_info.get_compression()) {
68  case kENCODING_DICT:
69  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
70  case kENCODING_NONE:
71  return llInt(int64_t(0));
72  default:
73  CHECK(false);
74  }
75  }
76  switch (type) {
77  case kBOOLEAN:
78  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
79  case kTINYINT:
80  return llInt(static_cast<int8_t>(inline_int_null_val(type_info)));
81  case kSMALLINT:
82  return llInt(static_cast<int16_t>(inline_int_null_val(type_info)));
83  case kINT:
84  return llInt(static_cast<int32_t>(inline_int_null_val(type_info)));
85  case kBIGINT:
86  return llInt(static_cast<int64_t>(inline_int_null_val(type_info)));
87  case kTIME:
88  case kTIMESTAMP:
89  if (type_info.get_compression() == kENCODING_FIXED) {
90  return llInt(inline_fixed_encoding_null_val(type_info));
91  }
92  case kDATE:
93  case kINTERVAL_DAY_TIME:
95  return llInt(inline_int_null_val(type_info));
96  case kDECIMAL:
97  case kNUMERIC:
98  return llInt(inline_int_null_val(type_info));
99  case kARRAY:
100  return llInt(int64_t(0));
101  default:
102  abort();
103  }
104 }
Definition: sqltypes.h:64
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:379
Definition: sqltypes.h:68
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:387
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:306
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
int64_t inline_fixed_encoding_null_val(const SQL_TYPE_INFO &ti)
Definition: sqltypes.h:60
bool is_string() const
Definition: sqltypes.h:575

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Constant * CgenState::inlineNull ( const SQLTypeInfo ti)

Definition at line 118 of file CgenState.cpp.

References inlineFpNull(), inlineIntNull(), and SQLTypeInfo::is_fp().

118  {
119  return ti.is_fp() ? static_cast<llvm::Constant*>(inlineFpNull(ti))
120  : static_cast<llvm::Constant*>(inlineIntNull(ti));
121 }
bool is_fp() const
Definition: sqltypes.h:579
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:64
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:106

+ Here is the call graph for this function:

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

Definition at line 474 of file CgenState.h.

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

474  {
475  switch (lit.which()) {
476  case 0:
477  return 1; // int8_t
478  case 1:
479  return 2; // int16_t
480  case 2:
481  return 4; // int32_t
482  case 3:
483  return 8; // int64_t
484  case 4:
485  return 4; // float
486  case 5:
487  return 8; // double
488  case 6:
489  return 4; // std::pair<std::string, int>
490  case 7:
491  return 4; // std::string
492  case 8:
493  return 4; // std::vector<double>
494  case 9:
495  return 4; // std::vector<int32_t>
496  case 10:
497  return 4; // std::vector<int8_t>
498  case 11:
499  return 4; // std::pair<std::vector<int8_t>, int>
500  default:
501  abort();
502  }
503  }

+ Here is the caller graph for this function:

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

Definition at line 320 of file CgenState.h.

References context_, and ll_bool().

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

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

References context_.

Referenced by CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFpArith(), CodeGenerator::codegenGeoUOper(), CodeGenerator::codegenIsNullNumber(), anonymous_namespace{WindowFunctionIR.cpp}::get_null_value_by_size(), anonymous_namespace{WindowFunctionIR.cpp}::get_null_value_by_size_with_encoding(), and inlineFpNull().

310  {
311  return static_cast<llvm::ConstantFP*>(
312  llvm::ConstantFP::get(llvm::Type::getFloatTy(context_), v));
313  }
llvm::LLVMContext & context_
Definition: CgenState.h:439

+ Here is the caller graph for this function:

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

Definition at line 315 of file CgenState.h.

References context_.

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

Definition at line 306 of file CgenState.h.

References context_, and ll_int().

Referenced by spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastBetweenTimestamps(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), 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(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenPerRowStringOper(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWidthBucketExpr(), CodeGenerator::codegenWindowPosition(), CodeGenerator::codgenAdjustFixedEncNull(), anonymous_namespace{WindowFunctionIR.cpp}::get_null_value_by_size(), anonymous_namespace{WindowFunctionIR.cpp}::get_null_value_by_size_with_encoding(), and inlineIntNull().

306  {
308  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:439

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CgenState::maybeCloneFunctionRecursive ( llvm::Function *  fn)

Definition at line 183 of file CgenState.cpp.

References CHECK, getExecutor(), and vmap_.

Referenced by spatial_type::Transform::codegen(), emitCall(), and emitEntryCall().

183  {
184  CHECK(fn);
185  if (!fn->isDeclaration()) {
186  return;
187  }
188 
189  // Get the implementation from the runtime module.
190  auto func_impl = getExecutor()->get_rt_module()->getFunction(fn->getName());
191  CHECK(func_impl) << fn->getName().str();
192 
193  if (func_impl->isDeclaration()) {
194  return;
195  }
196 
197  auto DestI = fn->arg_begin();
198  for (auto arg_it = func_impl->arg_begin(); arg_it != func_impl->arg_end(); ++arg_it) {
199  DestI->setName(arg_it->getName());
200  vmap_[&*arg_it] = &*DestI++;
201  }
202 
203  llvm::SmallVector<llvm::ReturnInst*, 8> Returns; // Ignore returns cloned.
204 #if LLVM_VERSION_MAJOR > 12
205  llvm::CloneFunctionInto(
206  fn, func_impl, vmap_, llvm::CloneFunctionChangeType::DifferentModule, Returns);
207 #else
208  llvm::CloneFunctionInto(fn, func_impl, vmap_, /*ModuleLevelChanges=*/true, Returns);
209 #endif
210 
211  for (auto it = llvm::inst_begin(fn), e = llvm::inst_end(fn); it != e; ++it) {
212  if (llvm::isa<llvm::CallInst>(*it)) {
213  auto& call = llvm::cast<llvm::CallInst>(*it);
214  maybeCloneFunctionRecursive(call.getCalledFunction());
215  }
216  }
217 }
std::shared_ptr< Executor > getExecutor() const
Definition: CgenState.cpp:375
void maybeCloneFunctionRecursive(llvm::Function *fn)
Definition: CgenState.cpp:183
#define CHECK(condition)
Definition: Logger.h:222
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:440

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void CgenState::moveInValuesBitmap ( std::unique_ptr< const InValuesBitmap > &  in_values_bitmap)
inline

Definition at line 210 of file CgenState.h.

References in_values_bitmaps_.

210  {
211  if (!in_values_bitmap->isEmpty()) {
212  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
213  }
214  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:455
const StringDictionaryTranslationMgr* CgenState::moveStringDictionaryTranslationMgr ( std::unique_ptr< const StringDictionaryTranslationMgr > &&  str_dict_translation_mgr)
inline

Definition at line 196 of file CgenState.h.

References str_dict_translation_mgrs_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenCastFromString(), and CodeGenerator::codegenPseudoStringOper().

197  {
198  str_dict_translation_mgrs_.emplace_back(std::move(str_dict_translation_mgr));
199  return str_dict_translation_mgrs_.back().get();
200  }
std::vector< std::unique_ptr< const StringDictionaryTranslationMgr > > str_dict_translation_mgrs_
Definition: CgenState.h:457

+ Here is the caller graph for this function:

void CgenState::replaceFunctionForGpu ( const std::string &  fcn_to_replace,
llvm::Function *  fn 
)

Definition at line 331 of file CgenState.cpp.

References run_benchmark_import::args, CHECK, CHECK_EQ, context_, anonymous_namespace{CgenState.cpp}::gpu_replacement_functions, module_, and VLOG.

Referenced by spatial_type::Transform::codegen().

332  {
333  CHECK(fn);
334  CHECK(!fn->isDeclaration());
335 
336  auto map_it = gpu_replacement_functions.find(fcn_to_replace);
337  if (map_it == gpu_replacement_functions.end()) {
338  throw QueryMustRunOnCpu("Codegen failed: Could not find replacement functon for " +
339  fcn_to_replace +
340  " to run on gpu. Query step must run in cpu mode.");
341  }
342  const auto& gpu_fcn_obj = map_it->second;
343  CHECK(gpu_fcn_obj);
344  VLOG(1) << "Replacing " << fcn_to_replace << " with " << gpu_fcn_obj->name_
345  << " for parent function " << fn->getName().str();
346 
347  for (auto& basic_block : *fn) {
348  auto& inst_list = basic_block.getInstList();
349  for (auto inst_itr = inst_list.begin(); inst_itr != inst_list.end(); ++inst_itr) {
350  if (auto call_inst = llvm::dyn_cast<llvm::CallInst>(inst_itr)) {
351  auto called_fcn = call_inst->getCalledFunction();
352  CHECK(called_fcn);
353 
354  if (called_fcn->getName() == fcn_to_replace) {
355  std::vector<llvm::Value*> args;
356  std::vector<llvm::Type*> arg_types;
357  for (auto& arg : call_inst->args()) {
358  arg_types.push_back(arg.get()->getType());
359  args.push_back(arg.get());
360  }
361  auto gpu_func = gpu_fcn_obj->getFunction(module_, context_);
362  CHECK(gpu_func);
363  auto gpu_func_type = gpu_func.getFunctionType();
364  CHECK(gpu_func_type);
365  CHECK_EQ(gpu_func_type->getReturnType(), called_fcn->getReturnType());
366  llvm::ReplaceInstWithInst(call_inst,
367  llvm::CallInst::Create(gpu_func, args, ""));
368  return;
369  }
370  }
371  }
372  }
373 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
static const std::unordered_map< std::string, std::shared_ptr< GpuFunctionDefinition > > gpu_replacement_functions
Definition: CgenState.cpp:293
llvm::Module * module_
Definition: CgenState.h:430
llvm::LLVMContext & context_
Definition: CgenState.h:439
#define CHECK(condition)
Definition: Logger.h:222
#define VLOG(n)
Definition: Logger.h:316

+ Here is the caller graph for this function:

void CgenState::set_module_shallow_copy ( const std::unique_ptr< llvm::Module > &  module,
bool  always_clone = false 
)

Definition at line 384 of file CgenState.cpp.

References CodeGenerator::alwaysCloneRuntimeFunction(), module_, and vmap_.

Referenced by GpuReductionHelperJIT::codegen().

385  {
386  module_ =
387  llvm::CloneModule(*llvm_module, vmap_, [always_clone](const llvm::GlobalValue* gv) {
388  auto func = llvm::dyn_cast<llvm::Function>(gv);
389  if (!func) {
390  return true;
391  }
392  return (func->getLinkage() == llvm::GlobalValue::LinkageTypes::PrivateLinkage ||
393  func->getLinkage() == llvm::GlobalValue::LinkageTypes::InternalLinkage ||
394  (always_clone && CodeGenerator::alwaysCloneRuntimeFunction(func)));
395  }).release();
396 }
llvm::Module * module_
Definition: CgenState.h:430
static bool alwaysCloneRuntimeFunction(const llvm::Function *func)
llvm::ValueToValueMapTy vmap_
Definition: CgenState.h:440

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::map<std::pair<llvm::Value*, llvm::Value*>, ArrayLoadCodegen> CgenState::array_load_cache_

Definition at line 459 of file CgenState.h.

Referenced by CodeGenerator::codegenGeoArrayLoadAndNullcheck().

const bool CgenState::contains_left_deep_outer_join_

Definition at line 451 of file CgenState.h.

llvm::LLVMContext& CgenState::context_

Definition at line 439 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), CodeGenerator::castArrayPointer(), castToTypeIn(), spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenBufferArgs(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenDateTruncHighPrecisionTimestamps(), CodeGenerator::codegenDiv(), CodeGenerator::codegenFixedLengthColVar(), CodeGenerator::codegenFixedLengthColVarInWindow(), CodeGenerator::codegenFunctionOper(), CodeGenerator::codegenFunctionOperCastArgs(), CodeGenerator::codegenFunctionOperNullArg(), CodeGenerator::codegenFunctionOperWithCustomTypeHandling(), CodeGenerator::codegenGeoArgs(), CodeGenerator::codegenGeoArrayLoadAndNullcheck(), CodeGenerator::codegenGeoBinOper(), CodeGenerator::codegenGeoConstant(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenGeoUOper(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenIsNull(), spatial_type::Transform::codegenLoads(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenOuterJoinNullPlaceholder(), CodeGenerator::codegenOverlaps(), CodeGenerator::codegenPerRowStringOper(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenVariableLengthStringColVar(), CodeGenerator::codegenWidthBucketExpr(), 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::createLineStringStructType(), CodeGenerator::createMultiLineStringStructType(), CodeGenerator::createMultiPointStructType(), CodeGenerator::createMultiPolygonStructType(), CodeGenerator::createPointStructType(), CodeGenerator::createPolygonStructType(), emitErrorCheck(), CodeGenerator::endArgsNullcheck(), anonymous_namespace{TableFunctionCompilationContext.cpp}::generate_entry_point(), anonymous_namespace{ExtensionsIR.cpp}::get_buffer_struct_type(), inlineIntMaxMin(), llBool(), llFp(), llInt(), AutomaticIRMetadataGuard::markInstructions(), CodeGenerator::NullCheckCodegen::NullCheckCodegen(), CodeGenerator::posArg(), and replaceFunctionForGpu().

size_t CgenState::executor_id_

Definition at line 333 of file CgenState.h.

Referenced by getExecutor().

std::vector<FunctionOperValue> CgenState::ext_call_cache_

Definition at line 447 of file CgenState.h.

Referenced by CodeGenerator::codegenFunctionOper().

std::unordered_map<size_t, std::vector<llvm::Value*> > CgenState::fetch_cache_
llvm::Function* CgenState::filter_func_

Definition at line 432 of file CgenState.h.

InsertionOrderedMap CgenState::filter_func_args_

Definition at line 454 of file CgenState.h.

llvm::BasicBlock* CgenState::filter_func_bb_

Definition at line 435 of file CgenState.h.

llvm::CallInst* CgenState::filter_func_call_

Definition at line 437 of file CgenState.h.

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

Definition at line 450 of file CgenState.h.

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

std::unordered_map<std::string, llvm::Value*> CgenState::geo_target_cache_

Definition at line 460 of file CgenState.h.

Referenced by CodeGenerator::codegenGeoOperator().

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

Definition at line 448 of file CgenState.h.

Referenced by CodeGenerator::resolveGroupedColumnReference().

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

Definition at line 438 of file CgenState.h.

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

Definition at line 455 of file CgenState.h.

Referenced by addInValuesBitmap(), and moveInValuesBitmap().

llvm::IRBuilder CgenState::ir_builder_

Definition at line 441 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), Executor::buildJoinLoops(), CodeGenerator::castArrayPointer(), castToTypeIn(), JoinLoop::codegen(), spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenBufferArgs(), 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::codegenGeoConstant(), CodeGenerator::codegenGeoLineStringArgs(), CodeGenerator::codegenGeoMultiLineStringArgs(), CodeGenerator::codegenGeoMultiPointArgs(), CodeGenerator::codegenGeoMultiPolygonArgs(), CodeGenerator::codegenGeoPointArgs(), CodeGenerator::codegenGeoPolygonArgs(), CodeGenerator::codegenGeosConstructorCall(), CodeGenerator::codegenGeosPredicateCall(), CodeGenerator::codegenHoistedConstantsPlaceholders(), CodeGenerator::codegenIsNullNumber(), spatial_type::Transform::codegenLoads(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenOuterJoinNullPlaceholder(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenWidthBucketExpr(), CodeGenerator::codgenAdjustFixedEncNull(), ScalarCodeGenerator::compile(), anonymous_namespace{ResultSetReductionCodegen.cpp}::create_entry_block(), anonymous_namespace{ResultSetReductionInterpreterStubs.cpp}::create_stub_function(), emitCall(), emitErrorCheck(), CodeGenerator::endArgsNullcheck(), JoinLoop::evaluateOuterJoinCondition(), CodeGenerator::NullCheckCodegen::NullCheckCodegen(), CodeGenerator::posArg(), and CodeGenerator::toBool().

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

Definition at line 535 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

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

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

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

Definition at line 465 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsLoads(), and emitEntryCall().

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

Definition at line 466 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstants().

llvm::BasicBlock* CgenState::row_func_bb_

Definition at line 434 of file CgenState.h.

llvm::CallInst* CgenState::row_func_call_

Definition at line 436 of file CgenState.h.

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

Definition at line 472 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

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

Definition at line 453 of file CgenState.h.

Referenced by CodeGenerator::posArg().

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

Definition at line 449 of file CgenState.h.

Referenced by addStringConstant().

std::vector<std::unique_ptr<const StringDictionaryTranslationMgr> > CgenState::str_dict_translation_mgrs_

Definition at line 457 of file CgenState.h.

Referenced by moveStringDictionaryTranslationMgr().

llvm::ValueToValueMapTy CgenState::vmap_

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