OmniSciDB  a5dc49c757
 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)
 
size_t size () const final
 
SQLTypeInfo getNullType () const final
 
llvm::Value * codegenCmpEqNullptr (llvm::IRBuilder<> &builder, llvm::Value *arg_lv)
 
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)
 
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)
 
static char const * pointIsNullFunctionName (SQLTypeInfo const &)
 
- Protected Attributes inherited from spatial_type::Codegen
const Analyzer::GeoOperatoroperator_
 
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)
inline

Definition at line 26 of file PointAccessors.h.

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

26  : Codegen(geo_operator) {
27  CHECK_EQ(operator_->size(), size_t(1));
28  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
size_t size() const
Definition: Analyzer.cpp:4211
Codegen(const Analyzer::GeoOperator *geo_operator)
Definition: Codegen.h:28

+ 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 89 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_.

92  {
93  CHECK_EQ(args.size(), size_t(1));
94  const auto array_buff_ptr = args.front();
95 
96  const auto& geo_ti = getOperand(0)->get_type_info();
97  CHECK(geo_ti.is_geometry());
98  auto& builder = cgen_state->ir_builder_;
99 
100  const bool is_x = operator_->getName() == "ST_X";
101  const std::string expr_name = is_x ? "x" : "y";
102 
103  llvm::Value* coord_lv;
104  if (geo_ti.get_compression() == kENCODING_GEOINT) {
105  auto compressed_arr_ptr = builder.CreateBitCast(
106  array_buff_ptr, llvm::Type::getInt32PtrTy(cgen_state->context_));
107  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
108  auto coord_lv_ptr = builder.CreateGEP(
109  compressed_arr_ptr->getType()->getScalarType()->getPointerElementType(),
110  compressed_arr_ptr,
111  coord_index,
112  expr_name + "_coord_ptr");
113  auto compressed_coord_lv =
114  builder.CreateLoad(coord_lv_ptr->getType()->getPointerElementType(),
115  coord_lv_ptr,
116  expr_name + "_coord_compressed");
117 
118  coord_lv =
119  cgen_state->emitExternalCall("decompress_" + expr_name + "_coord_geoint",
120  llvm::Type::getDoubleTy(cgen_state->context_),
121  {compressed_coord_lv});
122  } else {
123  auto coord_arr_ptr = builder.CreateBitCast(
124  array_buff_ptr, llvm::Type::getDoublePtrTy(cgen_state->context_));
125  auto coord_index = is_x ? cgen_state->llInt(0) : cgen_state->llInt(1);
126  auto coord_lv_ptr = builder.CreateGEP(
127  coord_arr_ptr->getType()->getScalarType()->getPointerElementType(),
128  coord_arr_ptr,
129  coord_index,
130  expr_name + "_coord_ptr");
131  coord_lv = builder.CreateLoad(coord_lv_ptr->getType()->getPointerElementType(),
132  coord_lv_ptr,
133  expr_name + "_coord");
134  }
135 
136  auto ret = coord_lv;
137  if (is_nullable_) {
138  CHECK(nullcheck_codegen);
139  ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(SQLTypeInfo(kDOUBLE)),
140  ret);
141  }
142  const auto key = operator_->toString();
143  CHECK(cgen_state->geo_target_cache_.insert(std::make_pair(key, ret)).second);
144  return {ret};
145  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
std::unordered_map< std::string, llvm::Value * > geo_target_cache_
Definition: CgenState.h:404
llvm::LLVMContext & context_
Definition: CgenState.h:382
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.cpp:395
const std::string & getName() const
Definition: Analyzer.h:3298
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:249
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1530
#define CHECK(condition)
Definition: Logger.h:291
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:64
std::string toString() const override
Definition: Analyzer.cpp:4183
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:104

+ Here is the call graph for this function:

llvm::Value* spatial_type::PointAccessors::codegenCmpEqNullptr ( llvm::IRBuilder<> &  builder,
llvm::Value *  arg_lv 
)
inline

Definition at line 34 of file PointAccessors.h.

References CHECK.

Referenced by codegenLoads().

34  {
35  auto* const ptr_type = llvm::dyn_cast<llvm::PointerType>(arg_lv->getType());
36  CHECK(ptr_type);
37  return builder.CreateICmpEQ(arg_lv, llvm::ConstantPointerNull::get(ptr_type));
38  }
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller 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 41 of file PointAccessors.h.

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

44  {
45  CHECK_EQ(pos_lvs.size(), size());
46  auto operand = getOperand(0);
47  CHECK(operand);
48  const auto& geo_ti = operand->get_type_info();
49  CHECK(geo_ti.is_geometry());
50  auto& builder = cgen_state->ir_builder_;
51 
52  llvm::Value* array_buff_ptr{nullptr};
53  llvm::Value* is_null{nullptr};
54  if (arg_lvs.size() == 1) {
55  if (dynamic_cast<const Analyzer::GeoExpr*>(operand)) {
56  is_null = codegenCmpEqNullptr(builder, arg_lvs.front());
57  return std::make_tuple(arg_lvs, is_null);
58  }
59  // col byte stream, get the array buffer ptr and is null attributes and cache
61  arg_lvs.front(), pos_lvs.front(), geo_ti, cgen_state);
62  array_buff_ptr = arr_load_lvs.buffer;
63  is_null = arr_load_lvs.is_null;
64  } else {
65  // ptr and size
66  CHECK_EQ(arg_lvs.size(), size_t(2));
67  if (dynamic_cast<const Analyzer::GeoOperator*>(operand)) {
68  if (geo_ti.get_type() == kPOINT && !geo_ti.is_variable_size()) {
69  char const* const fname = pointIsNullFunctionName(geo_ti);
70  is_null = cgen_state->emitCall(fname, {arg_lvs.front()});
71  } else {
72  // The above branch tests for both nullptr and null sentinel, whereas this
73  // branch only tests for nullptr. If not for this branch, the GeospatialTest
74  // LLVMOptimization test fails due to non-removal of the
75  // decompress_{x,y}_coord_geoint function call in the generated IR. See QE-1007.
76  is_null = codegenCmpEqNullptr(builder, arg_lvs.front());
77  }
78  }
79  // TODO: nulls from other types not yet supported
80  array_buff_ptr = arg_lvs.front();
81  }
82  CHECK(array_buff_ptr) << operator_->toString();
83  if (!is_null) {
84  is_nullable_ = false;
85  }
86  return std::make_tuple(std::vector<llvm::Value*>{array_buff_ptr}, is_null);
87  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t size() const final
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
llvm::Value * codegenCmpEqNullptr(llvm::IRBuilder<> &builder, llvm::Value *arg_lv)
llvm::Value * buffer
Definition: CgenState.h:36
static char const * pointIsNullFunctionName(SQLTypeInfo const &)
Definition: Codegen.cpp:69
CONSTEXPR DEVICE bool is_null(const T &value)
llvm::Value * emitCall(const std::string &fname, const std::vector< llvm::Value * > &args)
Definition: CgenState.cpp:217
static ArrayLoadCodegen codegenGeoArrayLoadAndNullcheck(llvm::Value *byte_stream, llvm::Value *pos, const SQLTypeInfo &ti, CgenState *cgen_state)
Definition: GeoIR.cpp:25
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
#define CHECK(condition)
Definition: Logger.h:291
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:64
std::string toString() const override
Definition: Analyzer.cpp:4183

+ 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); }
size_t spatial_type::PointAccessors::size ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 30 of file PointAccessors.h.

Referenced by codegenLoads().

30 { return 1; }

+ Here is the caller graph for this function:


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