OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{CompareIR.cpp} Namespace Reference

Functions

llvm::CmpInst::Predicate llvm_icmp_pred (const SQLOps op_type)
 
std::string icmp_name (const SQLOps op_type)
 
std::string icmp_arr_name (const SQLOps op_type)
 
llvm::CmpInst::Predicate llvm_fcmp_pred (const SQLOps op_type)
 
std::string string_cmp_func (const SQLOps optype)
 
std::shared_ptr
< Analyzer::BinOper
lower_bw_eq (const Analyzer::BinOper *bw_eq)
 
std::shared_ptr
< Analyzer::BinOper
make_eq (const std::shared_ptr< Analyzer::Expr > &lhs, const std::shared_ptr< Analyzer::Expr > &rhs, const SQLOps optype)
 
std::shared_ptr
< Analyzer::BinOper
lower_multicol_compare (const Analyzer::BinOper *multicol_compare)
 
void check_array_comp_cond (const Analyzer::BinOper *bin_oper)
 

Function Documentation

void anonymous_namespace{CompareIR.cpp}::check_array_comp_cond ( const Analyzer::BinOper bin_oper)

Definition at line 182 of file CompareIR.cpp.

References Analyzer::BinOper::get_left_operand(), Analyzer::BinOper::get_optype(), Analyzer::BinOper::get_right_operand(), IS_COMPARISON, IS_EQUIVALENCE, kARRAY_AT, kNE, and kTEXT.

Referenced by CodeGenerator::codegenCmp().

182  {
183  auto lhs_cv = dynamic_cast<const Analyzer::ColumnVar*>(bin_oper->get_left_operand());
184  auto rhs_cv = dynamic_cast<const Analyzer::ColumnVar*>(bin_oper->get_right_operand());
185  auto comp_op = IS_COMPARISON(bin_oper->get_optype());
186  if (lhs_cv && rhs_cv && comp_op) {
187  auto lhs_ti = lhs_cv->get_type_info();
188  auto rhs_ti = rhs_cv->get_type_info();
189  if (lhs_ti.is_array() && rhs_ti.is_array()) {
190  throw std::runtime_error(
191  "Comparing two full array columns is not supported yet. Please consider "
192  "rewriting the full array comparison to a comparison between indexed array "
193  "columns "
194  "(i.e., arr1[1] {<, <=, >, >=} arr2[1]).");
195  }
196  }
197  auto lhs_bin_oper =
198  dynamic_cast<const Analyzer::BinOper*>(bin_oper->get_left_operand());
199  auto rhs_bin_oper =
200  dynamic_cast<const Analyzer::BinOper*>(bin_oper->get_right_operand());
201  // we can do (non-)equivalence check of two encoded string
202  // even if they are (indexed) array cols
203  auto theta_comp = IS_COMPARISON(bin_oper->get_optype()) &&
204  !IS_EQUIVALENCE(bin_oper->get_optype()) &&
205  bin_oper->get_optype() != SQLOps::kNE;
206  if (lhs_bin_oper && rhs_bin_oper && theta_comp &&
207  lhs_bin_oper->get_optype() == SQLOps::kARRAY_AT &&
208  rhs_bin_oper->get_optype() == SQLOps::kARRAY_AT) {
209  auto lhs_arr_cv =
210  dynamic_cast<const Analyzer::ColumnVar*>(lhs_bin_oper->get_left_operand());
211  auto lhs_arr_idx =
212  dynamic_cast<const Analyzer::Constant*>(lhs_bin_oper->get_right_operand());
213  auto rhs_arr_cv =
214  dynamic_cast<const Analyzer::ColumnVar*>(rhs_bin_oper->get_left_operand());
215  auto rhs_arr_idx =
216  dynamic_cast<const Analyzer::Constant*>(rhs_bin_oper->get_right_operand());
217  if (lhs_arr_cv && rhs_arr_cv && lhs_arr_idx && rhs_arr_idx &&
218  ((lhs_arr_cv->get_type_info().is_array() &&
219  lhs_arr_cv->get_type_info().get_subtype() == SQLTypes::kTEXT) ||
220  (rhs_arr_cv->get_type_info().is_string() &&
221  rhs_arr_cv->get_type_info().get_subtype() == SQLTypes::kTEXT))) {
222  throw std::runtime_error(
223  "Comparison between string array columns is not supported yet.");
224  }
225  }
226 }
#define IS_EQUIVALENCE(X)
Definition: sqldefs.h:69
const Expr * get_right_operand() const
Definition: Analyzer.h:456
SQLOps get_optype() const
Definition: Analyzer.h:452
Definition: sqltypes.h:79
Definition: sqldefs.h:31
const Expr * get_left_operand() const
Definition: Analyzer.h:455
#define IS_COMPARISON(X)
Definition: sqldefs.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{CompareIR.cpp}::icmp_arr_name ( const SQLOps  op_type)

Definition at line 64 of file CompareIR.cpp.

References kEQ, kGE, kGT, kLE, kLT, and kNE.

Referenced by CodeGenerator::codegenQualifierCmp().

