23 namespace spatial_type {
29 :
Codegen(geo_operator, catalog) {
35 size_t size() const final {
return 1; }
40 const std::vector<llvm::Value*>& arg_lvs,
41 const std::vector<llvm::Value*>& pos_lvs,
46 const auto& operand_ti = operand->get_type_info();
48 std::string size_fn_name =
"array_size";
50 size_fn_name +=
"_nullable";
53 const uint32_t coords_elem_sz_bytes =
56 std::vector<llvm::Value*> operand_lvs;
58 if (dynamic_cast<const Analyzer::ColumnVar*>(operand)) {
59 for (
size_t i = 0; i < arg_lvs.size(); i++) {
61 operand_lvs.push_back(
62 cgen_state->emitExternalCall(
"array_buff",
63 llvm::Type::getInt8PtrTy(cgen_state->context_),
64 {lv, pos_lvs.front()}));
65 const auto ptr_type = llvm::dyn_cast_or_null<llvm::PointerType>(lv->getType());
67 const auto elem_type = ptr_type->getElementType();
69 std::vector<llvm::Value*> array_sz_args{
72 cgen_state->llInt(
log2_bytes(i == 0 ? coords_elem_sz_bytes : 4))};
74 array_sz_args.push_back(
75 cgen_state->llInt(static_cast<int32_t>(inline_int_null_value<int32_t>())));
77 operand_lvs.push_back(cgen_state->emitExternalCall(
78 size_fn_name,
get_int_type(32, cgen_state->context_), array_sz_args));
81 operand_lvs = arg_lvs;
84 size_t(2 * operand_ti.get_physical_coord_cols()));
87 return std::make_tuple(operand_lvs,
is_nullable_ ? operand_lvs[1] :
nullptr);
90 std::vector<llvm::Value*>
codegen(
const std::vector<llvm::Value*>&
args,
94 auto operand_lvs =
args;
96 const auto& operand_ti = getOperand(0)->get_type_info();
98 const bool is_geodesic =
99 operand_ti.get_subtype() ==
kGEOGRAPHY && operand_ti.get_output_srid() == 4326;
101 std::string func_name = getName() +
suffix(operand_ti.get_type());
102 if (is_geodesic && getName() ==
"ST_Perimeter") {
103 func_name +=
"_Geodesic";
107 operand_lvs.push_back(
109 operand_lvs.push_back(cgen_state->llInt(operand_ti.get_input_srid()));
110 auto output_srid = operand_ti.get_output_srid();
111 if (
const auto srid_override = operator_->getOutputSridOverride()) {
112 output_srid = *srid_override;
114 operand_lvs.push_back(cgen_state->llInt(output_srid));
116 const auto& ret_ti = operator_->get_type_info();
119 auto ret = cgen_state->emitExternalCall(
121 ret_ti.get_type() ==
kDOUBLE ? llvm::Type::getDoubleTy(cgen_state->context_)
122 : llvm::Type::getFloatTy(cgen_state->context_),
125 CHECK(nullcheck_codegen);
126 ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(ret_ti), ret);
class for a per-database catalog. also includes metadata for the current database and the current use...
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
AreaPerimeter(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)