OmniSciDB  d2f719934e
 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
 
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) 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 const Analyzer::ExprgetOperand (const size_t index)
 
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.

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

28  : Codegen(geo_operator, catalog) {
29  CHECK_EQ(operator_->size(), size_t(1));
30  }
Codegen(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.h:28
#define CHECK_EQ(x, y)
Definition: Logger.h:219
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
size_t size() const
Definition: Analyzer.cpp:3644

+ Here is the call graph for this function:

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 90 of file PointAccessors.h.

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

93  {
94  CHECK_EQ(args.size(), size_t(1));
95  const auto array_buff_ptr = args.front();
96 
97  const auto& geo_ti = getOperand(0)->get_type_info();
98  CHECK(geo_ti.is_geometry());
99  auto& builder = cgen_state->ir_builder_;
100 
101  const bool is_x = operator_->getName() == "ST_X";
102  const std::string expr_name = is_x ? "x" : "y";
103 
104  llvm::Value* coord_lv;
105  if (geo_ti.get_compression() == kENCODING_GEOINT) {
106  auto compressed_arr_ptr = builder.CreateBitCast(
107  array_buff_ptr, llvm::Type::getInt32PtrTy(cgen_state->context_));
108  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
109  auto coord_lv_ptr =
110  builder.CreateGEP(compressed_arr_ptr, coord_index, expr_name + "_coord_ptr");
111  auto compressed_coord_lv =
112  builder.CreateLoad(coord_lv_ptr, expr_name + "_coord_compressed");
113 
114  coord_lv =
115  cgen_state->emitExternalCall("decompress_" + expr_name + "_coord_geoint",
116  llvm::Type::getDoubleTy(cgen_state->context_),
117  {compressed_coord_lv});
118  } else {
119  auto coord_arr_ptr = builder.CreateBitCast(
120  array_buff_ptr, llvm::Type::getDoublePtrTy(cgen_state->context_));
121  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
122  auto coord_lv_ptr =
123  builder.CreateGEP(coord_arr_ptr, coord_index, expr_name + "_coord_ptr");
124  coord_lv = builder.CreateLoad(coord_lv_ptr, expr_name + "_coord");
125  }
126 
127  auto ret = coord_lv;
128  if (is_nullable_) {
129  CHECK(nullcheck_codegen);
130  ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(SQLTypeInfo(kDOUBLE)),
131  ret);
132  }
133  const auto key = operator_->toString();
134  CHECK(cgen_state->geo_target_cache_.insert(std::make_pair(key, ret)).second);
135  return {ret};
136  }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
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
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:1925
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
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:1447
#define CHECK(condition)
Definition: Logger.h:211
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:63
std::string toString() const override
Definition: Analyzer.cpp:3616
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,
const std::vector< llvm::Value * > &  pos_lvs,
CgenState cgen_state 
)
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 37 of file PointAccessors.h.

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

40  {
41  CHECK_EQ(pos_lvs.size(), size());
42  auto operand = getOperand(0);
43  CHECK(operand);
44  const auto& geo_ti = operand->get_type_info();
45  CHECK(geo_ti.is_geometry());
46  auto& builder = cgen_state->ir_builder_;
47 
48  llvm::Value* array_buff_ptr{nullptr};
49  llvm::Value* is_null{nullptr};
50  if (arg_lvs.size() == 1) {
51  if (dynamic_cast<const Analyzer::GeoExpr*>(operand)) {
52  const auto ptr_type =
53  llvm::dyn_cast<llvm::PointerType>(arg_lvs.front()->getType());
54  CHECK(ptr_type);
55  const auto is_null_lv =
56  builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
57  arg_lvs.front(),
58  llvm::ConstantPointerNull::get(ptr_type));
59  return std::make_tuple(arg_lvs, is_null_lv);
60  }
61  // col byte stream, get the array buffer ptr and is null attributes and cache
63  arg_lvs.front(), pos_lvs.front(), geo_ti, cgen_state);
64  array_buff_ptr = arr_load_lvs.buffer;
65  is_null = arr_load_lvs.is_null;
66  } else {
67  // ptr and size
68  CHECK_EQ(arg_lvs.size(), size_t(2));
69  if (dynamic_cast<const Analyzer::GeoOperator*>(operand)) {
70  // null check will be if the ptr is a nullptr
71  is_null = builder.CreateICmp(
72  llvm::CmpInst::ICMP_EQ,
73  arg_lvs.front(),
74  llvm::ConstantPointerNull::get( // TODO: check ptr address space
75  geo_ti.get_compression() == kENCODING_GEOINT
76  ? llvm::Type::getInt32PtrTy(cgen_state->context_)
77  : llvm::Type::getDoublePtrTy(cgen_state->context_)));
78  }
79 
80  // TODO: nulls from other types not yet supported
81  array_buff_ptr = arg_lvs.front();
82  }
83  CHECK(array_buff_ptr) << operator_->toString();
84  if (!is_null) {
85  is_nullable_ = false;
86  }
87  return std::make_tuple(std::vector<llvm::Value*>{array_buff_ptr}, is_null);
88  }
#define CHECK_EQ(x, y)
Definition: Logger.h:219
size_t size() const final
llvm::IRBuilder ir_builder_
Definition: CgenState.h:340
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:70
#define CHECK(condition)
Definition: Logger.h:211
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:63
std::string toString() const override
Definition: Analyzer.cpp:3616

+ Here is the call graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 34 of file PointAccessors.h.

References kBOOLEAN.

34 { return SQLTypeInfo(kBOOLEAN); }
size_t spatial_type::PointAccessors::size ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 32 of file PointAccessors.h.

Referenced by codegenLoads().

32 { return 1; }

+ Here is the caller graph for this function:


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