OmniSciDB  72c90bc290
 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, shared::StringDictKey >, 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 shared::StringDictKey &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 TreeModelPredictionMgrmoveTreeModelPredictionMgr (std::unique_ptr< const TreeModelPredictionMgr > &&tree_model_prediction_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 TreeModelPredictionMgr > > 
tree_model_prediction_mgrs_
 
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 41 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, shared::StringDictKey>, std::string, std::vector<double>, std::vector<int32_t>, std::vector<int8_t>, std::pair<std::vector<int8_t>, int>>

Definition at line 185 of file CgenState.h.

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

Definition at line 186 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 26 of file CgenState.cpp.

29  : executor_id_(executor->getExecutorId())
30  , module_(nullptr)
31  , row_func_(nullptr)
32  , filter_func_(nullptr)
33  , current_func_(nullptr)
34  , row_func_bb_(nullptr)
35  , filter_func_bb_(nullptr)
36  , row_func_call_(nullptr)
37  , filter_func_call_(nullptr)
38  , context_(executor->getContext())
40  , contains_left_deep_outer_join_(contains_left_deep_outer_join)
41  , outer_join_match_found_per_level_(std::max(num_query_infos, size_t(1)) - 1)
42  , needs_error_check_(false)
43  , needs_geos_(false)
44  , query_func_(nullptr)
std::vector< llvm::Value * > outer_join_match_found_per_level_
Definition: CgenState.h:395
llvm::Function * query_func_
Definition: CgenState.h:408
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
bool needs_geos_
Definition: CgenState.h:406
const bool contains_left_deep_outer_join_
Definition: CgenState.h:394
llvm::Function * row_func_
Definition: CgenState.h:374
llvm::Module * module_
Definition: CgenState.h:373
size_t executor_id_
Definition: CgenState.h:276
llvm::LLVMContext & context_
Definition: CgenState.h:382
llvm::Function * current_func_
Definition: CgenState.h:376
llvm::CallInst * filter_func_call_
Definition: CgenState.h:380
bool needs_error_check_
Definition: CgenState.h:405
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:409
llvm::BasicBlock * filter_func_bb_
Definition: CgenState.h:378
llvm::Function * filter_func_
Definition: CgenState.h:375
llvm::CallInst * row_func_call_
Definition: CgenState.h:379
llvm::BasicBlock * row_func_bb_
Definition: CgenState.h:377
CgenState::CgenState ( const size_t  num_query_infos,
const bool  contains_left_deep_outer_join 
)

Definition at line 47 of file CgenState.cpp.

49  : CgenState(num_query_infos,
50  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:509
static constexpr ExecutorId UNITARY_EXECUTOR_ID
Definition: Execute.h:423
CgenState(const size_t num_query_infos, const bool contains_left_deep_outer_join, Executor *executor)
Definition: CgenState.cpp:26
CgenState::CgenState ( llvm::LLVMContext &  context)

Definition at line 53 of file CgenState.cpp.

55  , module_(nullptr)
56  , row_func_(nullptr)
57  , context_(context)
60  , needs_error_check_(false)
61  , needs_geos_(false)
62  , query_func_(nullptr)
llvm::Function * query_func_
Definition: CgenState.h:408
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
static constexpr ExecutorId INVALID_EXECUTOR_ID
Definition: Execute.h:424
bool needs_geos_
Definition: CgenState.h:406
const bool contains_left_deep_outer_join_
Definition: CgenState.h:394
llvm::Function * row_func_
Definition: CgenState.h:374
llvm::Module * module_
Definition: CgenState.h:373
size_t executor_id_
Definition: CgenState.h:276
llvm::LLVMContext & context_
Definition: CgenState.h:382
bool needs_error_check_
Definition: CgenState.h:405
llvm::IRBuilder query_func_entry_ir_builder_
Definition: CgenState.h:409

Member Function Documentation

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

Definition at line 449 of file CgenState.h.

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

449  {
450  size_t off = off_in;
451  if (off % alignment != 0) {
452  off += (alignment - off % alignment);
453  }
454  return off + alignment;
455  }

+ Here is the caller graph for this function:

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

Definition at line 211 of file CgenState.h.

References in_values_bitmaps_.

Referenced by CodeGenerator::codegen().

212  {
213  if (in_values_bitmap->isEmpty()) {
214  return in_values_bitmap.get();
215  }
216  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
217  return in_values_bitmaps_.back().get();
218  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:398

+ Here is the caller graph for this function:

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

Definition at line 190 of file CgenState.h.

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

Referenced by CodeGenerator::codegen().

190  {
191  llvm::Value* str_lv = ir_builder_.CreateGlobalString(
192  str, "str_const_" + std::to_string(std::hash<std::string>()(str)));
193  auto i8_ptr = llvm::PointerType::get(get_int_type(8, context_), 0);
194  str_constants_.push_back(str_lv);
195  str_lv = ir_builder_.CreateBitCast(str_lv, i8_ptr);
196  return str_lv;
197  }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
std::vector< llvm::Value * > str_constants_
Definition: CgenState.h:392
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
llvm::LLVMContext & context_
Definition: CgenState.h:382

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

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

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

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

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

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

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

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

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

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

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

References context_, current_func_, ir_builder_, and needs_error_check_.

243  {
244  needs_error_check_ = true;
245  auto check_ok = llvm::BasicBlock::Create(context_, label + "_ok", current_func_);
246  auto check_fail = llvm::BasicBlock::Create(context_, label + "_fail", current_func_);
247  ir_builder_.CreateCondBr(condition, check_ok, check_fail);
248  ir_builder_.SetInsertPoint(check_fail);
249  ir_builder_.CreateRet(errorCode);
250  ir_builder_.SetInsertPoint(check_ok);
251 }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
llvm::LLVMContext & context_
Definition: CgenState.h:382
llvm::Function * current_func_
Definition: CgenState.h:376
bool needs_error_check_
Definition: CgenState.h:405
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 
)

Definition at line 395 of file CgenState.cpp.

References CHECK, CHECK_EQ, context_, ir_builder_, module_, and run_benchmark_import::result.

Referenced by spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastNonStringToString(), 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(), CodeGenerator::codegenStringFetchAndEncode(), and CodeGenerator::codegenVariableLengthStringColVar().

400  {
401  std::vector<llvm::Type*> arg_types;
402  for (const auto arg : args) {
403  CHECK(arg);
404  arg_types.push_back(arg->getType());
405  }
406  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
407  llvm::AttributeList attrs;
408  if (!fnattrs.empty()) {
409  std::vector<std::pair<unsigned, llvm::Attribute>> indexedAttrs;
410  indexedAttrs.reserve(fnattrs.size());
411  for (auto attr : fnattrs) {
412  indexedAttrs.emplace_back(llvm::AttributeList::FunctionIndex,
413  llvm::Attribute::get(context_, attr));
414  }
415  attrs = llvm::AttributeList::get(context_,
416  {&indexedAttrs.front(), indexedAttrs.size()});
417  }
418 
419  auto func_p = module_->getOrInsertFunction(fname, func_ty, attrs);
420  CHECK(func_p);
421  auto callee = func_p.getCallee();
422  llvm::Function* func{nullptr};
423  if (auto callee_cast = llvm::dyn_cast<llvm::ConstantExpr>(callee)) {
424  // Get or insert function automatically adds a ConstantExpr cast if the return type
425  // of the existing function does not match the supplied return type.
426  CHECK(callee_cast->isCast());
427  CHECK_EQ(callee_cast->getNumOperands(), size_t(1));
428  func = llvm::dyn_cast<llvm::Function>(callee_cast->getOperand(0));
429  } else {
430  func = llvm::dyn_cast<llvm::Function>(callee);
431  }
432  CHECK(func);
433  llvm::FunctionType* func_type = func_p.getFunctionType();
434  CHECK(func_type);
435  if (has_struct_return) {
436  const auto arg_ti = func_type->getParamType(0);
437  CHECK(arg_ti->isPointerTy() && arg_ti->getPointerElementType()->isStructTy());
438  auto attr_list = func->getAttributes();
439 #if 14 <= LLVM_VERSION_MAJOR
440  llvm::AttrBuilder arr_arg_builder(context_, attr_list.getParamAttrs(0));
441 #else
442  llvm::AttrBuilder arr_arg_builder(attr_list.getParamAttributes(0));
443 #endif
444  arr_arg_builder.addAttribute(llvm::Attribute::StructRet);
445  func->addParamAttrs(0, arr_arg_builder);
446  }
447  llvm::Value* result = ir_builder_.CreateCall(func_p, args);
448  // check the assumed type
449  CHECK_EQ(result->getType(), ret_type);
450  return result;
451 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
llvm::Module * module_
Definition: CgenState.h:373
llvm::LLVMContext & context_
Definition: CgenState.h:382
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

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

Definition at line 371 of file CgenState.cpp.

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

Referenced by getExecutorContext(), and maybeCloneFunctionRecursive().

371  {
374 }
static constexpr ExecutorId INVALID_EXECUTOR_ID
Definition: Execute.h:424
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:509
size_t executor_id_
Definition: CgenState.h:276
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 376 of file CgenState.cpp.

References getExecutor().

376  {
377  return getExecutor()->getContext();
378 }
std::shared_ptr< Executor > getExecutor() const
Definition: CgenState.cpp:371

+ Here is the call graph for this function:

size_t CgenState::getLiteralBufferUsage ( const int  device_id)
inline

Definition at line 236 of file CgenState.h.

References literal_bytes_.

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

Definition at line 188 of file CgenState.h.

References literals_.

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

Definition at line 49 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().

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

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

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

462  {
463  const LiteralValue var_val(val);
464  size_t literal_found_off{0};
465  auto& literals = literals_[device_id];
466  for (const auto& literal : literals) {
467  const auto lit_bytes = literalBytes(literal);
468  literal_found_off = addAligned(literal_found_off, lit_bytes);
469  if (literal == var_val) {
470  return {literal_found_off - lit_bytes, lit_bytes};
471  }
472  }
473  literals.emplace_back(val);
474  const auto lit_bytes = literalBytes(var_val);
475  literal_bytes_[device_id] = addAligned(literal_bytes_[device_id], lit_bytes);
476  return {literal_bytes_[device_id] - lit_bytes, lit_bytes};
477  }
static size_t literalBytes(const CgenState::LiteralValue &lit)
Definition: CgenState.h:418
boost::variant< int8_t, int16_t, int32_t, int64_t, float, double, std::pair< std::string, shared::StringDictKey >, std::string, std::vector< double >, std::vector< int32_t >, std::vector< int8_t >, std::pair< std::vector< int8_t >, int >> LiteralValue
Definition: CgenState.h:185
static size_t addAligned(const size_t off_in, const size_t alignment)
Definition: CgenState.h:449
std::unordered_map< int, size_t > literal_bytes_
Definition: CgenState.h:480
std::unordered_map< int, LiteralValues > literals_
Definition: CgenState.h:479

+ Here is the call graph for this function:

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

Definition at line 306 of file CgenState.cpp.

References CHECK, CodegenUtil::getCalledFunctionName(), and anonymous_namespace{CgenState.cpp}::gpu_replacement_functions.

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

306  {
307  std::vector<std::string> ret;
308 
309  CHECK(fn);
310  CHECK(!fn->isDeclaration());
311 
312  for (auto& basic_block : *fn) {
313  auto& inst_list = basic_block.getInstList();
314  for (auto inst_itr = inst_list.begin(); inst_itr != inst_list.end(); ++inst_itr) {
315  if (auto call_inst = llvm::dyn_cast<llvm::CallInst>(inst_itr)) {
316  auto const called_func_name = CodegenUtil::getCalledFunctionName(*call_inst);
317  CHECK(called_func_name);
318 
319  if (gpu_replacement_functions.find(std::string(*called_func_name)) !=
321  ret.emplace_back(*called_func_name);
322  }
323  }
324  }
325  }
326  return ret;
327 }
std::optional< std::string_view > getCalledFunctionName(llvm::CallInst &call_inst)
static const std::unordered_map< std::string, std::shared_ptr< GpuFunctionDefinition > > gpu_replacement_functions
Definition: CgenState.cpp:291
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 104 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().

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

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

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

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

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

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

Referenced by CodeGenerator::codegenPerRowStringOper().

116  {
117  return ti.is_fp() ? static_cast<llvm::Constant*>(inlineFpNull(ti))
118  : static_cast<llvm::Constant*>(inlineIntNull(ti));
119 }
bool is_fp() const
Definition: sqltypes.h:571
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:65
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:104

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

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

418  {
419  switch (lit.which()) {
420  case 0:
421  return 1; // int8_t
422  case 1:
423  return 2; // int16_t
424  case 2:
425  return 4; // int32_t
426  case 3:
427  return 8; // int64_t
428  case 4:
429  return 4; // float
430  case 5:
431  return 8; // double
432  case 6:
433  return 4; // std::pair<std::string, int>
434  case 7:
435  return 4; // std::string
436  case 8:
437  return 4; // std::vector<double>
438  case 9:
439  return 4; // std::vector<int32_t>
440  case 10:
441  return 4; // std::vector<int8_t>
442  case 11:
443  return 4; // std::pair<std::vector<int8_t>, int>
444  default:
445  abort();
446  }
447  }

+ Here is the caller graph for this function:

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

Definition at line 263 of file CgenState.h.

References context_, and ll_bool().

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

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

References context_.

Referenced by CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenCmp(), 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().

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

+ Here is the caller graph for this function:

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

Definition at line 258 of file CgenState.h.

References context_.

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

Definition at line 249 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::codegenCastNonStringToString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), CodeGenerator::codegenCmp(), 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::codegenStringFetchAndEncode(), 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().

249  {
251  }
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:382

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

References CHECK, getExecutor(), and vmap_.

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

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

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

References in_values_bitmaps_.

219  {
220  if (!in_values_bitmap->isEmpty()) {
221  in_values_bitmaps_.emplace_back(std::move(in_values_bitmap));
222  }
223  }
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
Definition: CgenState.h:398
const StringDictionaryTranslationMgr* CgenState::moveStringDictionaryTranslationMgr ( std::unique_ptr< const StringDictionaryTranslationMgr > &&  str_dict_translation_mgr)
inline

Definition at line 199 of file CgenState.h.

References str_dict_translation_mgrs_.

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

200  {
201  str_dict_translation_mgrs_.emplace_back(std::move(str_dict_translation_mgr));
202  return str_dict_translation_mgrs_.back().get();
203  }
std::vector< std::unique_ptr< const StringDictionaryTranslationMgr > > str_dict_translation_mgrs_
Definition: CgenState.h:401

+ Here is the caller graph for this function:

const TreeModelPredictionMgr* CgenState::moveTreeModelPredictionMgr ( std::unique_ptr< const TreeModelPredictionMgr > &&  tree_model_prediction_mgr)
inline

Definition at line 205 of file CgenState.h.

References tree_model_prediction_mgrs_.

Referenced by CodeGenerator::codegenTreeRegPredict().

206  {
207  tree_model_prediction_mgrs_.emplace_back(std::move(tree_model_prediction_mgr));
208  return tree_model_prediction_mgrs_.back().get();
209  }
std::vector< std::unique_ptr< const TreeModelPredictionMgr > > tree_model_prediction_mgrs_
Definition: CgenState.h:399

+ Here is the caller graph for this function:

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

Definition at line 329 of file CgenState.cpp.

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

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

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

+ Here is the call graph for this function:

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

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

Referenced by GpuReductionHelperJIT::codegen().

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

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

Referenced by CodeGenerator::codegenGeoArrayLoadAndNullcheck().

const bool CgenState::contains_left_deep_outer_join_

Definition at line 394 of file CgenState.h.

llvm::LLVMContext& CgenState::context_

Definition at line 382 of file CgenState.h.

Referenced by addStringConstant(), CodeGenerator::beginArgsNullcheck(), CodeGenerator::castArrayPointer(), castToTypeIn(), spatial_type::Transform::codegen(), CodeGenerator::codegen(), CodeGenerator::codegenAdd(), GroupByAndAggregate::codegenAggArg(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenArrayBuff(), CodeGenerator::codegenArrayExpr(), CodeGenerator::codegenBinOpWithOverflowForCPU(), CodeGenerator::codegenBoundingBoxIntersect(), CodeGenerator::codegenBufferArgs(), CodeGenerator::codegenCase(), CodeGenerator::codegenCast(), CodeGenerator::codegenCastBetweenIntTypes(), CodeGenerator::codegenCastBetweenIntTypesOverflowChecks(), CodeGenerator::codegenCastFromFp(), CodeGenerator::codegenCastFromString(), CodeGenerator::codegenCastNonStringToString(), CodeGenerator::codegenCastTimestampToDate(), CodeGenerator::codegenCastTimestampToTime(), CodeGenerator::codegenCastToFp(), CodeGenerator::codegenCmp(), 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::codegenPerRowStringOper(), CodeGenerator::codegenQualifierCmp(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenStringFetchAndEncode(), 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(), CodeGenerator::createStringViewStructType(), emitErrorCheck(), emitExternalCall(), 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 276 of file CgenState.h.

Referenced by getExecutor().

std::vector<FunctionOperValue> CgenState::ext_call_cache_

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

InsertionOrderedMap CgenState::filter_func_args_

Definition at line 397 of file CgenState.h.

llvm::BasicBlock* CgenState::filter_func_bb_

Definition at line 378 of file CgenState.h.

llvm::CallInst* CgenState::filter_func_call_

Definition at line 380 of file CgenState.h.

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

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

Referenced by CodeGenerator::codegenGeoOperator().

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

Definition at line 391 of file CgenState.h.

Referenced by CodeGenerator::resolveGroupedColumnReference().

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

Definition at line 381 of file CgenState.h.

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

Definition at line 398 of file CgenState.h.

Referenced by addInValuesBitmap(), and moveInValuesBitmap().

llvm::IRBuilder CgenState::ir_builder_

Definition at line 384 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::codegenCmp(), 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::codegenIsNull(), CodeGenerator::codegenIsNullNumber(), spatial_type::Transform::codegenLoads(), CodeGenerator::codegenLogical(), CodeGenerator::codegenLogicalShortCircuit(), CodeGenerator::codegenMod(), CodeGenerator::codegenMul(), CodeGenerator::codegenOuterJoinNullPlaceholder(), CodeGenerator::codegenRowId(), CodeGenerator::codegenSkipOverflowCheckForNull(), CodeGenerator::codegenStringFetchAndEncode(), CodeGenerator::codegenSub(), CodeGenerator::codegenUMinus(), CodeGenerator::codegenVariableLengthStringColVar(), CodeGenerator::codegenWidthBucketExpr(), CodeGenerator::codgenAdjustFixedEncNull(), ScalarCodeGenerator::compile(), anonymous_namespace{ResultSetReductionCodegen.cpp}::create_entry_block(), anonymous_namespace{ResultSetReductionInterpreterStubs.cpp}::create_stub_function(), CodegenUtil::createPtrWithHoistedMemoryAddr(), emitCall(), emitErrorCheck(), emitExternalCall(), 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 480 of file CgenState.h.

Referenced by getLiteralBufferUsage(), and getOrAddLiteral().

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

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

Referenced by CodeGenerator::codegenHoistedConstantsLoads().

llvm::IRBuilder CgenState::query_func_entry_ir_builder_

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

Referenced by CodeGenerator::codegenHoistedConstants().

llvm::BasicBlock* CgenState::row_func_bb_

Definition at line 377 of file CgenState.h.

llvm::CallInst* CgenState::row_func_call_

Definition at line 379 of file CgenState.h.

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

Definition at line 416 of file CgenState.h.

Referenced by CodeGenerator::codegenHoistedConstantsPlaceholders().

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

Definition at line 396 of file CgenState.h.

Referenced by CodeGenerator::posArg().

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

Definition at line 392 of file CgenState.h.

Referenced by addStringConstant().

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

Definition at line 401 of file CgenState.h.

Referenced by moveStringDictionaryTranslationMgr().

std::vector<std::unique_ptr<const TreeModelPredictionMgr> > CgenState::tree_model_prediction_mgrs_

Definition at line 399 of file CgenState.h.

Referenced by moveTreeModelPredictionMgr().

llvm::ValueToValueMapTy CgenState::vmap_

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