OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Codegen.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 #include "Analyzer/Analyzer.h"
18 #include "Catalog/Catalog.h"
20 #include "Shared/sqltypes.h"
21 
22 #pragma once
23 
24 namespace spatial_type {
25 
26 class Codegen {
27  public:
28  Codegen(const Analyzer::GeoOperator* geo_operator,
29  const Catalog_Namespace::Catalog* catalog)
30  : operator_(geo_operator), cat_(catalog) {}
31 
32  static std::unique_ptr<Codegen> init(const Analyzer::GeoOperator* geo_operator,
33  const Catalog_Namespace::Catalog* catalog);
34 
35  auto isNullable() const { return is_nullable_; }
36 
37  auto getTypeInfo() const { return operator_->get_type_info(); }
38 
39  std::string getName() const { return operator_->getName(); }
40 
41  virtual std::unique_ptr<CodeGenerator::NullCheckCodegen>
42  getNullCheckCodegen(llvm::Value* null_lv, CgenState* cgen_state, Executor* executor);
43 
44  // number of loads/arguments for the operator
45  virtual size_t size() const = 0;
46 
47  virtual SQLTypeInfo getNullType() const = 0;
48 
49  // by default index into the operator, but allow overloading for special cases. In those
50  // special cases, we typically create a synthethic operator and manipulate state, so
51  // this method cannot be const
52  virtual const Analyzer::Expr* getOperand(const size_t index);
53 
54  // returns arguments lvs and null lv
55  virtual std::tuple<std::vector<llvm::Value*>, llvm::Value*> codegenLoads(
56  const std::vector<llvm::Value*>& arg_lvs,
57  const std::vector<llvm::Value*>& pos_lvs,
58  CgenState* cgen_state) = 0;
59 
60  // codegen function operation post loads
61  virtual std::vector<llvm::Value*> codegen(
62  const std::vector<llvm::Value*>& args,
63  CodeGenerator::NullCheckCodegen* nullcheck_codegen,
64  CgenState* cgen_state,
65  const CompilationOptions& co) = 0;
66 
67  virtual ~Codegen() {}
68 
69  protected:
72  bool is_nullable_{true};
73 };
74 
75 std::string suffix(SQLTypes type);
76 
77 } // namespace spatial_type
Codegen(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.h:28
Defines data structures for the semantic analysis phase of query processing.
virtual ~Codegen()
Definition: Codegen.h:67
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:111
SQLTypes
Definition: sqltypes.h:38
virtual std::tuple< std::vector< llvm::Value * >, llvm::Value * > codegenLoads(const std::vector< llvm::Value * > &arg_lvs, const std::vector< llvm::Value * > &pos_lvs, CgenState *cgen_state)=0
virtual size_t size() const =0
Constants for Builtin SQL Types supported by OmniSci.
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:68
auto getTypeInfo() const
Definition: Codegen.h:37
This file contains the class specification and related data structures for Catalog.
virtual std::vector< llvm::Value * > codegen(const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co)=0
const std::string & getName() const
Definition: Analyzer.h:1925
const Catalog_Namespace::Catalog * cat_
Definition: Codegen.h:71
auto isNullable() const
Definition: Codegen.h:35
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
virtual SQLTypeInfo getNullType() const =0
virtual std::unique_ptr< CodeGenerator::NullCheckCodegen > getNullCheckCodegen(llvm::Value *null_lv, CgenState *cgen_state, Executor *executor)
Definition: Codegen.cpp:50
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:63
std::string getName() const
Definition: Codegen.h:39
static std::unique_ptr< Codegen > init(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.cpp:22