26 #include "../Analyzer/Analyzer.h"
27 #include "../Shared/InsertionOrderedMap.h"
29 #include <llvm/IR/Constants.h>
30 #include <llvm/IR/IRBuilder.h>
31 #include <llvm/Transforms/Utils/ValueMapper.h>
44 const bool contains_left_deep_outer_join,
46 CgenState(
const size_t num_query_infos,
const bool contains_left_deep_outer_join);
52 const int device_id) {
102 throw std::runtime_error(
103 "CHAR / VARCHAR NULL literal not supported in this context");
117 if (ti.get_subtype() ==
kDOUBLE) {
118 std::vector<double> double_array_literal;
122 double d = c->get_constval().doubleval;
123 double_array_literal.push_back(d);
127 if (ti.get_subtype() ==
kINT) {
128 std::vector<int32_t> int32_array_literal;
132 int32_t i = c->get_constval().intval;
133 int32_array_literal.push_back(i);
138 std::vector<int8_t> int8_array_literal;
142 int8_t i = c->get_constval().tinyintval;
143 int8_array_literal.push_back(i);
145 if (ti.get_comp_param() == 64) {
146 return getOrAddLiteral(std::make_pair(int8_array_literal, 64), device_id);
150 throw std::runtime_error(
"Unsupported literal array");
154 std::vector<int8_t> int8_array_literal;
158 int8_t i = c->get_constval().tinyintval;
159 int8_array_literal.push_back(i);
161 if (ti.get_comp_param() == 32) {
162 return getOrAddLiteral(std::make_pair(int8_array_literal, 32), device_id);
167 throw std::runtime_error(
"Encoded literal arrays are not supported");
180 std::pair<std::string, shared::StringDictKey>,
183 std::vector<int32_t>,
185 std::pair<std::vector<int8_t>,
int>>;
191 llvm::Value* str_lv =
ir_builder_.CreateGlobalString(
192 str,
"str_const_" +
std::to_string(std::hash<std::string>()(str)));
195 str_lv =
ir_builder_.CreateBitCast(str_lv, i8_ptr);
200 std::unique_ptr<const StringDictionaryTranslationMgr>&& str_dict_translation_mgr) {
206 std::unique_ptr<const TreeModelPredictionMgr>&& tree_model_prediction_mgr) {
212 std::unique_ptr<InValuesBitmap>& in_values_bitmap) {
213 if (in_values_bitmap->isEmpty()) {
214 return in_values_bitmap.get();
220 if (!in_values_bitmap->isEmpty()) {
227 const std::string& fname,
229 const std::vector<llvm::Value*>
args,
230 const std::vector<llvm::Attribute::AttrKind>& fnattrs = {},
231 const bool has_struct_return =
false);
232 llvm::Value*
emitCall(
const std::string& fname,
const std::vector<llvm::Value*>& args);
234 const std::vector<llvm::Value*>& args);
238 llvm::Value*
castToTypeIn(llvm::Value* val,
const size_t bit_width);
241 const size_t byte_width,
242 const bool is_signed);
249 llvm::ConstantInt*
llInt(
const T v)
const {
253 llvm::ConstantFP*
llFp(
const float v)
const {
254 return static_cast<llvm::ConstantFP*
>(
255 llvm::ConstantFP::get(llvm::Type::getFloatTy(
context_), v));
258 llvm::ConstantFP*
llFp(
const double v)
const {
259 return static_cast<llvm::ConstantFP*
>(
260 llvm::ConstantFP::get(llvm::Type::getDoubleTy(
context_), v));
274 bool always_clone =
false);
400 std::vector<std::unique_ptr<const StringDictionaryTranslationMgr>>
419 switch (lit.which()) {
449 static size_t addAligned(
const size_t off_in,
const size_t alignment) {
451 if (off % alignment != 0) {
452 off += (alignment - off % alignment);
454 return off + alignment;
464 size_t literal_found_off{0};
466 for (
const auto& literal : literals) {
468 literal_found_off =
addAligned(literal_found_off, lit_bytes);
469 if (literal == var_val) {
470 return {literal_found_off - lit_bytes, lit_bytes};
473 literals.emplace_back(val);
std::vector< llvm::Function * > helper_functions_
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
llvm::Value * castToTypeIn(llvm::Value *val, const size_t bit_width)
llvm::Value * emitEntryCall(const std::string &fname, const std::vector< llvm::Value * > &args)
std::vector< llvm::Value * > outer_join_match_found_per_level_
std::unordered_map< size_t, std::vector< llvm::Value * > > fetch_cache_
llvm::LLVMContext & getExecutorContext() const
std::shared_ptr< Executor > getExecutor() const
std::map< std::pair< llvm::Value *, llvm::Value * >, ArrayLoadCodegen > array_load_cache_
const Analyzer::FunctionOper * foper
llvm::Value * addStringConstant(const std::string &str)
void maybeCloneFunctionRecursive(llvm::Function *fn)
llvm::Function * query_func_
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
std::unordered_map< llvm::Value *, HoistedLiteralLoadLocator > row_func_hoisted_literals_
llvm::IRBuilder ir_builder_
int offset_in_literal_buffer
void moveInValuesBitmap(std::unique_ptr< const InValuesBitmap > &in_values_bitmap)
std::vector< llvm::Value * > str_constants_
llvm::ConstantInt * llBool(const bool v) const
std::unordered_map< int, std::vector< llvm::Value * > > query_func_literal_loads_
InsertionOrderedMap filter_func_args_
const bool contains_left_deep_outer_join_
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
const std::unordered_map< int, LiteralValues > & getLiterals() const
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
llvm::ConstantFP * llFp(const double v) const
static size_t literalBytes(const CgenState::LiteralValue &lit)
std::vector< FunctionOperValue > ext_call_cache_
llvm::Function * row_func_
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
std::vector< llvm::Value * > group_by_expr_cache_
llvm::LLVMContext & context_
llvm::Function * current_func_
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)
const TreeModelPredictionMgr * moveTreeModelPredictionMgr(std::unique_ptr< const TreeModelPredictionMgr > &&tree_model_prediction_mgr)
static size_t addAligned(const size_t off_in, const size_t alignment)
llvm::CallInst * filter_func_call_
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
std::vector< LiteralValue > LiteralValues
const InValuesBitmap * addInValuesBitmap(std::unique_ptr< InValuesBitmap > &in_values_bitmap)
void replaceFunctionForGpu(const std::string &fcn_to_replace, llvm::Function *fn)
std::unordered_map< int, size_t > literal_bytes_
std::unordered_map< int, llvm::Value * > scan_idx_to_hash_pos_
llvm::ConstantFP * llFp(const float v) const
std::vector< std::string > gpuFunctionsToReplace(llvm::Function *fn)
llvm::IRBuilder query_func_entry_ir_builder_
llvm::BasicBlock * filter_func_bb_
const SQLTypeInfo & get_type_info() const
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value * > &args)
SQLTypes decimal_to_int_type(const SQLTypeInfo &ti)
llvm::Constant * inlineNull(const SQLTypeInfo &)
void set_module_shallow_copy(const std::unique_ptr< llvm::Module > &module, bool always_clone=false)
std::vector< std::unique_ptr< const InValuesBitmap > > in_values_bitmaps_
llvm::Function * filter_func_
std::unordered_map< int, LiteralValues > literals_
std::vector< llvm::Value * > frag_offsets_
size_t getLiteralBufferUsage(const int device_id)
Datum get_constval() const
void emitErrorCheck(llvm::Value *condition, llvm::Value *errorCode, std::string label)
std::vector< std::unique_ptr< const TreeModelPredictionMgr > > tree_model_prediction_mgrs_
llvm::ConstantInt * llInt(const T v) const
int index_of_literal_load
llvm::ValueToValueMapTy vmap_
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
llvm::ConstantInt * ll_bool(const bool v, llvm::LLVMContext &context)
const StringDictionaryTranslationMgr * moveStringDictionaryTranslationMgr(std::unique_ptr< const StringDictionaryTranslationMgr > &&str_dict_translation_mgr)
std::vector< std::unique_ptr< const StringDictionaryTranslationMgr > > str_dict_translation_mgrs_
std::tuple< size_t, size_t > getOrAddLiteral(const T &val, const int device_id)
llvm::CallInst * row_func_call_
CgenState(const size_t num_query_infos, const bool contains_left_deep_outer_join, Executor *executor)
std::pair< llvm::ConstantInt *, llvm::ConstantInt * > inlineIntMaxMin(const size_t byte_width, const bool is_signed)
llvm::BasicBlock * row_func_bb_
std::tuple< size_t, size_t > getOrAddLiteral(const Analyzer::Constant *constant, const EncodingType enc_type, const shared::StringDictKey &dict_id, const int device_id)
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)