OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoIR.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "Geospatial/Compression.h"
19 #include "QueryEngine/Execute.h"
22 
24  llvm::Value* pos,
25  const SQLTypeInfo& ti,
26  CgenState* cgen_state) {
27  CHECK(byte_stream);
28 
29  const auto key = std::make_pair(byte_stream, pos);
30  auto cache_itr = cgen_state->array_load_cache_.find(key);
31  if (cache_itr != cgen_state->array_load_cache_.end()) {
32  return cache_itr->second;
33  }
34  const bool is_nullable = !ti.get_notnull();
35  CHECK(ti.get_type() == kPOINT); // TODO: lift this
36 
37  auto pt_arr_buf =
38  cgen_state->emitExternalCall("array_buff",
39  llvm::Type::getInt8PtrTy(cgen_state->context_),
40  {key.first, key.second});
41  llvm::Value* pt_is_null{nullptr};
42  if (is_nullable) {
43  pt_is_null = cgen_state->emitExternalCall("point_coord_array_is_null",
44  llvm::Type::getInt1Ty(cgen_state->context_),
45  {key.first, key.second});
46  }
47  ArrayLoadCodegen arr_load{pt_arr_buf, nullptr, pt_is_null};
48  cgen_state->array_load_cache_.insert(std::make_pair(key, arr_load));
49  return arr_load;
50 }
51 
52 std::vector<llvm::Value*> CodeGenerator::codegenGeoColumnVar(
53  const Analyzer::GeoColumnVar* geo_col_var,
54  const bool fetch_columns,
55  const CompilationOptions& co) {
56  const auto catalog = executor()->getCatalog();
57  CHECK(catalog);
58 
59  auto generate_column_lvs = [this, catalog, geo_col_var, &co](const int column_id) {
60  auto cd = get_column_descriptor(column_id, geo_col_var->get_table_id(), *catalog);
61  CHECK(cd);
62 
63  const auto col_var = Analyzer::ColumnVar(cd->columnType,
64  geo_col_var->get_table_id(),
65  column_id,
66  geo_col_var->get_rte_idx());
67  const auto lv_vec = codegen(&col_var, /*fetch_columns=*/true, co);
68  CHECK_EQ(lv_vec.size(), size_t(1)); // ptr
69  return lv_vec;
70  };
71 
72  const auto& ti = geo_col_var->get_type_info();
73  switch (ti.get_type()) {
74  case kPOINT:
75  case kLINESTRING:
76  case kPOLYGON:
77  case kMULTIPOLYGON: {
78  std::vector<llvm::Value*> geo_lvs;
79  // iterate over physical columns
80  for (int i = 0; i < ti.get_physical_coord_cols(); i++) {
81  const auto column_id = geo_col_var->get_column_id() + 1 + i;
82  const auto lvs = generate_column_lvs(column_id);
83  CHECK_EQ(lvs.size(), size_t(1)); // expecting ptr for each column
84  geo_lvs.insert(geo_lvs.end(), lvs.begin(), lvs.end());
85  }
86 
87  return geo_lvs;
88  }
89  default:
90  UNREACHABLE() << geo_col_var->toString();
91  }
92  UNREACHABLE();
93  return {};
94 }
95 
96 std::vector<llvm::Value*> CodeGenerator::codegenGeoExpr(const Analyzer::GeoExpr* expr,
97  const CompilationOptions& co) {
98  auto geo_constant = dynamic_cast<const Analyzer::GeoConstant*>(expr);
99  if (geo_constant) {
100  return codegenGeoConstant(geo_constant, co);
101  }
102  auto geo_operator = dynamic_cast<const Analyzer::GeoOperator*>(expr);
103  if (geo_operator) {
104  return codegenGeoOperator(geo_operator, co);
105  }
106  UNREACHABLE() << expr->toString();
107  return {};
108 }
109 
110 std::vector<llvm::Value*> CodeGenerator::codegenGeoConstant(
111  const Analyzer::GeoConstant* geo_constant,
112  const CompilationOptions& co) {
114 
115  std::vector<llvm::Value*> ret;
116  for (size_t i = 0; i < geo_constant->physicalCols(); i++) {
117  auto physical_constant = geo_constant->makePhysicalConstant(i);
118  auto operand_lvs = codegen(physical_constant.get(), /*fetch_columns=*/true, co);
119  CHECK_EQ(operand_lvs.size(), size_t(2));
120  auto array_buff_lv = operand_lvs[0];
121  if (i > 0) {
122  array_buff_lv = cgen_state_->ir_builder_.CreateBitCast(
123  operand_lvs[0], llvm::Type::getInt8PtrTy(cgen_state_->context_));
124  }
125  ret.push_back(array_buff_lv);
126  ret.push_back(operand_lvs[1]);
127  }
128  return ret;
129 }
130 
131 std::vector<llvm::Value*> CodeGenerator::codegenGeoOperator(
132  const Analyzer::GeoOperator* geo_operator,
133  const CompilationOptions& co) {
135 
136  if (geo_operator->getName() == "ST_X" || geo_operator->getName() == "ST_Y") {
137  const auto key = geo_operator->toString();
138  auto geo_target_cache_it = cgen_state_->geo_target_cache_.find(key);
139  if (geo_target_cache_it != cgen_state_->geo_target_cache_.end()) {
140  return {geo_target_cache_it->second};
141  }
142  }
143 
144  const auto catalog = executor()->getCatalog();
145  CHECK(catalog);
146 
147  auto op_codegen = spatial_type::Codegen::init(geo_operator, catalog);
148  CHECK(op_codegen);
149 
150  std::vector<llvm::Value*> load_lvs;
151  std::vector<llvm::Value*> pos_lvs;
152  for (size_t i = 0; i < op_codegen->size(); i++) {
153  auto intermediate_lvs =
154  codegen(op_codegen->getOperand(i), /*fetch_columns=*/true, co);
155  load_lvs.insert(load_lvs.end(), intermediate_lvs.begin(), intermediate_lvs.end());
156  pos_lvs.push_back(posArg(op_codegen->getOperand(i)));
157  }
158 
159  auto [arg_lvs, null_lv] = op_codegen->codegenLoads(load_lvs, pos_lvs, cgen_state_);
160 
161  std::unique_ptr<CodeGenerator::NullCheckCodegen> nullcheck_codegen =
162  op_codegen->getNullCheckCodegen(null_lv, cgen_state_, executor());
163  return op_codegen->codegen(arg_lvs, nullcheck_codegen.get(), cgen_state_, co);
164 }
165 
166 std::vector<llvm::Value*> CodeGenerator::codegenGeoUOper(
167  const Analyzer::GeoUOper* geo_expr,
168  const CompilationOptions& co) {
171  if (geo_expr->getOp() != Geospatial::GeoBase::GeoOp::kPROJECTION) {
172  throw QueryMustRunOnCpu();
173  }
174  }
175 
176  auto argument_list = codegenGeoArgs(geo_expr->getArgs0(), co);
177 
178  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kPROJECTION) {
179  return argument_list;
180  }
181 
182 #ifndef ENABLE_GEOS
183  throw std::runtime_error("Geo operation requires GEOS support.");
184 #endif
185 
186  // Basic set of arguments is currently common to all Geos_* func invocations:
187  // op kind, type of the first geo arg0, geo arg0 components
188  std::string func = "Geos_Wkb"s;
189 
190  if (geo_expr->getTypeInfo0().transforms() || geo_expr->get_type_info().transforms()) {
191  // If there is a transform on the argument and/or on the result of the operation,
192  // verify that the argument's output srid is equal to result's input srid
193  if (geo_expr->getTypeInfo0().get_output_srid() !=
194  geo_expr->get_type_info().get_input_srid()) {
195  throw std::runtime_error("GEOS runtime: input/output srids have to match.");
196  }
197  }
198  // Prepend arg0 geo SQLType
199  argument_list.insert(
200  argument_list.begin(),
201  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_type())));
202  // Prepend geo expr op
203  argument_list.insert(argument_list.begin(),
204  cgen_state_->llInt(static_cast<int>(geo_expr->getOp())));
205  for (auto i = 3; i > geo_expr->getTypeInfo0().get_physical_coord_cols(); i--) {
206  argument_list.insert(argument_list.end(), cgen_state_->llInt(int64_t(0)));
207  argument_list.insert(argument_list.end(),
208  llvm::ConstantPointerNull::get(
209  llvm::Type::getInt32PtrTy(cgen_state_->context_, 0)));
210  }
211  // Append geo expr compression
212  argument_list.insert(
213  argument_list.end(),
214  cgen_state_->llInt(static_cast<int>(
216  // Append geo expr input srid
217  argument_list.insert(
218  argument_list.end(),
219  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_input_srid())));
220  // Append geo expr output srid
221  argument_list.insert(
222  argument_list.end(),
223  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_output_srid())));
224 
225  // Deal with unary geo predicates
226  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kISEMPTY ||
228  return codegenGeosPredicateCall(func, argument_list, co);
229  }
230 
231  throw std::runtime_error("Unsupported unary geo operation.");
232  return {};
233 }
234 
235 std::vector<llvm::Value*> CodeGenerator::codegenGeoBinOper(
236  Analyzer::GeoBinOper const* geo_expr,
237  CompilationOptions const& co) {
240  throw QueryMustRunOnCpu();
241  }
242 #ifndef ENABLE_GEOS
243  throw std::runtime_error("Geo operation requires GEOS support.");
244 #endif
245 
246  auto argument_list = codegenGeoArgs(geo_expr->getArgs0(), co);
247 
248  // Basic set of arguments is currently common to all Geos_* func invocations:
249  // op kind, type of the first geo arg0, geo arg0 components
250  std::string func = "Geos_Wkb"s;
251  if (geo_expr->getTypeInfo0().transforms() || geo_expr->get_type_info().transforms()) {
252  // If there is a transform on the argument and/or on the result of the operation,
253  // verify that the argument's output srid is equal to result's input srid
254  if (geo_expr->getTypeInfo0().get_output_srid() !=
255  geo_expr->get_type_info().get_input_srid()) {
256  throw std::runtime_error("GEOS runtime: input/output srids have to match.");
257  }
258  }
259  // Prepend arg0 geo SQLType
260  argument_list.insert(
261  argument_list.begin(),
262  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_type())));
263  // Prepend geo expr op
264  argument_list.insert(argument_list.begin(),
265  cgen_state_->llInt(static_cast<int>(geo_expr->getOp())));
266  for (auto i = 3; i > geo_expr->getTypeInfo0().get_physical_coord_cols(); i--) {
267  argument_list.insert(argument_list.end(), cgen_state_->llInt(int64_t(0)));
268  argument_list.insert(argument_list.end(),
269  llvm::ConstantPointerNull::get(
270  llvm::Type::getInt32PtrTy(cgen_state_->context_, 0)));
271  }
272  // Append geo expr compression
273  argument_list.insert(
274  argument_list.end(),
275  cgen_state_->llInt(static_cast<int>(
277  // Append geo expr input srid
278  argument_list.insert(
279  argument_list.end(),
280  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_input_srid())));
281  // Append geo expr output srid
282  argument_list.insert(
283  argument_list.end(),
284  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_output_srid())));
285 
286  auto arg1_list = codegenGeoArgs(geo_expr->getArgs1(), co);
287 
288  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kDIFFERENCE ||
290  geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kUNION ||
292  func += "_Wkb"s;
293  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kEQUALS) {
294  func += "_Predicate"s;
295  }
296  // Prepend arg1 geo SQLType
297  arg1_list.insert(
298  arg1_list.begin(),
299  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo1().get_type())));
300  for (auto i = 3; i > geo_expr->getTypeInfo1().get_physical_coord_cols(); i--) {
301  arg1_list.insert(arg1_list.end(), cgen_state_->llInt(int64_t(0)));
302  arg1_list.insert(arg1_list.end(),
303  llvm::ConstantPointerNull::get(
304  llvm::Type::getInt32PtrTy(cgen_state_->context_, 0)));
305  }
306  // Append geo expr compression
307  arg1_list.insert(arg1_list.end(),
308  cgen_state_->llInt(static_cast<int>(
310  // Append geo expr input srid
311  arg1_list.insert(arg1_list.end(),
312  cgen_state_->llInt(geo_expr->getTypeInfo1().get_input_srid()));
313  // Append geo expr output srid
314  arg1_list.insert(arg1_list.end(),
316  } else if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kBUFFER) {
317  // Extra argument in this case is double
318  func += "_double"s;
319  } else {
320  throw std::runtime_error("Unsupported binary geo operation.");
321  }
322 
323  // Append arg1 to the list
324  argument_list.insert(argument_list.end(), arg1_list.begin(), arg1_list.end());
325 
326  // Deal with unary geo predicates
327  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kEQUALS) {
328  return codegenGeosPredicateCall(func, argument_list, co);
329  }
330 
331  auto result_srid = cgen_state_->llInt(geo_expr->get_type_info().get_output_srid());
332 
333  return codegenGeosConstructorCall(func, argument_list, result_srid, co);
334 }
335 
336 std::vector<llvm::Value*> CodeGenerator::codegenGeoArgs(
337  const std::vector<std::shared_ptr<Analyzer::Expr>>& geo_args,
338  const CompilationOptions& co) {
340  std::vector<llvm::Value*> argument_list;
341  bool coord_col = true;
342  for (const auto& geo_arg : geo_args) {
343  const auto arg = geo_arg.get();
344  const auto& arg_ti = arg->get_type_info();
345  const auto elem_ti = arg_ti.get_elem_type();
346  const auto arg_lvs = codegen(arg, true, co);
347  if (arg_ti.is_number()) {
348  argument_list.emplace_back(arg_lvs.front());
349  continue;
350  }
351  if (arg_ti.is_geometry()) {
352  argument_list.insert(argument_list.end(), arg_lvs.begin(), arg_lvs.end());
353  continue;
354  }
355  CHECK(arg_ti.is_array());
356  if (arg_lvs.size() > 1) {
357  CHECK_EQ(size_t(2), arg_lvs.size());
358  auto ptr_lv = arg_lvs.front();
359  if (coord_col) {
360  coord_col = false;
361  } else {
362  ptr_lv = cgen_state_->ir_builder_.CreatePointerCast(
363  ptr_lv, llvm::Type::getInt32PtrTy(cgen_state_->context_));
364  }
365  argument_list.emplace_back(ptr_lv);
366  auto cast_len_lv = cgen_state_->ir_builder_.CreateZExt(
367  arg_lvs.back(), get_int_type(64, cgen_state_->context_));
368  argument_list.emplace_back(cast_len_lv);
369  } else {
370  CHECK_EQ(size_t(1), arg_lvs.size());
371  if (arg_ti.get_size() > 0) {
372  // Set up the pointer lv for a dynamically generated point
373  auto ptr_lv = arg_lvs.front();
374  auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(arg);
375  // Override for point coord column access
376  if (col_var) {
377  ptr_lv = cgen_state_->emitExternalCall(
378  "fast_fixlen_array_buff",
379  llvm::Type::getInt8PtrTy(cgen_state_->context_),
380  {arg_lvs.front(), posArg(arg)});
381  }
382  if (coord_col) {
383  coord_col = false;
384  } else {
385  ptr_lv = cgen_state_->ir_builder_.CreatePointerCast(
386  ptr_lv, llvm::Type::getInt32PtrTy(cgen_state_->context_));
387  }
388  argument_list.emplace_back(ptr_lv);
389  argument_list.emplace_back(cgen_state_->llInt<int64_t>(arg_ti.get_size()));
390  } else {
391  auto ptr_lv =
392  cgen_state_->emitExternalCall("array_buff",
393  llvm::Type::getInt8PtrTy(cgen_state_->context_),
394  {arg_lvs.front(), posArg(arg)});
395  if (coord_col) {
396  coord_col = false;
397  } else {
398  ptr_lv = cgen_state_->ir_builder_.CreatePointerCast(
399  ptr_lv, llvm::Type::getInt32PtrTy(cgen_state_->context_));
400  }
401  argument_list.emplace_back(ptr_lv);
402  const auto len_lv = cgen_state_->emitExternalCall(
403  "array_size",
405  {arg_lvs.front(),
406  posArg(arg),
407  cgen_state_->llInt(log2_bytes(elem_ti.get_logical_size()))});
408  auto cast_len_lv = cgen_state_->ir_builder_.CreateZExt(
409  len_lv, get_int_type(64, cgen_state_->context_));
410  argument_list.emplace_back(cast_len_lv);
411  }
412  }
413  }
414  return argument_list;
415 }
416 
417 std::vector<llvm::Value*> CodeGenerator::codegenGeosPredicateCall(
418  const std::string& func,
419  std::vector<llvm::Value*> argument_list,
420  const CompilationOptions& co) {
422  auto i8_type = get_int_type(8, cgen_state_->context_);
423  auto result = cgen_state_->ir_builder_.CreateAlloca(i8_type, nullptr, "result");
424  argument_list.emplace_back(result);
425 
426  // Generate call to GEOS wrapper
427  cgen_state_->needs_geos_ = true;
428  auto status_lv = cgen_state_->emitExternalCall(
429  func, llvm::Type::getInt1Ty(cgen_state_->context_), argument_list);
430  // Need to check the status and throw an error if this call has failed.
431  llvm::BasicBlock* geos_pred_ok_bb{nullptr};
432  llvm::BasicBlock* geos_pred_fail_bb{nullptr};
433  geos_pred_ok_bb = llvm::BasicBlock::Create(
434  cgen_state_->context_, "geos_pred_ok_bb", cgen_state_->current_func_);
435  geos_pred_fail_bb = llvm::BasicBlock::Create(
436  cgen_state_->context_, "geos_pred_fail_bb", cgen_state_->current_func_);
437  if (!status_lv) {
438  status_lv = cgen_state_->llBool(false);
439  }
440  cgen_state_->ir_builder_.CreateCondBr(status_lv, geos_pred_ok_bb, geos_pred_fail_bb);
441  cgen_state_->ir_builder_.SetInsertPoint(geos_pred_fail_bb);
444  cgen_state_->ir_builder_.SetInsertPoint(geos_pred_ok_bb);
445  auto res = cgen_state_->ir_builder_.CreateLoad(
446  result->getType()->getPointerElementType(), result);
447  return {res};
448 }
449 
451  const std::string& func,
452  std::vector<llvm::Value*> argument_list,
453  llvm::Value* result_srid,
454  const CompilationOptions& co) {
456  // Create output buffer pointers, append pointers to output args to
457  auto i8_type = get_int_type(8, cgen_state_->context_);
458  auto i32_type = get_int_type(32, cgen_state_->context_);
459  auto i64_type = get_int_type(64, cgen_state_->context_);
460  auto pi8_type = llvm::PointerType::get(i8_type, 0);
461  auto pi32_type = llvm::PointerType::get(i32_type, 0);
462 
463  auto result_type =
464  cgen_state_->ir_builder_.CreateAlloca(i32_type, nullptr, "result_type");
465  auto result_coords =
466  cgen_state_->ir_builder_.CreateAlloca(pi8_type, nullptr, "result_coords");
467  auto result_coords_size =
468  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_coords_size");
469  auto result_ring_sizes =
470  cgen_state_->ir_builder_.CreateAlloca(pi32_type, nullptr, "result_ring_sizes");
471  auto result_ring_sizes_size =
472  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_ring_sizes_size");
473  auto result_poly_rings =
474  cgen_state_->ir_builder_.CreateAlloca(pi32_type, nullptr, "result_poly_rings");
475  auto result_poly_rings_size =
476  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_poly_rings_size");
477 
478  argument_list.emplace_back(result_type);
479  argument_list.emplace_back(result_coords);
480  argument_list.emplace_back(result_coords_size);
481  argument_list.emplace_back(result_ring_sizes);
482  argument_list.emplace_back(result_ring_sizes_size);
483  argument_list.emplace_back(result_poly_rings);
484  argument_list.emplace_back(result_poly_rings_size);
485  argument_list.emplace_back(result_srid);
486 
487  // Generate call to GEOS wrapper
488  cgen_state_->needs_geos_ = true;
489  auto status_lv = cgen_state_->emitExternalCall(
490  func, llvm::Type::getInt1Ty(cgen_state_->context_), argument_list);
491  // Need to check the status and throw an error if this call has failed.
492  llvm::BasicBlock* geos_ok_bb{nullptr};
493  llvm::BasicBlock* geos_fail_bb{nullptr};
494  geos_ok_bb = llvm::BasicBlock::Create(
495  cgen_state_->context_, "geos_ok_bb", cgen_state_->current_func_);
496  geos_fail_bb = llvm::BasicBlock::Create(
497  cgen_state_->context_, "geos_fail_bb", cgen_state_->current_func_);
498  if (!status_lv) {
499  status_lv = cgen_state_->llBool(false);
500  }
501  cgen_state_->ir_builder_.CreateCondBr(status_lv, geos_ok_bb, geos_fail_bb);
502  cgen_state_->ir_builder_.SetInsertPoint(geos_fail_bb);
505  cgen_state_->ir_builder_.SetInsertPoint(geos_ok_bb);
506 
507  // TODO: Currently forcing the output to MULTIPOLYGON, but need to handle
508  // other possible geometries that geos may return, e.g. a POINT, a LINESTRING
509  // Need to handle empty result, e.g. empty intersection.
510  // The type of result is returned in `result_type`
511 
512  // Load return values
513  auto buf1 = cgen_state_->ir_builder_.CreateLoad(
514  result_coords->getType()->getPointerElementType(), result_coords);
515  auto buf1s = cgen_state_->ir_builder_.CreateLoad(
516  result_coords_size->getType()->getPointerElementType(), result_coords_size);
517  auto buf2 = cgen_state_->ir_builder_.CreateLoad(
518  result_ring_sizes->getType()->getPointerElementType(), result_ring_sizes);
519  auto buf2s = cgen_state_->ir_builder_.CreateLoad(
520  result_ring_sizes_size->getType()->getPointerElementType(), result_ring_sizes_size);
521  auto buf3 = cgen_state_->ir_builder_.CreateLoad(
522  result_poly_rings->getType()->getPointerElementType(), result_poly_rings);
523  auto buf3s = cgen_state_->ir_builder_.CreateLoad(
524  result_poly_rings_size->getType()->getPointerElementType(), result_poly_rings_size);
525 
526  // generate register_buffer_with_executor_rsm() calls to register all output buffers
528  "register_buffer_with_executor_rsm",
529  llvm::Type::getVoidTy(cgen_state_->context_),
530  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
531  cgen_state_->ir_builder_.CreatePointerCast(buf1, pi8_type)});
532  cgen_state_->emitExternalCall(
533  "register_buffer_with_executor_rsm",
534  llvm::Type::getVoidTy(cgen_state_->context_),
535  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
536  cgen_state_->ir_builder_.CreatePointerCast(buf2, pi8_type)});
537  cgen_state_->emitExternalCall(
538  "register_buffer_with_executor_rsm",
539  llvm::Type::getVoidTy(cgen_state_->context_),
540  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
541  cgen_state_->ir_builder_.CreatePointerCast(buf3, pi8_type)});
542 
543  return {cgen_state_->ir_builder_.CreatePointerCast(buf1, pi8_type),
544  buf1s,
545  cgen_state_->ir_builder_.CreatePointerCast(buf2, pi32_type),
546  buf2s,
547  cgen_state_->ir_builder_.CreatePointerCast(buf3, pi32_type),
548  buf3s};
549 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:2433
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:2435
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:2404
CgenState * cgen_state_
std::map< std::pair< llvm::Value *, llvm::Value * >, ArrayLoadCodegen > array_load_cache_
Definition: CgenState.h:379
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)
Definition: CgenState.h:217
llvm::IRBuilder ir_builder_
Definition: CgenState.h:361
int32_t get_compression_scheme(const SQLTypeInfo &ti)
Definition: Compression.cpp:23
llvm::Value * posArg(const Analyzer::Expr *) const
Definition: ColumnIR.cpp:515
#define UNREACHABLE()
Definition: Logger.h:266
const SQLTypeInfo getTypeInfo1() const
Definition: Analyzer.h:2434
llvm::ConstantInt * llBool(const bool v) const
Definition: CgenState.h:310
bool needs_geos_
Definition: CgenState.h:382
static const int32_t ERR_GEOS
Definition: Execute.h:1352
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:329
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
std::vector< llvm::Value * > codegenGeoBinOper(const Analyzer::GeoBinOper *, const CompilationOptions &)
Definition: GeoIR.cpp:235
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
Definition: CgenState.h:380
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
Definition: GeoIR.cpp:96
llvm::LLVMContext & context_
Definition: CgenState.h:359
llvm::Function * current_func_
Definition: CgenState.h:353
std::vector< llvm::Value * > codegenGeoOperator(const Analyzer::GeoOperator *, const CompilationOptions &)
Definition: GeoIR.cpp:131
std::vector< llvm::Value * > codegenGeoUOper(const Analyzer::GeoUOper *, const CompilationOptions &)
Definition: GeoIR.cpp:166
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:2405
const std::string & getName() const
Definition: Analyzer.h:2649
bool needs_error_check_
Definition: CgenState.h:381
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::vector< llvm::Value * > codegenGeosConstructorCall(const std::string &, std::vector< llvm::Value * >, llvm::Value *, const CompilationOptions &)
Definition: GeoIR.cpp:450
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
ExecutorDeviceType device_type
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:30
virtual std::string toString() const =0
std::vector< llvm::Value * > codegenGeosPredicateCall(const std::string &, std::vector< llvm::Value * >, const CompilationOptions &)
Definition: GeoIR.cpp:417
static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)
Definition: GeoIR.cpp:23
std::vector< llvm::Value * > codegenGeoColumnVar(const Analyzer::GeoColumnVar *, const bool fetch_columns, const CompilationOptions &co)
Definition: GeoIR.cpp:52
HOST DEVICE int get_input_srid() const
Definition: sqltypes.h:333
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:296
std::vector< llvm::Value * > codegenGeoArgs(const std::vector< std::shared_ptr< Analyzer::Expr >> &, const CompilationOptions &)
Definition: GeoIR.cpp:336
#define CHECK(condition)
Definition: Logger.h:222
Geospatial::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:2403
std::vector< llvm::Value * > codegenGeoConstant(const Analyzer::GeoConstant *, const CompilationOptions &)
Definition: GeoIR.cpp:110
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:176
std::shared_ptr< Analyzer::Constant > makePhysicalConstant(const size_t index) const
Definition: Analyzer.cpp:3753
bool transforms() const
Definition: sqltypes.h:531
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:336
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.cpp:22
std::string toString() const override
Definition: Analyzer.cpp:3837
int get_physical_coord_cols() const
Definition: sqltypes.h:375
size_t physicalCols() const
Definition: Analyzer.cpp:3748
Geospatial::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:2432
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs1() const
Definition: Analyzer.h:2436
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:191
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:335
Executor * executor() const