OmniSciDB  62f1aeabe6
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) {
186  const auto qualifier = bin_oper->get_qualifier();
187  const auto lhs = bin_oper->get_left_operand();
188  const auto rhs = bin_oper->get_right_operand();
189  if (dynamic_cast<const Analyzer::ExpressionTuple*>(lhs)) {
190  CHECK(dynamic_cast<const Analyzer::ExpressionTuple*>(rhs));
191  const auto lowered = lower_multicol_compare(bin_oper);
192  const auto lowered_lvs = codegen(lowered.get(), true, co);
193  CHECK_EQ(size_t(1), lowered_lvs.size());
194  return lowered_lvs.front();
195  }
196  const auto optype = bin_oper->get_optype();
197  if (optype == kBW_EQ) {
198  const auto bw_eq_oper = lower_bw_eq(bin_oper);
199  return codegenLogical(bw_eq_oper.get(), co);
200  }
201  if (optype == kOVERLAPS) {
202  return codegenOverlaps(optype,
203  qualifier,
204  bin_oper->get_own_left_operand(),
205  bin_oper->get_own_right_operand(),
206  co);
207  }
208  if (is_unnest(lhs) || is_unnest(rhs)) {
209  throw std::runtime_error("Unnest not supported in comparisons");
210  }
211  const auto& lhs_ti = lhs->get_type_info();
212  const auto& rhs_ti = rhs->get_type_info();
213 
214  if (lhs_ti.is_string() && rhs_ti.is_string() &&
215  !(IS_EQUIVALENCE(optype) || optype == kNE)) {
216  auto cmp_str = codegenStrCmp(optype,
217  qualifier,
218  bin_oper->get_own_left_operand(),
219  bin_oper->get_own_right_operand(),
220  co);
221  if (cmp_str) {
222  return cmp_str;
223  }
224  }
225 
226  if (lhs_ti.is_decimal()) {
227  auto cmp_decimal_const =
228  codegenCmpDecimalConst(optype, qualifier, lhs, lhs_ti, rhs, co);
229  if (cmp_decimal_const) {
230  return cmp_decimal_const;
231  }
232  }
233 
234  auto lhs_lvs = codegen(lhs, true, co);
235  return codegenCmp(optype, qualifier, lhs_lvs, lhs_ti, rhs, co);
236 }
237 
238 llvm::Value* CodeGenerator::codegenOverlaps(const SQLOps optype,
239  const SQLQualifier qualifier,
240  const std::shared_ptr<Analyzer::Expr> lhs,
241  const std::shared_ptr<Analyzer::Expr> rhs,
242  const CompilationOptions& co) {
243  // TODO(adb): we should never get here, but going to leave this in place for now since
244  // it will likely be useful in factoring the bounds check out of ST_Contains
245  const auto lhs_ti = lhs->get_type_info();
247  LOG(FATAL) << "Fatal error when generating code for qualifier "
248  << lhs_ti.get_type_name();
249  }
250  CHECK(lhs_ti.is_geometry());
251 
252  if (lhs_ti.is_geometry()) {
253  // only point in linestring/poly/mpoly is currently supported
254  CHECK(lhs_ti.get_type() == kPOINT);
255  const auto lhs_col = dynamic_cast<Analyzer::ColumnVar*>(lhs.get());
256  CHECK(lhs_col);
257 
258  // Get the actual point data column descriptor
259  const auto coords_cd = executor()->getCatalog()->getMetadataForColumn(
260  lhs_col->get_table_id(), lhs_col->get_column_id() + 1);
261  CHECK(coords_cd);
262 
263  std::vector<std::shared_ptr<Analyzer::Expr>> geoargs;
264  geoargs.push_back(makeExpr<Analyzer::ColumnVar>(coords_cd->columnType,
265  coords_cd->tableId,
266  coords_cd->columnId,
267  lhs_col->get_rte_idx()));
268 
269  Datum input_compression;
270  input_compression.intval =
271  (lhs_ti.get_compression() == kENCODING_GEOINT && lhs_ti.get_comp_param() == 32)
272  ? 1
273  : 0;
274  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, input_compression));
275  Datum input_srid;
276  input_srid.intval = lhs_ti.get_input_srid();
277  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, input_srid));
278  Datum output_srid;
279  output_srid.intval = lhs_ti.get_output_srid();
280  geoargs.push_back(makeExpr<Analyzer::Constant>(kINT, false, output_srid));
281 
282  const auto x_ptr_oper = makeExpr<Analyzer::FunctionOper>(
283  SQLTypeInfo(kDOUBLE, true), "ST_X_Point", geoargs);
284  const auto y_ptr_oper = makeExpr<Analyzer::FunctionOper>(
285  SQLTypeInfo(kDOUBLE, true), "ST_Y_Point", geoargs);
286 
287  const auto rhs_ti = rhs->get_type_info();
288  CHECK(IS_GEO_POLY(rhs_ti.get_type()));
289  const auto rhs_col = dynamic_cast<Analyzer::ColumnVar*>(rhs.get());
290  CHECK(rhs_col);
291 
292  const auto poly_bounds_cd = executor()->getCatalog()->getMetadataForColumn(
293  rhs_col->get_table_id(),
294  rhs_col->get_column_id() + rhs_ti.get_physical_coord_cols() + 1);
295  CHECK(poly_bounds_cd);
296 
297  auto bbox_col_var = makeExpr<Analyzer::ColumnVar>(poly_bounds_cd->columnType,
298  poly_bounds_cd->tableId,
299  poly_bounds_cd->columnId,
300  rhs_col->get_rte_idx());
301 
302  const auto bbox_contains_func_oper =
303  makeExpr<Analyzer::FunctionOper>(SQLTypeInfo(kBOOLEAN, false),
304  "Point_Overlaps_Box",
305  std::vector<std::shared_ptr<Analyzer::Expr>>{
306  bbox_col_var, x_ptr_oper, y_ptr_oper});
307 
308  return codegenFunctionOper(bbox_contains_func_oper.get(), co);
309  }
310 
311  CHECK(false) << "Unsupported type for overlaps operator: " << lhs_ti.get_type_name();
312  return nullptr;
313 }
314 
315 llvm::Value* CodeGenerator::codegenStrCmp(const SQLOps optype,
316  const SQLQualifier qualifier,
317  const std::shared_ptr<Analyzer::Expr> lhs,
318  const std::shared_ptr<Analyzer::Expr> rhs,
319  const CompilationOptions& co) {
320  const auto lhs_ti = lhs->get_type_info();
321  const auto rhs_ti = rhs->get_type_info();
322 
323  CHECK(lhs_ti.is_string());
324  CHECK(rhs_ti.is_string());
325 
326  const auto null_check_suffix = get_null_check_suffix(lhs_ti, rhs_ti);
327  if (lhs_ti.get_compression() == kENCODING_DICT &&
328  rhs_ti.get_compression() == kENCODING_DICT) {
329  if (lhs_ti.get_comp_param() == rhs_ti.get_comp_param()) {
330  // Both operands share a dictionary
331 
332  // check if query is trying to compare a columnt against literal
333 
334  auto ir = codegenDictStrCmp(lhs, rhs, optype, co);
335  if (ir) {
336  return ir;
337  }
338  } else {
339  // Both operands don't share a dictionary
340  return nullptr;
341  }
342  }
343  return nullptr;
344 }
346  const SQLQualifier qualifier,
347  const Analyzer::Expr* lhs,
348  const SQLTypeInfo& lhs_ti,
349  const Analyzer::Expr* rhs,
350  const CompilationOptions& co) {
351  auto u_oper = dynamic_cast<const Analyzer::UOper*>(lhs);
352  if (!u_oper || u_oper->get_optype() != kCAST) {
353  return nullptr;
354  }
355  auto rhs_constant = dynamic_cast<const Analyzer::Constant*>(rhs);
356  if (!rhs_constant) {
357  return nullptr;
358  }
359  const auto operand = u_oper->get_operand();
360  const auto& operand_ti = operand->get_type_info();
361  if (operand_ti.is_decimal() && operand_ti.get_scale() < lhs_ti.get_scale()) {
362  // lhs decimal type has smaller scale
363  } else if (operand_ti.is_integer() && 0 < lhs_ti.get_scale()) {
364  // lhs is integer, no need to scale it all the way up to the cmp expr scale
365  } else {
366  return nullptr;
367  }
368 
369  auto scale_diff = lhs_ti.get_scale() - operand_ti.get_scale() - 1;
370  int64_t bigintval = rhs_constant->get_constval().bigintval;
371  bool negative = false;
372  if (bigintval < 0) {
373  negative = true;
374  bigintval = -bigintval;
375  }
376  int64_t truncated_decimal = bigintval / exp_to_scale(scale_diff);
377  int64_t decimal_tail = bigintval % exp_to_scale(scale_diff);
378  if (truncated_decimal % 10 == 0 && decimal_tail > 0) {
379  truncated_decimal += 1;
380  }
381  SQLTypeInfo new_ti = SQLTypeInfo(
382  kDECIMAL, 19, lhs_ti.get_scale() - scale_diff, operand_ti.get_notnull());
383  if (negative) {
384  truncated_decimal = -truncated_decimal;
385  }
386  Datum d;
387  d.bigintval = truncated_decimal;
388  const auto new_rhs_lit =
389  makeExpr<Analyzer::Constant>(new_ti, rhs_constant->get_is_null(), d);
390  const auto operand_lv = codegen(operand, true, co).front();
391  const auto lhs_lv = codegenCast(operand_lv, operand_ti, new_ti, false, co);
392  return codegenCmp(optype, qualifier, {lhs_lv}, new_ti, new_rhs_lit.get(), co);
393 }
394 
395 llvm::Value* CodeGenerator::codegenCmp(const SQLOps optype,
396  const SQLQualifier qualifier,
397  std::vector<llvm::Value*> lhs_lvs,
398  const SQLTypeInfo& lhs_ti,
399  const Analyzer::Expr* rhs,
400  const CompilationOptions& co) {
401  CHECK(IS_COMPARISON(optype));
402  const auto& rhs_ti = rhs->get_type_info();
403  if (rhs_ti.is_array()) {
404  return codegenQualifierCmp(optype, qualifier, lhs_lvs, rhs, co);
405  }
406  auto rhs_lvs = codegen(rhs, true, co);
407  CHECK_EQ(kONE, qualifier);
408  if (optype == kOVERLAPS) {
409  CHECK(lhs_ti.is_geometry());
410  CHECK(rhs_ti.is_array() ||
411  rhs_ti.is_geometry()); // allow geo col or bounds col to pass
412  } else {
413  CHECK((lhs_ti.get_type() == rhs_ti.get_type()) ||
414  (lhs_ti.is_string() && rhs_ti.is_string()));
415  }
416  const auto null_check_suffix = get_null_check_suffix(lhs_ti, rhs_ti);
417  if (lhs_ti.is_integer() || lhs_ti.is_decimal() || lhs_ti.is_time() ||
418  lhs_ti.is_boolean() || lhs_ti.is_string() || lhs_ti.is_timeinterval()) {
419  if (lhs_ti.is_string()) {
420  CHECK(rhs_ti.is_string());
421  CHECK_EQ(lhs_ti.get_compression(), rhs_ti.get_compression());
422  if (lhs_ti.get_compression() == kENCODING_NONE) {
423  // unpack pointer + length if necessary
424  if (lhs_lvs.size() != 3) {
425  CHECK_EQ(size_t(1), lhs_lvs.size());
426  lhs_lvs.push_back(cgen_state_->emitCall("extract_str_ptr", {lhs_lvs.front()}));
427  lhs_lvs.push_back(cgen_state_->emitCall("extract_str_len", {lhs_lvs.front()}));
428  }
429  if (rhs_lvs.size() != 3) {
430  CHECK_EQ(size_t(1), rhs_lvs.size());
431  rhs_lvs.push_back(cgen_state_->emitCall("extract_str_ptr", {rhs_lvs.front()}));
432  rhs_lvs.push_back(cgen_state_->emitCall("extract_str_len", {rhs_lvs.front()}));
433  }
434  std::vector<llvm::Value*> str_cmp_args{
435  lhs_lvs[1], lhs_lvs[2], rhs_lvs[1], rhs_lvs[2]};
436  if (!null_check_suffix.empty()) {
437  str_cmp_args.push_back(
439  }
440  return cgen_state_->emitCall(
441  string_cmp_func(optype) + (null_check_suffix.empty() ? "" : "_nullable"),
442  str_cmp_args);
443  } else {
444  CHECK(optype == kEQ || optype == kNE);
445  }
446  }
447 
448  if (lhs_ti.is_boolean() && rhs_ti.is_boolean()) {
449  auto& lhs_lv = lhs_lvs.front();
450  auto& rhs_lv = rhs_lvs.front();
451  CHECK(lhs_lv->getType()->isIntegerTy());
452  CHECK(rhs_lv->getType()->isIntegerTy());
453  if (lhs_lv->getType()->getIntegerBitWidth() <
454  rhs_lv->getType()->getIntegerBitWidth()) {
455  lhs_lv =
456  cgen_state_->castToTypeIn(lhs_lv, rhs_lv->getType()->getIntegerBitWidth());
457  } else {
458  rhs_lv =
459  cgen_state_->castToTypeIn(rhs_lv, lhs_lv->getType()->getIntegerBitWidth());
460  }
461  }
462 
463  return null_check_suffix.empty()
464  ? cgen_state_->ir_builder_.CreateICmp(
465  llvm_icmp_pred(optype), lhs_lvs.front(), rhs_lvs.front())
467  icmp_name(optype) + "_" + numeric_type_name(lhs_ti) +
468  null_check_suffix,
469  {lhs_lvs.front(),
470  rhs_lvs.front(),
473  }
474  if (lhs_ti.get_type() == kFLOAT || lhs_ti.get_type() == kDOUBLE) {
475  return null_check_suffix.empty()
476  ? cgen_state_->ir_builder_.CreateFCmp(
477  llvm_fcmp_pred(optype), lhs_lvs.front(), rhs_lvs.front())
479  icmp_name(optype) + "_" + numeric_type_name(lhs_ti) +
480  null_check_suffix,
481  {lhs_lvs.front(),
482  rhs_lvs.front(),
483  lhs_ti.get_type() == kFLOAT ? cgen_state_->llFp(NULL_FLOAT)
486  }
487  CHECK(false);
488  return nullptr;
489 }
490 
491 llvm::Value* CodeGenerator::codegenQualifierCmp(const SQLOps optype,
492  const SQLQualifier qualifier,
493  std::vector<llvm::Value*> lhs_lvs,
494  const Analyzer::Expr* rhs,
495  const CompilationOptions& co) {
496  const auto& rhs_ti = rhs->get_type_info();
497  const Analyzer::Expr* arr_expr{rhs};
498  if (dynamic_cast<const Analyzer::UOper*>(rhs)) {
499  const auto cast_arr = static_cast<const Analyzer::UOper*>(rhs);
500  CHECK_EQ(kCAST, cast_arr->get_optype());
501  arr_expr = cast_arr->get_operand();
502  }
503  const auto& arr_ti = arr_expr->get_type_info();
504  const auto& elem_ti = arr_ti.get_elem_type();
505  auto rhs_lvs = codegen(arr_expr, true, co);
506  CHECK_NE(kONE, qualifier);
507  std::string fname{std::string("array_") + (qualifier == kANY ? "any" : "all") + "_" +
508  icmp_arr_name(optype)};
509  const auto& target_ti = rhs_ti.get_elem_type();
510  const bool is_real_string{target_ti.is_string() &&
511  target_ti.get_compression() != kENCODING_DICT};
512  if (is_real_string) {
513  if (g_cluster) {
514  throw std::runtime_error(
515  "Comparison between a dictionary-encoded and a none-encoded string not "
516  "supported for distributed queries");
517  }
518  if (g_enable_watchdog) {
519  throw WatchdogException(
520  "Comparison between a dictionary-encoded and a none-encoded string would be "
521  "slow");
522  }
524  throw QueryMustRunOnCpu();
525  }
526  CHECK_EQ(kENCODING_NONE, target_ti.get_compression());
527  fname += "_str";
528  }
529  if (elem_ti.is_integer() || elem_ti.is_boolean() || elem_ti.is_string()) {
530  fname += ("_" + numeric_type_name(elem_ti));
531  } else {
532  CHECK(elem_ti.is_fp());
533  fname += elem_ti.get_type() == kDOUBLE ? "_double" : "_float";
534  }
535  if (is_real_string) {
536  CHECK_EQ(size_t(3), lhs_lvs.size());
538  fname,
540  {rhs_lvs.front(),
541  posArg(arr_expr),
542  lhs_lvs[1],
543  lhs_lvs[2],
544  cgen_state_->llInt(int64_t(executor()->getStringDictionaryProxy(
545  elem_ti.get_comp_param(), executor()->getRowSetMemoryOwner(), true))),
546  cgen_state_->inlineIntNull(elem_ti)});
547  }
548  if (target_ti.is_integer() || target_ti.is_boolean() || target_ti.is_string()) {
549  fname += ("_" + numeric_type_name(target_ti));
550  } else {
551  CHECK(target_ti.is_fp());
552  fname += target_ti.get_type() == kDOUBLE ? "_double" : "_float";
553  }
555  fname,
557  {rhs_lvs.front(),
558  posArg(arr_expr),
559  lhs_lvs.front(),
560  elem_ti.is_fp() ? static_cast<llvm::Value*>(cgen_state_->inlineFpNull(elem_ti))
561  : static_cast<llvm::Value*>(cgen_state_->inlineIntNull(elem_ti))});
562 }
SQLQualifier get_qualifier() const
Definition: Analyzer.h:442
#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:185
bool is_time() const
Definition: sqltypes.h:421
llvm::Value * codegenStrCmp(const SQLOps, const SQLQualifier, const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const CompilationOptions &)
Definition: CompareIR.cpp:315
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:300
bool is_string() const
Definition: sqltypes.h:415
bool is_boolean() const
Definition: sqltypes.h:422
std::string icmp_name(const SQLOps op_type)
Definition: CompareIR.cpp:45
bool is_integer() const
Definition: sqltypes.h:417
#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:319
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:426
llvm::CmpInst::Predicate llvm_fcmp_pred(const SQLOps op_type)
Definition: CompareIR.cpp:83
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
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:418
int32_t intval
Definition: sqltypes.h:136
HOST DEVICE int get_scale() const
Definition: sqltypes.h:263
std::string icmp_arr_name(const SQLOps op_type)
Definition: CompareIR.cpp:64
bool g_enable_overlaps_hashjoin
Definition: Execute.cpp:91
SQLOps get_optype() const
Definition: Analyzer.h:440
llvm::LLVMContext & context_
Definition: CgenState.h:317
llvm::Value * codegenCmpDecimalConst(const SQLOps, const SQLQualifier, const Analyzer::Expr *, const SQLTypeInfo &, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:345
#define CHECK_NE(x, y)
Definition: Logger.h:206
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:27
int64_t bigintval
Definition: sqltypes.h:137
#define NULL_FLOAT
Definition: sqltypes.h:184
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:238
llvm::Value * codegenDictStrCmp(const std::shared_ptr< Analyzer::Expr >, const std::shared_ptr< Analyzer::Expr >, const SQLOps, const CompilationOptions &co)
std::string get_null_check_suffix(const SQLTypeInfo &lhs_ti, const SQLTypeInfo &rhs_ti)
Definition: Execute.h:980
const std::shared_ptr< Analyzer::Expr > get_own_left_operand() const
Definition: Analyzer.h:445
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:272
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:206
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:448
bool is_geometry() const
Definition: sqltypes.h:427
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:79
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
Definition: sqldefs.h:31
llvm::Value * codegenLogical(const Analyzer::BinOper *, const CompilationOptions &)
Definition: LogicalIR.cpp:289
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:138
bool get_contains_agg() const
Definition: Analyzer.h:81
Definition: sqltypes.h:46
llvm::Value * codegenQualifierCmp(const SQLOps, const SQLQualifier, std::vector< llvm::Value *>, const Analyzer::Expr *, const CompilationOptions &)
Definition: CompareIR.cpp:491
bool is_unnest(const Analyzer::Expr *expr)
Definition: Execute.h:996
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:296
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:444
const Expr * get_left_operand() const
Definition: Analyzer.h:443
#define IS_GEO_POLY(T)
Definition: sqltypes.h:177