OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spatial_type::PointAccessors Class Reference

#include <PointAccessors.h>

+ Inheritance diagram for spatial_type::PointAccessors:
+ Collaboration diagram for spatial_type::PointAccessors:

Public Member Functions

 PointAccessors (const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
 
size_t size () const final
 
SQLTypeInfo getNullType () const final
 
const Analyzer::ExprgetPositionOperand () const final
 
const Analyzer::ExprgetOperand (const size_t index) final
 
std::tuple< std::vector
< llvm::Value * >, llvm::Value * > 
codegenLoads (const std::vector< llvm::Value * > &arg_lvs, llvm::Value *pos_lv, CgenState *cgen_state) final
 
std::vector< llvm::Value * > codegen (const std::vector< llvm::Value * > &args, CodeGenerator::NullCheckCodegen *nullcheck_codegen, CgenState *cgen_state, const CompilationOptions &co) final
 
- Public Member Functions inherited from spatial_type::Codegen
 Codegen (const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
 
auto isNullable () const
 
auto getTypeInfo () const
 
std::string getName () const
 
virtual std::unique_ptr
< CodeGenerator::NullCheckCodegen
getNullCheckCodegen (llvm::Value *null_lv, CgenState *cgen_state, Executor *executor)
 
virtual ~Codegen ()
 

Additional Inherited Members

- Static Public Member Functions inherited from spatial_type::Codegen
static std::unique_ptr< Codegeninit (const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
 
- Protected Attributes inherited from spatial_type::Codegen
const Analyzer::GeoOperatoroperator_
 
const Catalog_Namespace::Catalogcat_
 
bool is_nullable_ {true}
 

Detailed Description

Definition at line 24 of file PointAccessors.h.

Constructor & Destructor Documentation

spatial_type::PointAccessors::PointAccessors ( const Analyzer::GeoOperator geo_operator,
const Catalog_Namespace::Catalog catalog 
)
inline

Definition at line 26 of file PointAccessors.h.

28  : Codegen(geo_operator, catalog) {}
Codegen(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.h:27

Member Function Documentation

std::vector<llvm::Value*> spatial_type::PointAccessors::codegen ( const std::vector< llvm::Value * > &  args,
CodeGenerator::NullCheckCodegen nullcheck_codegen,
CgenState cgen_state,
const CompilationOptions co 
)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 97 of file PointAccessors.h.

References run_benchmark_import::args, CHECK, CHECK_EQ, Analyzer::Expr::get_type_info(), Analyzer::GeoOperator::getName(), getOperand(), kENCODING_GEOINT, and spatial_type::Codegen::operator_.

100  {
101  CHECK_EQ(args.size(), size_t(1));
102  const auto array_buff_ptr = args.front();
103 
104  const auto& geo_ti = getOperand(0)->get_type_info();
105  CHECK(geo_ti.is_geometry());
106  auto& builder = cgen_state->ir_builder_;
107 
108  const bool is_x = operator_->getName() == "ST_X";
109  const std::string expr_name = is_x ? "x" : "y";
110 
111  llvm::Value* coord_lv;
112  if (geo_ti.get_compression() == kENCODING_GEOINT) {
113  auto compressed_arr_ptr = builder.CreateBitCast(
114  array_buff_ptr, llvm::Type::getInt32PtrTy(cgen_state->context_));
115  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
116  auto coord_lv_ptr =
117  builder.CreateGEP(compressed_arr_ptr, coord_index, expr_name + "_coord_ptr");
118  auto compressed_coord_lv =
119  builder.CreateLoad(coord_lv_ptr, expr_name + "_coord_compressed");
120 
121  coord_lv =
122  cgen_state->emitExternalCall("decompress_" + expr_name + "_coord_geoint",
123  llvm::Type::getDoubleTy(cgen_state->context_),
124  {compressed_coord_lv});
125  } else {
126  auto coord_arr_ptr = builder.CreateBitCast(
127  array_buff_ptr, llvm::Type::getDoublePtrTy(cgen_state->context_));
128  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
129  auto coord_lv_ptr =
130  builder.CreateGEP(coord_arr_ptr, coord_index, expr_name + "_coord_ptr");
131  coord_lv = builder.CreateLoad(coord_lv_ptr, expr_name + "_coord");
132  }
133 
134  auto ret = coord_lv;
135  if (is_nullable_) {
136  CHECK(nullcheck_codegen);
137  ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(SQLTypeInfo(kDOUBLE)),
138  ret);
139  }
140  const auto key = operator_->toString();
141  CHECK(cgen_state->geo_target_cache_.insert(std::make_pair(key, ret)).second);
142  return {ret};
143  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
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:228
llvm::IRBuilder ir_builder_
Definition: CgenState.h:340
const Analyzer::Expr * getOperand(const size_t index) final
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
Definition: CgenState.h:357
llvm::LLVMContext & context_
Definition: CgenState.h:338
const std::string & getName() const
Definition: Analyzer.h:1759
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:68
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:307
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1036
#define CHECK(condition)
Definition: Logger.h:206
std::string toString() const override
Definition: Analyzer.cpp:3470
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:67

+ Here is the call graph for this function:

std::tuple<std::vector<llvm::Value*>, llvm::Value*> spatial_type::PointAccessors::codegenLoads ( const std::vector< llvm::Value * > &  arg_lvs,
llvm::Value *  pos_lv,
CgenState cgen_state 
)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 45 of file PointAccessors.h.

References ArrayLoadCodegen::buffer, CHECK, CHECK_EQ, CodeGenerator::codegenGeoArrayLoadAndNullcheck(), getOperand(), is_null(), spatial_type::Codegen::is_nullable_, kENCODING_GEOINT, spatial_type::Codegen::operator_, and Analyzer::GeoOperator::toString().

48  {
49  auto operand = getOperand(0);
50  CHECK(operand);
51  const auto& geo_ti = operand->get_type_info();
52  CHECK(geo_ti.is_geometry());
53  auto& builder = cgen_state->ir_builder_;
54 
55  llvm::Value* array_buff_ptr{nullptr};
56  llvm::Value* is_null{nullptr};
57  if (arg_lvs.size() == 1) {
58  if (dynamic_cast<const Analyzer::GeoExpr*>(operand)) {
59  const auto ptr_type =
60  llvm::dyn_cast<llvm::PointerType>(arg_lvs.front()->getType());
61  CHECK(ptr_type);
62  const auto is_null_lv =
63  builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
64  arg_lvs.front(),
65  llvm::ConstantPointerNull::get(ptr_type));
66  return std::make_tuple(arg_lvs, is_null_lv);
67  }
68  // col byte stream, get the array buffer ptr and is null attributes and cache
70  arg_lvs.front(), pos_lv, geo_ti, cgen_state);
71  array_buff_ptr = arr_load_lvs.buffer;
72  is_null = arr_load_lvs.is_null;
73  } else {
74  // ptr and size
75  CHECK_EQ(arg_lvs.size(), size_t(2));
76  if (dynamic_cast<const Analyzer::GeoOperator*>(operand)) {
77  // null check will be if the ptr is a nullptr
78  is_null = builder.CreateICmp(
79  llvm::CmpInst::ICMP_EQ,
80  arg_lvs.front(),
81  llvm::ConstantPointerNull::get( // TODO: check ptr address space
82  geo_ti.get_compression() == kENCODING_GEOINT
83  ? llvm::Type::getInt32PtrTy(cgen_state->context_)
84  : llvm::Type::getDoublePtrTy(cgen_state->context_)));
85  }
86 
87  // TODO: nulls from other types not yet supported
88  array_buff_ptr = arg_lvs.front();
89  }
90  CHECK(array_buff_ptr) << operator_->toString();
91  if (!is_null) {
92  is_nullable_ = false;
93  }
94  return std::make_tuple(std::vector<llvm::Value*>{array_buff_ptr}, is_null);
95  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
llvm::IRBuilder ir_builder_
Definition: CgenState.h:340
const Analyzer::Expr * getOperand(const size_t index) final
llvm::Value * buffer
Definition: CgenState.h:32
llvm::LLVMContext & context_
Definition: CgenState.h:338
CONSTEXPR DEVICE bool is_null(const T &value)
static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)
Definition: GeoIR.cpp:23
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:68
#define CHECK(condition)
Definition: Logger.h:206
std::string toString() const override
Definition: Analyzer.cpp:3470

+ Here is the call graph for this function:

SQLTypeInfo spatial_type::PointAccessors::getNullType ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 32 of file PointAccessors.h.

References kBOOLEAN.

32 { return SQLTypeInfo(kBOOLEAN); }
const Analyzer::Expr* spatial_type::PointAccessors::getOperand ( const size_t  index)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 38 of file PointAccessors.h.

References CHECK_EQ, Analyzer::GeoOperator::getOperand(), spatial_type::Codegen::operator_, and Analyzer::GeoOperator::size().

Referenced by codegen(), and codegenLoads().

38  {
39  CHECK_EQ(operator_->size(), size_t(1));
40  CHECK_EQ(index, size_t(0));
41  return operator_->getOperand(0);
42  }
#define CHECK_EQ(x, y)
Definition: Logger.h:214
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:68
size_t size() const
Definition: Analyzer.cpp:3498
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:3502

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Analyzer::Expr* spatial_type::PointAccessors::getPositionOperand ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 34 of file PointAccessors.h.

References Analyzer::GeoOperator::getOperand(), and spatial_type::Codegen::operator_.

34  {
35  return operator_->getOperand(0);
36  }
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:68
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:3502

+ Here is the call graph for this function:

size_t spatial_type::PointAccessors::size ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 30 of file PointAccessors.h.

30 { return 1; }

The documentation for this class was generated from the following file: