OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StartEndPoint.h
Go to the documentation of this file.
1 /*
2  * Copyright 2021 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 #pragma once
18 
20 
21 namespace spatial_type {
22 
23 class StartEndPoint : public Codegen {
24  public:
25  StartEndPoint(const Analyzer::GeoOperator* geo_operator,
26  const Catalog_Namespace::Catalog* catalog)
27  : Codegen(geo_operator, catalog) {
28  // nulls not supported yet
29  this->is_nullable_ = false;
30  }
31 
32  size_t size() const final { return 1; }
33 
35 
36  const Analyzer::Expr* getPositionOperand() const final { return nullptr; }
37 
38  const Analyzer::Expr* getOperand(const size_t index) final {
39  CHECK_EQ(operator_->size(), size_t(1));
40  CHECK_EQ(index, size_t(0));
41 
42  const auto geo_arg = operator_->getOperand(0);
43  const auto geo_arg_expr = dynamic_cast<const Analyzer::GeoExpr*>(geo_arg);
44  CHECK(geo_arg_expr) << geo_arg->toString();
45  return geo_arg;
46  }
47 
48  // returns arguments lvs and null lv
49  std::tuple<std::vector<llvm::Value*>, llvm::Value*> codegenLoads(
50  const std::vector<llvm::Value*>& arg_lvs,
51  llvm::Value* pos_lv,
52  CgenState* cgen_state) final {
53  CHECK_EQ(arg_lvs.size(), size_t(2)); // ptr, size
54  return std::make_tuple(arg_lvs, nullptr);
55  }
56 
57  std::vector<llvm::Value*> codegen(const std::vector<llvm::Value*>& args,
58  CodeGenerator::NullCheckCodegen* nullcheck_codegen,
59  CgenState* cgen_state) final {
60  CHECK_EQ(args.size(), size_t(2)); // ptr, size
61  const auto& geo_ti = getOperand(0)->get_type_info();
62  CHECK(geo_ti.is_geometry());
63 
64  auto& builder = cgen_state->ir_builder_;
65  llvm::Value* array_buff_cast{nullptr};
66  int32_t elem_size_bytes = 0;
67  if (geo_ti.get_compression() == kENCODING_GEOINT) {
68  array_buff_cast = builder.CreateBitCast(
69  args.front(), llvm::Type::getInt32PtrTy(cgen_state->context_));
70  elem_size_bytes = 4; // 4-byte ints
71  } else {
72  array_buff_cast = builder.CreateBitCast(
73  args.front(), llvm::Type::getDoublePtrTy(cgen_state->context_));
74  elem_size_bytes = 8; // doubles
75  }
76  CHECK_GT(elem_size_bytes, 0);
77 
78  const auto num_elements_lv =
79  builder.CreateSDiv(args.back(), cgen_state->llInt(elem_size_bytes));
80  const auto end_index_lv =
81  builder.CreateSub(num_elements_lv, cgen_state->llInt(int32_t(2)));
82  auto array_offset_lv = builder.CreateGEP(
83  array_buff_cast, end_index_lv, operator_->getName() + "_Offset");
84  return {array_offset_lv, args.back()};
85  }
86 };
87 
88 } // namespace spatial_type
#define CHECK_EQ(x, y)
Definition: Logger.h:214
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:102
#define const
std::vector< llvm::Value * > codegen(const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state) final
Definition: StartEndPoint.h:57
#define CHECK_GT(x, y)
Definition: Logger.h:218
const Analyzer::Expr * getPositionOperand() const final
Definition: StartEndPoint.h:36
std::tuple< std::vector< llvm::Value * >, llvm::Value * > codegenLoads(const std::vector< llvm::Value * > &arg_lvs, llvm::Value *pos_lv, CgenState *cgen_state) final
Definition: StartEndPoint.h:49
const std::string & getName() const
Definition: Analyzer.h:1749
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
size_t size() const final
Definition: StartEndPoint.h:32
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:64
size_t size() const
Definition: Analyzer.cpp:3445
#define CHECK(condition)
Definition: Logger.h:206
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:3449
StartEndPoint(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: StartEndPoint.h:25
SQLTypeInfo getNullType() const final
Definition: StartEndPoint.h:34
const Analyzer::Expr * getOperand(const size_t index) final
Definition: StartEndPoint.h:38