64  {
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 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
Definition: sqldefs.h:31
Definition: sqldefs.h:32

+ Here is the caller graph for this function:

std::string anonymous_namespace{CompareIR.cpp}::icmp_name ( const SQLOps  op_type)

Definition at line 45 of file CompareIR.cpp.

References kEQ, kGE, kGT, kLE, kLT, and kNE.

Referenced by CodeGenerator::codegenCmp().

45  {
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 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
Definition: sqldefs.h:31
Definition: sqldefs.h:32

+ Here is the caller graph for this function:

llvm::CmpInst::Predicate anonymous_namespace{CompareIR.cpp}::llvm_fcmp_pred ( const SQLOps  op_type)

Definition at line 83 of file CompareIR.cpp.

References kEQ, kGE, kGT, kLE, kLT, and kNE.

Referenced by CodeGenerator::codegenCmp().

83  {
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 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
Definition: sqldefs.h:31
Definition: sqldefs.h:32

+ Here is the caller graph for this function:

llvm::CmpInst::Predicate anonymous_namespace{CompareIR.cpp}::llvm_icmp_pred ( const SQLOps  op_type)

Definition at line 26 of file CompareIR.cpp.

References kEQ, kGE, kGT, kLE, kLT, and kNE.

Referenced by CodeGenerator::codegenCmp().

26  {
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 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
Definition: sqldefs.h:31
Definition: sqldefs.h:32

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::BinOper> anonymous_namespace{CompareIR.cpp}::lower_bw_eq ( const Analyzer::BinOper bw_eq)

Definition at line 125 of file CompareIR.cpp.

References CHECK, Analyzer::Expr::get_contains_agg(), Analyzer::BinOper::get_own_left_operand(), Analyzer::BinOper::get_own_right_operand(), Analyzer::BinOper::get_qualifier(), Analyzer::Expr::get_type_info(), kAND, kBOOLEAN, kEQ, kISNULL, kONE, kOR, and Parser::OperExpr::normalize().

Referenced by CodeGenerator::codegenCmp(), and make_eq().

125  {
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 }
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, const Executor *executor=nullptr)
Definition: ParserNode.cpp:379
Definition: sqldefs.h:37
bool get_contains_agg() const
Definition: Analyzer.h:81
Definition: sqldefs.h:29
Definition: sqldefs.h:36
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
Definition: sqldefs.h:71
#define CHECK(condition)
Definition: Logger.h:291
const std::shared_ptr< Analyzer::Expr > get_own_right_operand() const
Definition: Analyzer.h:460
const std::shared_ptr< Analyzer::Expr > get_own_left_operand() const
Definition: Analyzer.h:457
SQLQualifier get_qualifier() const
Definition: Analyzer.h:454

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::BinOper> anonymous_namespace{CompareIR.cpp}::lower_multicol_compare ( const Analyzer::BinOper multicol_compare)

Definition at line 159 of file CompareIR.cpp.

References CHECK, CHECK_EQ, CHECK_GT, Analyzer::BinOper::get_left_operand(), Analyzer::BinOper::get_optype(), Analyzer::BinOper::get_right_operand(), kAND, kBOOLEAN, kONE, and make_eq().

Referenced by CodeGenerator::codegenCmp().

160  {
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 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const Expr * get_right_operand() const
Definition: Analyzer.h:456
#define CHECK_GT(x, y)
Definition: Logger.h:305
SQLOps get_optype() const
Definition: Analyzer.h:452
Definition: sqldefs.h:36
Definition: sqldefs.h:71
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
#define CHECK(condition)
Definition: Logger.h:291
const Expr * get_left_operand() const
Definition: Analyzer.h:455

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr<Analyzer::BinOper> anonymous_namespace{CompareIR.cpp}::make_eq ( const std::shared_ptr< Analyzer::Expr > &  lhs,
const std::shared_ptr< Analyzer::Expr > &  rhs,
const SQLOps  optype 
)

Definition at line 145 of file CompareIR.cpp.

References CHECK, IS_EQUIVALENCE, kBW_EQ, kONE, lower_bw_eq(), and Parser::OperExpr::normalize().

Referenced by lower_multicol_compare().

147  {
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 }
#define IS_EQUIVALENCE(X)
Definition: sqldefs.h:69
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, const Executor *executor=nullptr)
Definition: ParserNode.cpp:379
std::shared_ptr< Analyzer::BinOper > lower_bw_eq(const Analyzer::BinOper *bw_eq)
Definition: CompareIR.cpp:125
Definition: sqldefs.h:71
#define CHECK(condition)
Definition: Logger.h:291
Definition: sqldefs.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{CompareIR.cpp}::string_cmp_func ( const SQLOps  optype)

Definition at line 106 of file CompareIR.cpp.

References kEQ, kGE, kGT, kLE, kLT, and kNE.

Referenced by CodeGenerator::codegenCmp().

106  {
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 }
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:29
Definition: sqldefs.h:33
Definition: sqldefs.h:31
Definition: sqldefs.h:32

+ Here is the caller graph for this function: