22 namespace spatial_type {
32 size_t size() const final {
return 1; }
37 const std::vector<llvm::Value*>& arg_lvs,
38 const std::vector<llvm::Value*>& pos_lvs,
43 const auto& operand_ti = operand->get_type_info();
45 std::string size_fn_name =
"array_size";
47 size_fn_name +=
"_nullable";
50 std::vector<llvm::Value*> operand_lvs;
52 if (dynamic_cast<const Analyzer::ColumnVar*>(operand)) {
53 for (
size_t i = 0; i < arg_lvs.size(); i++) {
55 operand_lvs.push_back(
56 cgen_state->emitExternalCall(
"array_buff",
57 llvm::Type::getInt8PtrTy(cgen_state->context_),
58 {lv, pos_lvs.front()}));
59 const auto ptr_type = llvm::dyn_cast_or_null<llvm::PointerType>(lv->getType());
61 const auto elem_type = ptr_type->getPointerElementType();
63 auto const is_coords = (i == 0);
64 auto const shift =
log2_bytes(is_coords ? 1 : 4);
65 std::vector<llvm::Value*> array_sz_args{
66 lv, pos_lvs.front(), cgen_state->llInt(shift)};
68 array_sz_args.push_back(
69 cgen_state->llInt(static_cast<int32_t>(inline_int_null_value<int32_t>())));
71 operand_lvs.push_back(cgen_state->emitExternalCall(
72 size_fn_name,
get_int_type(32, cgen_state->context_), array_sz_args));
75 operand_lvs = arg_lvs;
78 size_t(2 * operand_ti.get_physical_coord_cols()));
81 return std::make_tuple(operand_lvs,
is_nullable_ ? operand_lvs[1] :
nullptr);
84 std::vector<llvm::Value*>
codegen(
const std::vector<llvm::Value*>&
args,
88 auto operand_lvs =
args;
90 const auto& operand_ti = getOperand(0)->get_type_info();
92 const bool is_geodesic =
93 operand_ti.get_subtype() ==
kGEOGRAPHY && operand_ti.get_output_srid() == 4326;
95 std::string func_name = getName() +
suffix(operand_ti.get_type());
96 if (is_geodesic && getName() ==
"ST_Perimeter") {
97 func_name +=
"_Geodesic";
101 operand_lvs.push_back(
103 operand_lvs.push_back(cgen_state->llInt(operand_ti.get_input_srid()));
104 auto output_srid = operand_ti.get_output_srid();
105 if (
const auto srid_override = operator_->getOutputSridOverride()) {
106 output_srid = *srid_override;
108 operand_lvs.push_back(cgen_state->llInt(output_srid));
110 const auto& ret_ti = operator_->get_type_info();
113 auto ret = cgen_state->emitExternalCall(
115 ret_ti.get_type() ==
kDOUBLE ? llvm::Type::getDoubleTy(cgen_state->context_)
116 : llvm::Type::getFloatTy(cgen_state->context_),
119 CHECK(nullcheck_codegen);
120 ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(ret_ti), ret);
AreaPerimeter(const Analyzer::GeoOperator *geo_operator)
int32_t get_compression_scheme(const SQLTypeInfo &ti)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::string suffix(SQLTypes type)
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
std::vector< llvm::Value * > codegen(const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co) final
const SQLTypeInfo & get_type_info() const
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