21 namespace spatial_type {
31 size_t size() const final {
return 1; }
37 const std::vector<llvm::Value*>& arg_lvs,
38 const std::vector<llvm::Value*>& pos_lvs,
42 if (arg_lvs.size() == size_t(1)) {
46 const auto& geo_ti = operand->get_type_info();
49 std::vector<llvm::Value*> array_operand_lvs;
50 array_operand_lvs.push_back(
51 cgen_state->emitExternalCall(
"array_buff",
52 llvm::Type::getInt8PtrTy(cgen_state->context_),
53 {arg_lvs.front(), pos_lvs.front()}));
54 const bool is_nullable = !geo_ti.get_notnull();
55 std::string size_fn_name =
"array_size";
57 size_fn_name +=
"_nullable";
60 std::vector<llvm::Value*> array_sz_args{
61 arg_lvs.front(), pos_lvs.front(), cgen_state->llInt(
log2_bytes(elem_sz))};
63 array_sz_args.push_back(
64 cgen_state->llInt(static_cast<int32_t>(inline_int_null_value<int32_t>())));
66 array_operand_lvs.push_back(cgen_state->emitExternalCall(
67 size_fn_name,
get_int_type(32, cgen_state->context_), array_sz_args));
68 return std::make_tuple(array_operand_lvs,
nullptr);
71 return std::make_tuple(arg_lvs,
nullptr);
74 std::vector<llvm::Value*>
codegen(
const std::vector<llvm::Value*>&
args,
79 const auto& geo_ti = getOperand(0)->get_type_info();
80 CHECK(geo_ti.is_geometry());
82 auto& builder = cgen_state->ir_builder_;
83 llvm::Value* array_buff_cast{
nullptr};
84 int32_t elem_size_bytes = 0;
86 array_buff_cast = builder.CreateBitCast(
87 args.front(), llvm::Type::getInt32PtrTy(cgen_state->context_));
90 array_buff_cast = builder.CreateBitCast(
91 args.front(), llvm::Type::getDoublePtrTy(cgen_state->context_));
95 const bool is_end_point = getName() ==
"ST_EndPoint";
96 const auto num_elements_lv =
97 builder.CreateSDiv(
args.back(), cgen_state->llInt(elem_size_bytes));
99 is_end_point ? builder.CreateSub(num_elements_lv, cgen_state->llInt(int32_t(2)))
100 : cgen_state->llInt(int32_t(0));
101 auto array_offset_lv = builder.CreateGEP(
102 array_buff_cast->getType()->getScalarType()->getPointerElementType(),
105 operator_->getName() +
"_Offset");
106 return {array_offset_lv,
args.back()};
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::vector< llvm::Value * > codegen(const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co) final
StartEndPoint(const Analyzer::GeoOperator *geo_operator)
std::tuple< std::vector< llvm::Value * >, llvm::Value * > codegenLoads(const std::vector< llvm::Value * > &arg_lvs, const std::vector< llvm::Value * > &pos_lvs, CgenState *cgen_state) final
size_t size() const final
const Analyzer::GeoOperator * operator_
virtual const Analyzer::Expr * getOperand(const size_t index)
uint32_t log2_bytes(const uint32_t bytes)
SQLTypeInfo getNullType() const final