32 CHECK(idx_ti.is_integer());
33 auto idx_lvs =
codegen(idx_expr,
true, co);
35 auto idx_lv = idx_lvs.front();
36 if (idx_ti.get_logical_size() < 8) {
41 const auto& array_ti = arr_expr->get_type_info();
42 CHECK(array_ti.is_array());
43 const auto& elem_ti = array_ti.get_elem_type();
44 const std::string array_at_fname{
46 ?
"array_at_" + std::string(elem_ti.get_type() ==
kDOUBLE ?
"double_checked"
48 :
"array_at_int" +
std::to_string(elem_ti.get_logical_size() * 8) +
52 ? (elem_ti.get_type() ==
kDOUBLE
56 const auto arr_lvs =
codegen(arr_expr,
true, co);
71 const auto arr_expr = expr->
get_arg();
73 CHECK(array_ti.is_array());
74 const auto& elem_ti = array_ti.get_elem_type();
75 auto arr_lv =
codegen(arr_expr,
true, co);
76 std::string fn_name(
"array_size");
78 if (
auto alloca = llvm::dyn_cast<llvm::AllocaInst>(arr_lv.front())) {
79 if (alloca->getAllocatedType()->isStructTy()) {
80 throw std::runtime_error(
"Unsupported type used in 'cardinality'");
84 std::vector<llvm::Value*> array_size_args{
88 const bool is_nullable{!arr_expr->get_type_info().get_notnull()};
90 fn_name +=
"_nullable";
101 using ValueVector = std::vector<llvm::Value*>;
102 ValueVector argument_list;
106 auto coord_compression = (return_type.get_compression() ==
kENCODING_GEOINT);
107 if (coord_compression) {
112 const auto arg_lvs =
codegen(arg,
true, co);
113 if (arg_lvs.size() == 1) {
114 if (coord_compression) {
117 auto c = ir_builder.CreateCast(llvm::Instruction::CastOps::FPToSI,
118 ir_builder.CreateFMul(arg_lvs.front(), mult),
120 argument_list.push_back(c);
122 argument_list.push_back(arg_lvs.front());
125 throw std::runtime_error(
126 "Unexpected argument count during array[] code generation.");
130 auto array_element_size_bytes =
131 return_type.get_elem_type().get_array_context_logical_size();
132 auto* array_index_type =
137 if (array_expr->
isNull()) {
138 return {llvm::ConstantPointerNull::get(
145 llvm::Value* dead_pointer = llvm::ConstantExpr::getIntToPtr(
150 llvm::Value* allocated_target_buffer;
152 allocated_target_buffer = ir_builder.CreateAlloca(array_type);
158 allocated_target_buffer =
164 "register_buffer_with_executor_rsm",
167 allocated_target_buffer});
169 llvm::Value* casted_allocated_target_buffer =
170 ir_builder.CreatePointerCast(allocated_target_buffer, array_type->getPointerTo());
172 for (
size_t i = 0; i < array_expr->getElementCount(); i++) {
173 auto* element = argument_list[i];
174 auto* element_ptr = ir_builder.CreateGEP(
176 casted_allocated_target_buffer,
179 const auto& elem_ti = return_type.get_elem_type();
180 if (elem_ti.is_boolean()) {
181 const auto byte_casted_bit =
182 ir_builder.CreateIntCast(element, array_index_type,
true);
183 ir_builder.CreateStore(byte_casted_bit, element_ptr);
184 }
else if (elem_ti.is_fp()) {
185 switch (elem_ti.get_size()) {
186 case sizeof(double): {
187 const auto double_element_ptr = ir_builder.CreatePointerCast(
189 ir_builder.CreateStore(element, double_element_ptr);
192 case sizeof(float): {
193 const auto float_element_ptr = ir_builder.CreatePointerCast(
195 ir_builder.CreateStore(element, float_element_ptr);
201 }
else if (elem_ti.is_integer() || elem_ti.is_decimal() || elem_ti.is_date() ||
202 elem_ti.is_timestamp() || elem_ti.is_time() || elem_ti.is_timeinterval() ||
203 elem_ti.is_dict_encoded_string()) {
205 const auto sign_extended_element = ir_builder.CreateSExt(element, array_index_type);
206 ir_builder.CreateStore(sign_extended_element, element_ptr);
208 throw std::runtime_error(
"Unsupported type used in ARRAY construction.");
212 return {ir_builder.CreateGEP(
const Expr * get_right_operand() const
llvm::IRBuilder ir_builder_
llvm::Value * posArg(const Analyzer::Expr *) const
llvm::Value * codegenArrayAt(const Analyzer::BinOper *, const CompilationOptions &)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
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::ConstantInt * inlineIntNull(const SQLTypeInfo &)
llvm::ConstantFP * llFp(const float v) const
std::vector< llvm::Value * > codegenArrayExpr(const Analyzer::ArrayExpr *, const CompilationOptions &)
const SQLTypeInfo & get_type_info() const
size_t getElementCount() const
ExecutorDeviceType device_type
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
bool isLocalAlloc() const
const Expr * get_operand() const
llvm::ConstantInt * llInt(const T v) const
llvm::Value * codegenUnnest(const Analyzer::UOper *, const CompilationOptions &)
const Expr * get_left_operand() const
uint32_t log2_bytes(const uint32_t bytes)
llvm::ArrayType * get_int_array_type(int const width, int count, llvm::LLVMContext &context)
const Expr * get_arg() const
const Analyzer::Expr * getElement(const size_t i) const
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Executor * executor() const