29 const auto key = std::make_pair(byte_stream, pos);
32 return cache_itr->second;
39 llvm::Type::getInt8PtrTy(cgen_state->
context_),
40 {key.first, key.second});
41 llvm::Value* pt_is_null{
nullptr};
43 pt_is_null = cgen_state->emitExternalCall(
"point_coord_array_is_null",
44 llvm::Type::getInt1Ty(cgen_state->context_),
45 {key.first, key.second});
48 cgen_state->array_load_cache_.insert(std::make_pair(key, arr_load));
54 const bool fetch_columns,
56 auto generate_column_lvs = [
this, geo_col_var, &co](
const int column_id) {
65 const auto lv_vec =
codegen(&col_var,
true, co);
71 switch (ti.get_type()) {
77 std::vector<llvm::Value*> geo_lvs;
79 for (
int i = 0; i < ti.get_physical_coord_cols(); i++) {
81 const auto lvs = generate_column_lvs(column_id);
83 geo_lvs.insert(geo_lvs.end(), lvs.begin(), lvs.end());
114 std::vector<llvm::Value*> ret;
115 for (
size_t i = 0; i < geo_constant->
physicalCols(); i++) {
117 auto operand_lvs =
codegen(physical_constant.get(),
true, co);
118 CHECK_EQ(operand_lvs.size(), size_t(2));
119 auto array_buff_lv = operand_lvs[0];
124 ret.push_back(array_buff_lv);
125 ret.push_back(operand_lvs[1]);
135 if (geo_operator->
getName() ==
"ST_X" || geo_operator->
getName() ==
"ST_Y") {
136 const auto key = geo_operator->
toString();
139 return {geo_target_cache_it->second};
146 std::vector<llvm::Value*> load_lvs;
147 std::vector<llvm::Value*> pos_lvs;
148 for (
size_t i = 0; i < op_codegen->size(); i++) {
149 auto intermediate_lvs =
150 codegen(op_codegen->getOperand(i),
true, co);
151 load_lvs.insert(load_lvs.end(), intermediate_lvs.begin(), intermediate_lvs.end());
152 pos_lvs.push_back(
posArg(op_codegen->getOperand(i)));
155 auto [arg_lvs, null_lv] = op_codegen->codegenLoads(load_lvs, pos_lvs,
cgen_state_);
157 std::unique_ptr<CodeGenerator::NullCheckCodegen> nullcheck_codegen =
159 return op_codegen->codegen(arg_lvs, nullcheck_codegen.get(),
cgen_state_, co);
175 return argument_list;
179 throw std::runtime_error(
"Geo operation requires GEOS support.");
184 std::string func =
"Geos_Wkb"s;
191 throw std::runtime_error(
"GEOS runtime: input/output srids have to match.");
195 argument_list.insert(
196 argument_list.begin(),
199 argument_list.insert(argument_list.begin(),
202 argument_list.insert(argument_list.end(),
203 llvm::ConstantPointerNull::get(
208 argument_list.insert(
213 argument_list.insert(
217 argument_list.insert(
231 argument_list.insert(argument_list.end(),
cgen_state_->
llFp(
double(0)));
238 throw std::runtime_error(
"Unsupported unary geo operation.");
250 throw std::runtime_error(
"Geo operation requires GEOS support.");
257 std::string func =
"Geos_Wkb"s;
263 throw std::runtime_error(
"GEOS runtime: input/output srids have to match.");
267 argument_list.insert(
268 argument_list.begin(),
271 argument_list.insert(argument_list.begin(),
274 argument_list.insert(argument_list.end(),
275 llvm::ConstantPointerNull::get(
280 argument_list.insert(
285 argument_list.insert(
289 argument_list.insert(
301 func +=
"_Predicate"s;
308 arg1_list.insert(arg1_list.end(),
309 llvm::ConstantPointerNull::get(
314 arg1_list.insert(arg1_list.end(),
318 arg1_list.insert(arg1_list.end(),
321 arg1_list.insert(arg1_list.end(),
327 #if (GEOS_VERSION_MAJOR > 3) || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 11)
331 throw std::runtime_error(
"ST_ConcaveHull requires GEOS 3.11 or newer");
334 throw std::runtime_error(
"Unsupported binary geo operation.");
338 argument_list.insert(argument_list.end(), arg1_list.begin(), arg1_list.end());
351 const std::vector<std::shared_ptr<Analyzer::Expr>>& geo_args,
354 std::vector<llvm::Value*> argument_list;
355 bool coord_col =
true;
356 for (
const auto& geo_arg : geo_args) {
357 const auto arg = geo_arg.get();
358 const auto& arg_ti = arg->get_type_info();
359 const auto elem_ti = arg_ti.get_elem_type();
360 const auto arg_lvs =
codegen(arg,
true, co);
361 if (arg_ti.is_number()) {
362 argument_list.emplace_back(arg_lvs.front());
365 if (arg_ti.is_geometry()) {
366 argument_list.insert(argument_list.end(), arg_lvs.begin(), arg_lvs.end());
369 CHECK(arg_ti.is_array());
370 if (arg_lvs.size() > 1) {
371 CHECK_EQ(
size_t(2), arg_lvs.size());
372 auto ptr_lv = arg_lvs.front();
379 argument_list.emplace_back(ptr_lv);
382 argument_list.emplace_back(cast_len_lv);
384 CHECK_EQ(
size_t(1), arg_lvs.size());
385 if (arg_ti.get_size() > 0) {
387 auto ptr_lv = arg_lvs.front();
392 "fast_fixlen_array_buff",
394 {arg_lvs.front(),
posArg(arg)});
402 argument_list.emplace_back(ptr_lv);
408 {arg_lvs.front(),
posArg(arg)});
415 argument_list.emplace_back(ptr_lv);
424 argument_list.emplace_back(cast_len_lv);
428 return argument_list;
432 const std::string& func,
433 std::vector<llvm::Value*> argument_list,
438 argument_list.emplace_back(
result);
445 llvm::BasicBlock* geos_pred_ok_bb{
nullptr};
446 llvm::BasicBlock* geos_pred_fail_bb{
nullptr};
447 geos_pred_ok_bb = llvm::BasicBlock::Create(
449 geos_pred_fail_bb = llvm::BasicBlock::Create(
465 const std::string& func,
466 std::vector<llvm::Value*> argument_list,
467 llvm::Value* result_srid,
474 auto pi8_type = llvm::PointerType::get(i8_type, 0);
475 auto pi32_type = llvm::PointerType::get(i32_type, 0);
481 auto result_coords_size =
483 auto result_ring_sizes =
485 auto result_ring_sizes_size =
487 auto result_poly_rings =
489 auto result_poly_rings_size =
492 argument_list.emplace_back(result_type);
493 argument_list.emplace_back(result_coords);
494 argument_list.emplace_back(result_coords_size);
495 argument_list.emplace_back(result_ring_sizes);
496 argument_list.emplace_back(result_ring_sizes_size);
497 argument_list.emplace_back(result_poly_rings);
498 argument_list.emplace_back(result_poly_rings_size);
499 argument_list.emplace_back(result_srid);
506 llvm::BasicBlock* geos_ok_bb{
nullptr};
507 llvm::BasicBlock* geos_fail_bb{
nullptr};
508 geos_ok_bb = llvm::BasicBlock::Create(
510 geos_fail_bb = llvm::BasicBlock::Create(
528 result_coords->getType()->getPointerElementType(), result_coords);
530 result_coords_size->getType()->getPointerElementType(), result_coords_size);
532 result_ring_sizes->getType()->getPointerElementType(), result_ring_sizes);
534 result_ring_sizes_size->getType()->getPointerElementType(), result_ring_sizes_size);
536 result_poly_rings->getType()->getPointerElementType(), result_poly_rings);
538 result_poly_rings_size->getType()->getPointerElementType(), result_poly_rings_size);
542 "register_buffer_with_executor_rsm",
546 cgen_state_->emitExternalCall(
547 "register_buffer_with_executor_rsm",
548 llvm::Type::getVoidTy(cgen_state_->context_),
549 {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
550 cgen_state_->ir_builder_.CreatePointerCast(buf2, pi8_type)});
551 cgen_state_->emitExternalCall(
552 "register_buffer_with_executor_rsm",
553 llvm::Type::getVoidTy(cgen_state_->context_),
554 {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
555 cgen_state_->ir_builder_.CreatePointerCast(buf3, pi8_type)});
557 return {cgen_state_->ir_builder_.CreatePointerCast(buf1, pi8_type),
559 cgen_state_->ir_builder_.CreatePointerCast(buf2, pi32_type),
561 cgen_state_->ir_builder_.CreatePointerCast(buf3, pi32_type),
const SQLTypeInfo getTypeInfo0() const
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
const SQLTypeInfo getTypeInfo0() const
std::map< std::pair< llvm::Value *, llvm::Value * >, ArrayLoadCodegen > array_load_cache_
llvm::IRBuilder ir_builder_
int32_t get_compression_scheme(const SQLTypeInfo &ti)
llvm::Value * posArg(const Analyzer::Expr *) const
const SQLTypeInfo getTypeInfo1() const
llvm::ConstantInt * llBool(const bool v) const
static const int32_t ERR_GEOS
HOST DEVICE SQLTypes get_type() const
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::vector< llvm::Value * > codegenGeoBinOper(const Analyzer::GeoBinOper *, const CompilationOptions &)
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
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)
std::vector< llvm::Value * > codegenGeoOperator(const Analyzer::GeoOperator *, const CompilationOptions &)
std::vector< llvm::Value * > codegenGeoUOper(const Analyzer::GeoUOper *, const CompilationOptions &)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
std::string toString() const override
const ColumnDescriptor * get_column_descriptor(const shared::ColumnKey &column_key)
const std::string & getName() const
llvm::ConstantFP * llFp(const float v) const
std::vector< llvm::Value * > codegenGeosConstructorCall(const std::string &, std::vector< llvm::Value * >, llvm::Value *, const CompilationOptions &)
const SQLTypeInfo & get_type_info() const
ExecutorDeviceType device_type
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
virtual std::string toString() const =0
const shared::ColumnKey & getColumnKey() const
std::vector< llvm::Value * > codegenGeosPredicateCall(const std::string &, std::vector< llvm::Value * >, const CompilationOptions &)
static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)
std::vector< llvm::Value * > codegenGeoColumnVar(const Analyzer::GeoColumnVar *, const bool fetch_columns, const CompilationOptions &co)
HOST DEVICE int get_input_srid() const
llvm::ConstantInt * llInt(const T v) const
std::vector< llvm::Value * > codegenGeoArgs(const std::vector< std::shared_ptr< Analyzer::Expr >> &, const CompilationOptions &)
Geospatial::GeoBase::GeoOp getOp() const
std::vector< llvm::Value * > codegenGeoConstant(const Analyzer::GeoConstant *, const CompilationOptions &)
uint32_t log2_bytes(const uint32_t bytes)
std::shared_ptr< Analyzer::Constant > makePhysicalConstant(const size_t index) const
HOST DEVICE bool get_notnull() const
std::string toString() const override
int32_t get_rte_idx() const
int get_physical_coord_cols() const
size_t physicalCols() const
Geospatial::GeoBase::GeoOp getOp() const
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs1() const
HOST DEVICE int get_output_srid() const
Executor * executor() const