OmniSciDB  471d68cefb
 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 2019 OmniSci, 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  if (geo_expr->getTypeInfo0().transforms()) {
190  throw std::runtime_error(
191  "GEOS runtime does not support transforms on geometry inputs.");
192  }
193  // Catch transforms applied to geometry construction only
194  if (geo_expr->get_type_info().transforms()) {
195  throw std::runtime_error(
196  "GEOS runtime does not support transforms on geometry outputs.");
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 SRID
217  argument_list.insert(
218  argument_list.end(),
219  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_output_srid())));
220 
221  // Deal with unary geo predicates
222  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kISEMPTY ||
224  return codegenGeosPredicateCall(func, argument_list, co);
225  }
226 
227  throw std::runtime_error("Unsupported unary geo operation.");
228  return {};
229 }
230 
231 std::vector<llvm::Value*> CodeGenerator::codegenGeoBinOper(
232  Analyzer::GeoBinOper const* geo_expr,
233  CompilationOptions const& co) {
236  throw QueryMustRunOnCpu();
237  }
238 #ifndef ENABLE_GEOS
239  throw std::runtime_error("Geo operation requires GEOS support.");
240 #endif
241 
242  auto argument_list = codegenGeoArgs(geo_expr->getArgs0(), co);
243 
244  // Basic set of arguments is currently common to all Geos_* func invocations:
245  // op kind, type of the first geo arg0, geo arg0 components
246  std::string func = "Geos_Wkb"s;
247  if (geo_expr->getTypeInfo0().transforms() || geo_expr->getTypeInfo1().transforms()) {
248  throw std::runtime_error(
249  "GEOS runtime does not support transforms on geometry inputs.");
250  }
251  if (geo_expr->get_type_info().transforms()) {
252  throw std::runtime_error(
253  "GEOS runtime does not support transforms on geometry outputs.");
254  }
255  // Prepend arg0 geo SQLType
256  argument_list.insert(
257  argument_list.begin(),
258  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_type())));
259  // Prepend geo expr op
260  argument_list.insert(argument_list.begin(),
261  cgen_state_->llInt(static_cast<int>(geo_expr->getOp())));
262  for (auto i = 3; i > geo_expr->getTypeInfo0().get_physical_coord_cols(); i--) {
263  argument_list.insert(argument_list.end(), cgen_state_->llInt(int64_t(0)));
264  argument_list.insert(argument_list.end(),
265  llvm::ConstantPointerNull::get(
266  llvm::Type::getInt32PtrTy(cgen_state_->context_, 0)));
267  }
268  // Append geo expr compression
269  argument_list.insert(
270  argument_list.end(),
271  cgen_state_->llInt(static_cast<int>(
273  // Append geo expr SRID
274  argument_list.insert(
275  argument_list.end(),
276  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo0().get_output_srid())));
277 
278  auto arg1_list = codegenGeoArgs(geo_expr->getArgs1(), co);
279 
280  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kDIFFERENCE ||
282  geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kUNION ||
284  func += "_Wkb"s;
285  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kEQUALS) {
286  func += "_Predicate"s;
287  }
288  // Prepend arg1 geo SQLType
289  arg1_list.insert(
290  arg1_list.begin(),
291  cgen_state_->llInt(static_cast<int>(geo_expr->getTypeInfo1().get_type())));
292  for (auto i = 3; i > geo_expr->getTypeInfo1().get_physical_coord_cols(); i--) {
293  arg1_list.insert(arg1_list.end(), cgen_state_->llInt(int64_t(0)));
294  arg1_list.insert(arg1_list.end(),
295  llvm::ConstantPointerNull::get(
296  llvm::Type::getInt32PtrTy(cgen_state_->context_, 0)));
297  }
298  // Append geo expr compression
299  arg1_list.insert(arg1_list.end(),
300  cgen_state_->llInt(static_cast<int>(
302  // Append geo expr compression
303  arg1_list.insert(arg1_list.end(),
305  } else if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kBUFFER) {
306  // Extra argument in this case is double
307  func += "_double"s;
308  } else {
309  throw std::runtime_error("Unsupported binary geo operation.");
310  }
311 
312  // Append arg1 to the list
313  argument_list.insert(argument_list.end(), arg1_list.begin(), arg1_list.end());
314 
315  // Deal with unary geo predicates
316  if (geo_expr->getOp() == Geospatial::GeoBase::GeoOp::kEQUALS) {
317  return codegenGeosPredicateCall(func, argument_list, co);
318  }
319 
320  return codegenGeosConstructorCall(func, argument_list, co);
321 }
322 
323 std::vector<llvm::Value*> CodeGenerator::codegenGeoArgs(
324  const std::vector<std::shared_ptr<Analyzer::Expr>>& geo_args,
325  const CompilationOptions& co) {
327  std::vector<llvm::Value*> argument_list;
328  bool coord_col = true;
329  for (const auto& geo_arg : geo_args) {
330  const auto arg = geo_arg.get();
331  const auto& arg_ti = arg->get_type_info();
332  const auto elem_ti = arg_ti.get_elem_type();
333  const auto arg_lvs = codegen(arg, true, co);
334  if (arg_ti.is_number()) {
335  argument_list.emplace_back(arg_lvs.front());
336  continue;
337  }
338  if (arg_ti.is_geometry()) {
339  argument_list.insert(argument_list.end(), arg_lvs.begin(), arg_lvs.end());
340  continue;
341  }
342  CHECK(arg_ti.is_array());
343  if (arg_lvs.size() > 1) {
344  CHECK_EQ(size_t(2), arg_lvs.size());
345  auto ptr_lv = arg_lvs.front();
346  if (coord_col) {
347  coord_col = false;
348  } else {
349  ptr_lv = cgen_state_->ir_builder_.CreatePointerCast(
350  ptr_lv, llvm::Type::getInt32PtrTy(cgen_state_->context_));
351  }
352  argument_list.emplace_back(ptr_lv);
353  auto cast_len_lv = cgen_state_->ir_builder_.CreateZExt(
354  arg_lvs.back(), get_int_type(64, cgen_state_->context_));
355  argument_list.emplace_back(cast_len_lv);
356  } else {
357  CHECK_EQ(size_t(1), arg_lvs.size());
358  if (arg_ti.get_size() > 0) {
359  // Set up the pointer lv for a dynamically generated point
360  auto ptr_lv = arg_lvs.front();
361  auto col_var = dynamic_cast<const Analyzer::ColumnVar*>(arg);
362  // Override for point coord column access
363  if (col_var) {
364  ptr_lv = cgen_state_->emitExternalCall(
365  "fast_fixlen_array_buff",
366  llvm::Type::getInt8PtrTy(cgen_state_->context_),
367  {arg_lvs.front(), posArg(arg)});
368  }
369  if (coord_col) {
370  coord_col = false;
371  } else {
372  ptr_lv = cgen_state_->ir_builder_.CreatePointerCast(
373  ptr_lv, llvm::Type::getInt32PtrTy(cgen_state_->context_));
374  }
375  argument_list.emplace_back(ptr_lv);
376  argument_list.emplace_back(cgen_state_->llInt<int64_t>(arg_ti.get_size()));
377  } else {
378  auto ptr_lv =
379  cgen_state_->emitExternalCall("array_buff",
380  llvm::Type::getInt8PtrTy(cgen_state_->context_),
381  {arg_lvs.front(), posArg(arg)});
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  const auto len_lv = cgen_state_->emitExternalCall(
390  "array_size",
392  {arg_lvs.front(),
393  posArg(arg),
394  cgen_state_->llInt(log2_bytes(elem_ti.get_logical_size()))});
395  auto cast_len_lv = cgen_state_->ir_builder_.CreateZExt(
396  len_lv, get_int_type(64, cgen_state_->context_));
397  argument_list.emplace_back(cast_len_lv);
398  }
399  }
400  }
401  return argument_list;
402 }
403 
404 std::vector<llvm::Value*> CodeGenerator::codegenGeosPredicateCall(
405  const std::string& func,
406  std::vector<llvm::Value*> argument_list,
407  const CompilationOptions& co) {
409  auto i8_type = get_int_type(8, cgen_state_->context_);
410  auto result = cgen_state_->ir_builder_.CreateAlloca(i8_type, nullptr, "result");
411  argument_list.emplace_back(result);
412 
413  // Generate call to GEOS wrapper
414  cgen_state_->needs_geos_ = true;
415  auto status_lv = cgen_state_->emitExternalCall(
416  func, llvm::Type::getInt1Ty(cgen_state_->context_), argument_list);
417  // Need to check the status and throw an error if this call has failed.
418  llvm::BasicBlock* geos_pred_ok_bb{nullptr};
419  llvm::BasicBlock* geos_pred_fail_bb{nullptr};
420  geos_pred_ok_bb = llvm::BasicBlock::Create(
421  cgen_state_->context_, "geos_pred_ok_bb", cgen_state_->current_func_);
422  geos_pred_fail_bb = llvm::BasicBlock::Create(
423  cgen_state_->context_, "geos_pred_fail_bb", cgen_state_->current_func_);
424  if (!status_lv) {
425  status_lv = cgen_state_->llBool(false);
426  }
427  cgen_state_->ir_builder_.CreateCondBr(status_lv, geos_pred_ok_bb, geos_pred_fail_bb);
428  cgen_state_->ir_builder_.SetInsertPoint(geos_pred_fail_bb);
431  cgen_state_->ir_builder_.SetInsertPoint(geos_pred_ok_bb);
432  auto res = cgen_state_->ir_builder_.CreateLoad(result);
433  return {res};
434 }
435 
437  const std::string& func,
438  std::vector<llvm::Value*> argument_list,
439  const CompilationOptions& co) {
441  // Create output buffer pointers, append pointers to output args to
442  auto i8_type = get_int_type(8, cgen_state_->context_);
443  auto i32_type = get_int_type(32, cgen_state_->context_);
444  auto i64_type = get_int_type(64, cgen_state_->context_);
445  auto pi8_type = llvm::PointerType::get(i8_type, 0);
446  auto pi32_type = llvm::PointerType::get(i32_type, 0);
447 
448  auto result_type =
449  cgen_state_->ir_builder_.CreateAlloca(i32_type, nullptr, "result_type");
450  auto result_coords =
451  cgen_state_->ir_builder_.CreateAlloca(pi8_type, nullptr, "result_coords");
452  auto result_coords_size =
453  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_coords_size");
454  auto result_ring_sizes =
455  cgen_state_->ir_builder_.CreateAlloca(pi32_type, nullptr, "result_ring_sizes");
456  auto result_ring_sizes_size =
457  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_ring_sizes_size");
458  auto result_poly_rings =
459  cgen_state_->ir_builder_.CreateAlloca(pi32_type, nullptr, "result_poly_rings");
460  auto result_poly_rings_size =
461  cgen_state_->ir_builder_.CreateAlloca(i64_type, nullptr, "result_poly_rings_size");
462 
463  argument_list.emplace_back(result_type);
464  argument_list.emplace_back(result_coords);
465  argument_list.emplace_back(result_coords_size);
466  argument_list.emplace_back(result_ring_sizes);
467  argument_list.emplace_back(result_ring_sizes_size);
468  argument_list.emplace_back(result_poly_rings);
469  argument_list.emplace_back(result_poly_rings_size);
470 
471  // Generate call to GEOS wrapper
472  cgen_state_->needs_geos_ = true;
473  auto status_lv = cgen_state_->emitExternalCall(
474  func, llvm::Type::getInt1Ty(cgen_state_->context_), argument_list);
475  // Need to check the status and throw an error if this call has failed.
476  llvm::BasicBlock* geos_ok_bb{nullptr};
477  llvm::BasicBlock* geos_fail_bb{nullptr};
478  geos_ok_bb = llvm::BasicBlock::Create(
479  cgen_state_->context_, "geos_ok_bb", cgen_state_->current_func_);
480  geos_fail_bb = llvm::BasicBlock::Create(
481  cgen_state_->context_, "geos_fail_bb", cgen_state_->current_func_);
482  if (!status_lv) {
483  status_lv = cgen_state_->llBool(false);
484  }
485  cgen_state_->ir_builder_.CreateCondBr(status_lv, geos_ok_bb, geos_fail_bb);
486  cgen_state_->ir_builder_.SetInsertPoint(geos_fail_bb);
489  cgen_state_->ir_builder_.SetInsertPoint(geos_ok_bb);
490 
491  // TODO: Currently forcing the output to MULTIPOLYGON, but need to handle
492  // other possible geometries that geos may return, e.g. a POINT, a LINESTRING
493  // Need to handle empty result, e.g. empty intersection.
494  // The type of result is returned in `result_type`
495 
496  // Load return values
497  auto buf1 = cgen_state_->ir_builder_.CreateLoad(result_coords);
498  auto buf1s = cgen_state_->ir_builder_.CreateLoad(result_coords_size);
499  auto buf2 = cgen_state_->ir_builder_.CreateLoad(result_ring_sizes);
500  auto buf2s = cgen_state_->ir_builder_.CreateLoad(result_ring_sizes_size);
501  auto buf3 = cgen_state_->ir_builder_.CreateLoad(result_poly_rings);
502  auto buf3s = cgen_state_->ir_builder_.CreateLoad(result_poly_rings_size);
503 
504  // generate register_buffer_with_executor_rsm() calls to register all output buffers
506  "register_buffer_with_executor_rsm",
507  llvm::Type::getVoidTy(cgen_state_->context_),
508  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
509  cgen_state_->ir_builder_.CreatePointerCast(buf1, pi8_type)});
510  cgen_state_->emitExternalCall(
511  "register_buffer_with_executor_rsm",
512  llvm::Type::getVoidTy(cgen_state_->context_),
513  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
514  cgen_state_->ir_builder_.CreatePointerCast(buf2, pi8_type)});
515  cgen_state_->emitExternalCall(
516  "register_buffer_with_executor_rsm",
517  llvm::Type::getVoidTy(cgen_state_->context_),
518  {cgen_state_->llInt(reinterpret_cast<int64_t>(executor())),
519  cgen_state_->ir_builder_.CreatePointerCast(buf3, pi8_type)});
520 
521  return {cgen_state_->ir_builder_.CreatePointerCast(buf1, pi8_type),
522  buf1s,
523  cgen_state_->ir_builder_.CreatePointerCast(buf2, pi32_type),
524  buf2s,
525  cgen_state_->ir_builder_.CreatePointerCast(buf3, pi32_type),
526  buf3s};
527 }
#define CHECK_EQ(x, y)
Definition: Logger.h:217
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:1716
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:1718
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:1687
CgenState * cgen_state_
std::map< std::pair< llvm::Value *, llvm::Value * >, ArrayLoadCodegen > array_load_cache_
Definition: CgenState.h:356
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:228
llvm::IRBuilder ir_builder_
Definition: CgenState.h:340
int32_t get_compression_scheme(const SQLTypeInfo &ti)
Definition: Compression.cpp:23
llvm::Value * posArg(const Analyzer::Expr *) const
Definition: ColumnIR.cpp:512
#define UNREACHABLE()
Definition: Logger.h:253
const SQLTypeInfo getTypeInfo1() const
Definition: Analyzer.h:1717
llvm::ConstantInt * llBool(const bool v) const
Definition: CgenState.h:321
bool needs_geos_
Definition: CgenState.h:359
static const int32_t ERR_GEOS
Definition: Execute.h:1169
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:231
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
Definition: CgenState.h:357
std::vector< llvm::Value * > codegenGeoExpr(const Analyzer::GeoExpr *, const CompilationOptions &)
Definition: GeoIR.cpp:96
llvm::LLVMContext & context_
Definition: CgenState.h:338
llvm::Function * current_func_
Definition: CgenState.h:332
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:1688
const std::string & getName() const
Definition: Analyzer.h:1925
std::vector< llvm::Value * > codegenGeosConstructorCall(const std::string &, std::vector< llvm::Value * >, const CompilationOptions &)
Definition: GeoIR.cpp:436
bool needs_error_check_
Definition: CgenState.h:358
#define AUTOMATIC_IR_METADATA(CGENSTATE)
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
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:404
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
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:307
std::vector< llvm::Value * > codegenGeoArgs(const std::vector< std::shared_ptr< Analyzer::Expr >> &, const CompilationOptions &)
Definition: GeoIR.cpp:323
#define CHECK(condition)
Definition: Logger.h:209
Geospatial::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:1686
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:174
std::shared_ptr< Analyzer::Constant > makePhysicalConstant(const size_t index) const
Definition: Analyzer.cpp:3532
bool transforms() const
Definition: sqltypes.h:530
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:3612
int get_physical_coord_cols() const
Definition: sqltypes.h:365
size_t physicalCols() const
Definition: Analyzer.cpp:3527
Geospatial::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:1715
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs1() const
Definition: Analyzer.h:1719
const ColumnDescriptor * get_column_descriptor(const int col_id, const int table_id, const Catalog_Namespace::Catalog &cat)
Definition: Execute.h:189
HOST DEVICE int get_output_srid() const
Definition: sqltypes.h:335
Executor * executor() const