OmniSciDB  dfae7c3b14
CompareIR.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 "CodeGenerator.h"
18 #include "Execute.h"
19 
20 #include <typeinfo>
21 
22 #include "../Parser/ParserNode.h"
23 
24 namespace {
25 
26 llvm::CmpInst::Predicate llvm_icmp_pred(const SQLOps op_type) {
27  switch (op_type) {
28  case kEQ:
29  return llvm::ICmpInst::ICMP_EQ;
30  case kNE:
31  return llvm::ICmpInst::ICMP_NE;
32  case kLT:
33  return llvm::ICmpInst::ICMP_SLT;
34  case kGT:
35  return llvm::ICmpInst::ICMP_SGT;
36  case kLE:
37  return llvm::ICmpInst::ICMP_SLE;
38  case kGE:
39  return llvm::ICmpInst::ICMP_SGE;
40  default:
41  abort();
42  }
43 }
44 
45 std::string icmp_name(const SQLOps op_type) {
46  switch (op_type) {
47  case kEQ:
48  return "eq";
49  case kNE:
50  return "ne";
51  case kLT:
52  return "lt";
53  case kGT:
54  return "gt";
55  case kLE:
56  return "le";
57  case kGE:
58  return "ge";
59  default:
60  abort();
61  }
62 }
63 
64 std::string icmp_arr_name(const SQLOps op_type) {
65  switch (op_type) {
66  case kEQ:
67  return "eq";
68  case kNE:
69  return "ne";
70  case kLT:
71  return "gt";
72  case kGT:
73  return "lt";
74  case kLE:
75  return "ge";
76  case kGE:
77  return "le";
78  default:
79  abort();
80  }
81 }
82 
83 llvm::CmpInst::Predicate llvm_fcmp_pred(const SQLOps op_type) {
84  switch (op_type) {
85  case kEQ:
86  return llvm::CmpInst::FCMP_OEQ;
87  case kNE:
88  return llvm::CmpInst::FCMP_ONE;
89  case kLT:
90  return llvm::CmpInst::FCMP_OLT;
91  case kGT:
92  return llvm::CmpInst::FCMP_OGT;
93  case kLE:
94  return llvm::CmpInst::FCMP_OLE;
95  case kGE:
96  return llvm::CmpInst::FCMP_OGE;
97  default:
98  abort();
99  }
100 }
101 
102 } // namespace
103 
104 namespace {
105 
106 std::string string_cmp_func(const SQLOps optype) {
107  switch (optype) {
108  case kLT:
109  return "string_lt";
110  case kLE:
111  return "string_le";
112  case kGT:
113  return "string_gt";
114  case kGE:
115  return "string_ge";
116  case kEQ:
117  return "string_eq";
118  case kNE:
119  return "string_ne";
120  default:
121  abort();
122  }
123 }
124 
125 std::shared_ptr<Analyzer::BinOper> lower_bw_eq(const Analyzer::BinOper* bw_eq) {
126  const auto eq_oper =
127  std::make_shared<Analyzer::BinOper>(bw_eq->get_type_info(),
128  bw_eq->get_contains_agg(),
129  kEQ,
130  bw_eq->get_qualifier(),
131  bw_eq->get_own_left_operand(),
132  bw_eq->get_own_right_operand());
133  const auto lhs_is_null =
134  std::make_shared<Analyzer::UOper>(kBOOLEAN, kISNULL, bw_eq->get_own_left_operand());
135  const auto rhs_is_null = std::make_shared<Analyzer::UOper>(
137  const auto both_are_null =
138  Parser::OperExpr::normalize(kAND, kONE, lhs_is_null, rhs_is_null);
139  const auto bw_eq_oper = std::dynamic_pointer_cast<Analyzer::BinOper>(
140  Parser::OperExpr::normalize(kOR, kONE, eq_oper, both_are_null));
141  CHECK(bw_eq_oper);
142  return bw_eq_oper;
143 }
144 
145 std::shared_ptr<Analyzer::BinOper> make_eq(const std::shared_ptr<Analyzer::Expr>& lhs,
146  const std::shared_ptr<Analyzer::Expr>& rhs,
147  const SQLOps optype) {
148  CHECK(IS_EQUIVALENCE(optype));
149  // Sides of a tuple equality are stripped of cast operators to simplify the logic
150  // in the hash table construction algorithm. Add them back here.
151  auto eq_oper = std::dynamic_pointer_cast<Analyzer::BinOper>(
152  Parser::OperExpr::normalize(optype, kONE, lhs, rhs));
153  CHECK(eq_oper);
154  return optype == kBW_EQ ? lower_bw_eq(eq_oper.get()) : eq_oper;
155 }
156 
157 // Convert a column tuple equality expression back to a conjunction of comparisons
158 // so that it can be handled by the regular code generation methods.
159 std::shared_ptr<Analyzer::BinOper> lower_multicol_compare(
160  const Analyzer::BinOper* multicol_compare) {
161  const auto left_tuple_expr = dynamic_cast<const Analyzer::ExpressionTuple*>(
162  multicol_compare->get_left_operand());
163  const auto right_tuple_expr = dynamic_cast<const Analyzer::ExpressionTuple*>(
164  multicol_compare->get_right_operand());
165  CHECK(left_tuple_expr && right_tuple_expr);
166  const auto& left_tuple = left_tuple_expr->getTuple();
167  const auto& right_tuple = right_tuple_expr->getTuple();
168  CHECK_EQ(left_tuple.size(), right_tuple.size());
169  CHECK_GT(left_tuple.size(), size_t(1));
170  auto acc =
171  make_eq(left_tuple.front(), right_tuple.front(), multicol_compare->get_optype());
172  for (size_t i = 1; i < left_tuple.size(); ++i) {
173  auto crt = make_eq(left_tuple[i], right_tuple[i], multicol_compare->get_optype());
174  const bool not_null =
175  acc->get_type_info().get_notnull() && crt->get_type_info().get_notnull();
176  acc = makeExpr<Analyzer::BinOper>(
177  SQLTypeInfo(kBOOLEAN, not_null), false, kAND, kONE, acc, crt);
178  }
179  return acc;
180 }
181 
182 } // namespace
183 
184 llvm::Value* CodeGenerator::codegenCmp(const Analyzer::BinOper* bin_oper,
185  const CompilationOptions& co) {
187  const auto qualifier = bin_oper->get_qualifier();
188  const auto lhs = bin_oper->get_left_operand();
189  const auto rhs = bin_oper->get_right_operand();
190  if (dynamic_cast<const Analyzer::ExpressionTuple*>(lhs)) {
191  CHECK(dynamic_cast<const Analyzer::ExpressionTuple*>(rhs));
192  const auto lowered = lower_multicol_compare(bin_oper);
193  const auto lowered_lvs = codegen(lowered.get(), true, co);
194  CHECK_EQ(size_t(1), lowered_lvs.size());
195  return lowered_lvs.front();
196  }
197  const auto optype = bin_oper->get_optype();
198  if (optype == kBW_EQ) {
199  const auto bw_eq_oper = lower_bw_eq(bin_oper);
200  return codegenLogical(bw_eq_oper.get(), co);
201  }
202  if (optype == kOVERLAPS) {
203  return codegenOverlaps(optype,
204  qualifier,
205  bin_oper->get_own_left_operand(),
206  bin_oper->get_own_right_operand(),
207  co);
208  }
209  if (is_unnest(lhs) || is_unnest(rhs)) {
210  throw std::runtime_error("Unnest not supported in comparisons");
211  }
212  const auto& lhs_ti = lhs->get_type_info();
213  const auto& rhs_ti = rhs->get_type_info();
214 
215  if (lhs_ti.is_string() && rhs_ti.is_string() &&
216  !(IS_EQUIVALENCE(optype) || optype == kNE)) {
217  auto cmp_str = codegenStrCmp(optype,
218  qualifier,
219  bin_oper->get_own_left_operand(),
220  bin_oper->get_own_right_operand(),
221  co);
222  if (cmp_str) {
223  return cmp_str;
224  }
225  }
226 
227  if (lhs_ti.is_decimal()) {
228  auto cmp_decimal_const =
229  codegenCmpDecimalConst(optype, qualifier, lhs, lhs_ti, rhs, co);
230  if (cmp_decimal_const) {
231  return cmp_decimal_const;
232  }
233  }
234 
235  auto lhs_lvs = codegen(lhs, true, co);
236  return codegenCmp(optype, qualifier, lhs_lvs, lhs_ti, rhs, co);
237 }
238 
239 llvm::Value* CodeGenerator::codegenOverlaps(const SQLOps optype,
240  const SQLQualifier qualifier,
241  const std::shared_ptr<Analyzer::Expr> lhs,
242  const std::shared_ptr<Analyzer::Expr> rhs,
243  const CompilationOptions& co) {
244  // TODO(adb): we should never get here, but going to leave this in place for now since
245  // it will likely be useful in factoring the bounds check out of ST_Contains
247  const auto lhs_ti = lhs->get_type_info();
249  LOG(FATAL) << "Fatal error when generating code for qualifier "
250  << lhs_ti.get_type_name();
251  }
252  CHECK(lhs_ti.is_geometry());
253 
254  if (lhs_ti.is_geometry()) {
255  // only point in linestring/poly/mpoly is currently supported
256  CHECK(lhs_ti.get_type() == kPOINT);
257  const auto lhs_col = dynamic_cast<Analyzer::ColumnVar*>(lhs.get());
258  CHECK(lhs_col);
259 
260  // Get the actual point data column descriptor
261  const auto coords_cd = executor()->getCatalog()->getMetadataForColumn(
262  lhs_col->get_table_id(), lhs_col->get_column_id() + 1);
263  CHECK(coords_cd);
264 
265  std::vector<std::shared_ptr<Analyzer::Expr>> geoargs;
266  geoargs.push_back(makeExpr<Analyzer::ColumnVar>(coords_cd->columnType,
267  coords_cd->tableId,
268  coords_cd->columnId,
269  lhs_col->get_rte_idx()));
270 
271  Datum input_compression;
272  input_compression.intval =
273  (lhs_ti.get_compression() == kENCODING_GEOINT && lhs_ti.get_comp_param() == 32)
274  ? 1
275  : 0;
276  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, input_compression));
277  Datum input_srid;
278  input_srid.intval = lhs_ti.get_input_srid();
279  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, input_srid));
280  Datum output_srid;
281  output_srid.intval = lhs_ti.get_output_srid();
282  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, output_srid));
283 
284  const auto x_ptr_oper = makeExpr<Analyzer::FunctionOper>(
285  SQLTypeInfo(kDOUBLE, true), "ST_X_Point", geoargs);
286  const auto y_ptr_oper = makeExpr<Analyzer::FunctionOper>(
287  SQLTypeInfo(kDOUBLE, true), "ST_Y_Point", geoargs);
288 
289  const auto rhs_ti = rhs->get_type_info();
290  CHECK(IS_GEO_POLY(rhs_ti.get_type()));
291  const auto rhs_col = dynamic_cast<Analyzer::ColumnVar*>(rhs.get());
292  CHECK(rhs_col);
293 
294  const auto poly_bounds_cd = executor()->getCatalog()->getMetadataForColumn(
295  rhs_col->get_table_id(),
296  rhs_col->get_column_id() + rhs_ti.get_physical_coord_cols() + 1);
297  CHECK(poly_bounds_cd);
298 
299  auto bbox_col_var = makeExpr<Analyzer::ColumnVar>(poly_bounds_cd->columnType,
300  poly_bounds_cd->tableId,
301  poly_bounds_cd->columnId,
302  rhs_col->get_rte_idx());
303 
304  const auto bbox_contains_func_oper =
305  makeExpr<Analyzer::FunctionOper>(SQLTypeInfo(kBOOLEAN, false),
306  "Point_Overlaps_Box",
307  std::vector<std::shared_ptr<Analyzer::Expr>>{
308  bbox_col_var, x_ptr_oper, y_ptr_oper});
309 
310  return codegenFunctionOper(bbox_contains_func_oper.get(), co);
311  }
312 
313  CHECK(false) << "Unsupported type for overlaps operator: " << lhs_ti.get_type_name();
314  return nullptr;
315 }
316 
317 llvm::Value* CodeGenerator::codegenStrCmp(const SQLOps optype,
318  const SQLQualifier qualifier,
319  const std::shared_ptr<Analyzer::Expr> lhs,
320  const std::shared_ptr<Analyzer::Expr> rhs,
321  const CompilationOptions& co) {
323  const auto lhs_ti = lhs->get_type_info();
324  const auto rhs_ti = rhs->get_type_info();
325 
326  CHECK(lhs_ti.is_string());
327  CHECK(rhs_ti.is_string());
328 
329  const auto null_check_suffix = get_null_check_suffix(lhs_ti, rhs_ti);
330  if (lhs_ti.get_compression() == kENCODING_DICT &&
331  rhs_ti.get_compression() == kENCODING_DICT) {
332  if (lhs_ti.get_comp_param() == rhs_ti.get_comp_param()) {
333  // Both operands share a dictionary
334 
335  // check if query is trying to compare a columnt against literal
336 
337  auto ir = codegenDictStrCmp(lhs, rhs, optype, co);
338  if (ir) {
339  return ir;
340  }
341  } else {
342  // Both operands don't share a dictionary
343  return nullptr;
344  }
345  }
346  return nullptr;
347 }
348 
350  const SQLQualifier qualifier,
351  const Analyzer::Expr* lhs,
352  const SQLTypeInfo& lhs_ti,
353  const Analyzer::Expr* rhs,
354  const CompilationOptions& co) {
356  auto u_oper = dynamic_cast<const Analyzer::UOper*>(lhs);
357  if (!u_oper || u_oper->get_optype() != kCAST) {
358  return nullptr;
359  }
360  auto rhs_constant = dynamic_cast<const Analyzer::Constant*>(rhs);
361  if (!rhs_constant) {
362  return nullptr;
363  }
364  const auto operand = u_oper->get_operand();
365  const auto& operand_ti = operand->get_type_info();
366  if (operand_ti.is_decimal() && operand_ti.get_scale() < lhs_ti.get_scale()) {
367  // lhs decimal type has smaller scale
368  } else if (operand_ti.is_integer() && 0 < lhs_ti.get_scale()) {
369  // lhs is integer, no need to scale it all the way up to the cmp expr scale
370  } else {
371  return nullptr;
372  }
373 
374  auto scale_diff = lhs_ti.get_scale() - operand_ti.get_scale() - 1;
375  int64_t bigintval = rhs_constant->get_constval().bigintval;
376  bool negative = false;
377  if (bigintval < 0) {
378  negative = true;
379  bigintval = -bigintval;
380  }
381  int64_t truncated_decimal = bigintval / exp_to_scale(scale_diff);
382  int64_t decimal_tail = bigintval % exp_to_scale(scale_diff);
383  if (truncated_decimal % 10 == 0 && decimal_tail > 0) {
384  truncated_decimal += 1;
385  }
386  SQLTypeInfo new_ti = SQLTypeInfo(
387  kDECIMAL, 19, lhs_ti.get_scale() - scale_diff, operand_ti.get_notnull());
388  if (negative) {
389  truncated_decimal = -truncated_decimal;
390  }
391  Datum d;
392  d.bigintval = truncated_decimal;
393  const auto new_rhs_lit =
394  makeExpr<Analyzer::Constant>(new_ti, rhs_constant->get_is_null(), d);
395  const auto operand_lv = codegen(operand, true, co).front();
396  const auto lhs_lv = codegenCast(operand_lv, operand_ti, new_ti, false, co);
397  return codegenCmp(optype, qualifier, {lhs_lv}, new_ti, new_rhs_lit.get(), co);
398 }
399 
400 llvm::Value* CodeGenerator::codegenCmp(const SQLOps optype,
401  const SQLQualifier qualifier,
402  std::vector<llvm::Value*> lhs_lvs,
403  const SQLTypeInfo& lhs_ti,
404  const Analyzer::Expr* rhs,
405  const CompilationOptions& co) {
407  CHECK(IS_COMPARISON(optype));
408  const auto& rhs_ti = rhs->get_type_info();
409  if (rhs_ti.is_array()) {
410  return codegenQualifierCmp(optype, qualifier, lhs_lvs, rhs, co);
411  }
412  auto rhs_lvs = codegen(rhs, true, co);
413  CHECK_EQ(kONE, qualifier);
414  if (optype == kOVERLAPS) {
415  CHECK(lhs_ti.is_geometry());
416  CHECK(rhs_ti.is_array() ||
417  rhs_ti.is_geometry()); // allow geo col or bounds col to pass
418  } else {
419  CHECK((lhs_ti.get_type() == rhs_ti.get_type()) ||
420  (lhs_ti.is_string() && rhs_ti.is_string()));
421  }
422  const auto null_check_suffix = get_null_check_suffix(lhs_ti, rhs_ti);
423  if (lhs_ti.is_integer() || lhs_ti.is_decimal() || lhs_ti.is_time() ||
424  lhs_ti.is_boolean() || lhs_ti.is_string() || lhs_ti.is_timeinterval()) {
425  if (lhs_ti.is_string()) {
426  CHECK(rhs_ti.is_string());
427  CHECK_EQ(lhs_ti.get_compression(), rhs_ti.get_compression());
428  if (lhs_ti.get_compression() == kENCODING_NONE) {
429  // unpack pointer + length if necessary
430  if (lhs_lvs.size() != 3) {
431  CHECK_EQ(size_t(1), lhs_lvs.size());
432  lhs_lvs.push_back(cgen_state_->emitCall("extract_str_ptr", {lhs_lvs.front()}));
433  lhs_lvs.push_back(cgen_state_->emitCall("extract_str_len", {lhs_lvs.front()}));
434  }
435  if (rhs_lvs.size() != 3) {
436  CHECK_EQ(size_t(1), rhs_lvs.size());
437  rhs_lvs.push_back(cgen_state_->emitCall("extract_str_ptr", {rhs_lvs.front()}));
438  rhs_lvs.push_back(cgen_state_->emitCall("extract_str_len", {rhs_lvs.front()}));
439  }
440  std::vector<llvm::Value*> str_cmp_args{
441  lhs_lvs[1], lhs_lvs[2], rhs_lvs[1], rhs_lvs[2]};
442  if (!null_check_suffix.empty()) {
443  str_cmp_args.push_back(
445  }
446  return cgen_state_->emitCall(
447  string_cmp_func(optype) + (null_check_suffix.empty() ? "" : "_nullable"),
448  str_cmp_args);
449  } else {
450  CHECK(optype == kEQ || optype == kNE);
451  }
452  }
453 
454  if (lhs_ti.is_boolean() && rhs_ti.is_boolean()) {
455  auto& lhs_lv = lhs_lvs.front();
456  auto& rhs_lv = rhs_lvs.front();
457  CHECK(lhs_lv->getType()->isIntegerTy());
458  CHECK(rhs_lv->getType()->isIntegerTy());
459  if (lhs_lv->getType()->getIntegerBitWidth() <
460  rhs_lv->getType()->getIntegerBitWidth()) {
461  lhs_lv =
462  cgen_state_->castToTypeIn(lhs_lv, rhs_lv->getType()->getIntegerBitWidth());
463  } else {
464  rhs_lv =
465  cgen_state_->castToTypeIn(rhs_lv, lhs_lv->getType()->getIntegerBitWidth());
466  }
467  }
468 
469  return null_check_suffix.empty()
470  ? cgen_state_->ir_builder_.CreateICmp(
471  llvm_icmp_pred(optype), lhs_lvs.front(), rhs_lvs.front())
473  icmp_name(optype) + "_" + numeric_type_name(lhs_ti) +
474  null_check_suffix,
475  {lhs_lvs.front(),
476  rhs_lvs.front(),
479  }
480  if (lhs_ti.get_type() == kFLOAT || lhs_ti.get_type() == kDOUBLE) {
481  return null_check_suffix.empty()
482  ? cgen_state_->ir_builder_.CreateFCmp(
483  llvm_fcmp_pred(optype), lhs_lvs.front(), rhs_lvs.front())
485  icmp_name(optype) + "_" + numeric_type_name(lhs_ti) +
486  null_check_suffix,
487  {lhs_lvs.front(),
488  rhs_lvs.front(),
489  lhs_ti.get_type() == kFLOAT ? cgen_state_->llFp(NULL_FLOAT)
492  }
493  CHECK(false);
494  return nullptr;
495 }
496 
497 llvm::Value* CodeGenerator::codegenQualifierCmp(const SQLOps optype,
498  const SQLQualifier qualifier,
499  std::vector<llvm::Value*> lhs_lvs,
500  const Analyzer::Expr* rhs,
501  const CompilationOptions& co) {
503  const auto& rhs_ti = rhs->get_type_info();
504  const Analyzer::Expr* arr_expr{rhs};
505  if (dynamic_cast<const Analyzer::UOper*>(rhs)) {
506  const auto cast_arr = static_cast<const Analyzer::UOper*>(rhs);
507  CHECK_EQ(kCAST, cast_arr->get_optype());
508  arr_expr = cast_arr->get_operand();
509  }
510  const auto& arr_ti = arr_expr->get_type_info();
511  const auto& elem_ti = arr_ti.get_elem_type();
512  auto rhs_lvs = codegen(arr_expr, true, co);
513  CHECK_NE(kONE, qualifier);
514  std::string fname{std::string("array_") + (qualifier == kANY ? "any" : "all") + "_" +
515  icmp_arr_name(optype)};
516  const auto& target_ti = rhs_ti.get_elem_type();
517  const bool is_real_string{target_ti.is_string() &&
518  target_ti.get_compression() != kENCODING_DICT};
519  if (is_real_string) {
520  if (g_cluster) {
521  throw std::runtime_error(
522  "Comparison between a dictionary-encoded and a none-encoded string not "
523  "supported for distributed queries");
524  }
525  if (g_enable_watchdog) {
526  throw WatchdogException(
527  "Comparison between a dictionary-encoded and a none-encoded string would be "
528  "slow");
529  }
531  throw QueryMustRunOnCpu();
532  }
533  CHECK_EQ(kENCODING_NONE, target_ti.get_compression());
534  fname += "_str";
535  }
536  if (elem_ti.is_integer() || elem_ti.is_boolean() || elem_ti.is_string()) {
537  fname += ("_" + numeric_type_name(elem_ti));
538  } else {
539  CHECK(elem_ti.is_fp());
540  fname += elem_ti.get_type() == kDOUBLE ? "_double" : "_float";
541  }
542  if (is_real_string) {
543  CHECK_EQ(size_t(3), lhs_lvs.size());
545  fname,
547  {rhs_lvs.front(),
548  posArg(arr_expr),
549  lhs_lvs[1],
550  lhs_lvs[2],
551  cgen_state_->llInt(int64_t(executor()->getStringDictionaryProxy(
552  elem_ti.get_comp_param(), executor()->getRowSetMemoryOwner(), true))),
553  cgen_state_->inlineIntNull(elem_ti)});
554  }
555  if (target_ti.is_integer() || target_ti.is_boolean() || target_ti.is_string()) {
556  fname += ("_" + numeric_type_name(target_ti));
557  } else {
558  CHECK(target_ti.is_fp());
559  fname += target_ti.get_type() == kDOUBLE ? "_double" : "_float";
560  }
562  fname,
564  {rhs_lvs.front(),
565  posArg(arr_expr),
566  lhs_lvs.front(),
567  elem_ti.is_fp() ? static_cast<llvm::Value*>(cgen_state_->inlineFpNull(elem_ti))
568  : static_cast<llvm::Value*>(cgen_state_->inlineIntNull(elem_ti))});
569 }
SQLQualifier get_qualifier() const
Definition: Analyzer.h:441
#define CHECK_EQ(x, y)
Definition: Logger.h:205
llvm::Value * castToTypeIn(llvm::Value *val, const size_t bit_width)
Definition: CgenState.cpp:106
#define NULL_DOUBLE
Definition: sqltypes.h:186
bool is_time() const
Definition: sqltypes.h:423
llvm::Value * codegenStrCmp(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:317
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:316
bool is_string() const
Definition: sqltypes.h:417
bool is_boolean() const
Definition: sqltypes.h:424
std::string icmp_name(const SQLOps op_type)
Definition: CompareIR.cpp:45
bool is_integer() const
Definition: sqltypes.h:419
#define IS_EQUIVALENCE(X)
Definition: sqldefs.h:67
CgenState * cgen_state_
SQLQualifier
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::BinOper > lower_multicol_compare(const Analyzer::BinOper *multicol_compare)
Definition: CompareIR.cpp:159
Executor * executor() const
#define LOG(tag)
Definition: Logger.h:188
SQLOps
Definition: sqldefs.h:29
Definition: sqldefs.h:35
llvm::IRBuilder ir_builder_
Definition: CgenState.h:341
Definition: sqldefs.h:36
Definition: sqldefs.h:38
Definition: sqldefs.h:49
Definition: sqldefs.h:30
std::shared_ptr< Analyzer::BinOper > lower_bw_eq(const Analyzer::BinOper *bw_eq)
Definition: CompareIR.cpp:125
bool is_timeinterval() const
Definition: sqltypes.h:428
llvm::CmpInst::Predicate llvm_fcmp_pred(const SQLOps op_type)
Definition: CompareIR.cpp:83
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define CHECK_GT(x, y)
Definition: Logger.h:209
bool is_decimal() const
Definition: sqltypes.h:420
int32_t intval
Definition: sqltypes.h:137
HOST DEVICE int get_scale() const
Definition: sqltypes.h:264
std::string icmp_arr_name(const SQLOps op_type)
Definition: CompareIR.cpp:64
bool g_enable_overlaps_hashjoin
Definition: Execute.cpp:92
SQLOps get_optype() const
Definition: Analyzer.h:439
llvm::LLVMContext & context_
Definition: CgenState.h:339
llvm::Value * codegenCmpDecimalConst(const SQLOps, const SQLQualifier, const Analyzer::Expr *, const SQLTypeInfo &, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:349
#define CHECK_NE(x, y)
Definition: Logger.h:206
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:27
int64_t bigintval
Definition: sqltypes.h:138
#define NULL_FLOAT
Definition: sqltypes.h:185
llvm::Value * codegenFunctionOper(const Analyzer::FunctionOper *, const CompilationOptions &)
Definition: sqldefs.h:37
Definition: sqldefs.h:69
llvm::Value * codegenOverlaps(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:239
llvm::Value * codegenDictStrCmp(const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const SQLOps, const CompilationOptions &co)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:1026
const std::shared_ptr< Analyzer::Expr > get_own_left_operand() const
Definition: Analyzer.h:444
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr)
Definition: ParserNode.cpp:270
ExecutorDeviceType device_type
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:222
Definition: sqldefs.h:34
std::vector< llvm::Value * > codegen(const Analyzer::Expr *, const bool fetch_columns, const CompilationOptions &)
Definition: IRCodegen.cpp:26
const std::shared_ptr< Analyzer::Expr > get_own_right_operand() const
Definition: Analyzer.h:447
bool is_geometry() const
Definition: sqltypes.h:429
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::BinOper > make_eq(const std::shared_ptr< Analyzer::Expr > &lhs, const std::shared_ptr< Analyzer::Expr > &rhs, const SQLOps optype)
Definition: CompareIR.cpp:145
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value *> &args)
Definition: CgenState.cpp:137
Definition: sqldefs.h:32
llvm::CmpInst::Predicate llvm_icmp_pred(const SQLOps op_type)
Definition: CompareIR.cpp:26
llvm::Value * codegenCmp(const Analyzer::BinOper *, const CompilationOptions &)
Definition: CompareIR.cpp:184
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqldefs.h:31
llvm::Value * codegenLogical(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:290
uint64_t exp_to_scale(const unsigned exp)
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
bool g_cluster
bool g_enable_watchdog
Definition: Execute.cpp:74
Definition: sqldefs.h:33
llvm::Value * codegenCast(const Analyzer::UOper *, const CompilationOptions &)
Definition: CastIR.cpp:20
std::string numeric_type_name(const SQLTypeInfo &ti)
Definition: Execute.h:172
bool get_contains_agg() const
Definition: Analyzer.h:80
Definition: sqltypes.h:47
llvm::Value * codegenQualifierCmp(const SQLOps, const SQLQualifier, std::vector< llvm::Value *>, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:497
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:1042
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:312
std::string string_cmp_func(const SQLOps optype)
Definition: CompareIR.cpp:106
#define IS_COMPARISON(X)
Definition: sqldefs.h:57
const Expr * get_right_operand() const
Definition: Analyzer.h:443
const Expr * get_left_operand() const
Definition: Analyzer.h:442
#define IS_GEO_POLY(T)
Definition: sqltypes.h:178