OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
spatial_type::PointConstructor Class Reference

#include <PointConstructor.h>

+ Inheritance diagram for spatial_type::PointConstructor:
+ Collaboration diagram for spatial_type::PointConstructor:

Public Member Functions

 PointConstructor (const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
 
std::unique_ptr
< CodeGenerator::NullCheckCodegen
getNullCheckCodegen (llvm::Value *null_lv, CgenState *cgen_state, Executor *executor) final
 
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 const Analyzer::ExprgetOperand (const size_t index)
 
virtual ~Codegen ()
 

Private Attributes

llvm::AllocaInst * pt_local_storage_lv_ {nullptr}
 

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 26 of file PointConstructor.h.

Constructor & Destructor Documentation

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

Definition at line 28 of file PointConstructor.h.

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

30  : Codegen(geo_operator, catalog) {
31  CHECK_EQ(operator_->size(), size_t(2));
32  const auto& ti = geo_operator->get_type_info();
33  if (ti.get_notnull()) {
34  is_nullable_ = false;
35  } else {
36  is_nullable_ = true;
37  }
38  }
Codegen(const Analyzer::GeoOperator *geo_operator, const Catalog_Namespace::Catalog *catalog)
Definition: Codegen.h:28
#define CHECK_EQ(x, y)
Definition: Logger.h:230
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
size_t size() const
Definition: Analyzer.cpp:3913

+ Here is the call graph for this function:

Member Function Documentation

std::vector<llvm::Value*> spatial_type::PointConstructor::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 158 of file PointConstructor.h.

References run_benchmark_import::args, CHECK, CHECK_EQ, Analyzer::Expr::get_type_info(), kENCODING_GEOINT, kPOINT, spatial_type::Codegen::operator_, and pt_local_storage_lv_.

161  {
162  CHECK_EQ(args.size(), size_t(2));
163 
164  const auto& geo_ti = operator_->get_type_info();
165  CHECK(geo_ti.get_type() == kPOINT);
166 
167  auto& builder = cgen_state->ir_builder_;
169 
170  const bool is_compressed = geo_ti.get_compression() == kENCODING_GEOINT;
171 
172  // store x coord
173  auto x_coord_ptr = builder.CreateGEP(
174  pt_local_storage_lv_->getType()->getScalarType()->getPointerElementType(),
176  {cgen_state->llInt(0), cgen_state->llInt(0)},
177  "x_coord_ptr");
178  if (is_compressed) {
179  auto compressed_lv =
180  cgen_state->emitExternalCall("compress_x_coord_geoint",
181  llvm::Type::getInt32Ty(cgen_state->context_),
182  {args.front()});
183  builder.CreateStore(compressed_lv, x_coord_ptr);
184  } else {
185  builder.CreateStore(args.front(), x_coord_ptr);
186  }
187 
188  // store y coord
189  auto y_coord_ptr = builder.CreateGEP(
190  pt_local_storage_lv_->getType()->getScalarType()->getPointerElementType(),
192  {cgen_state->llInt(0), cgen_state->llInt(1)},
193  "y_coord_ptr");
194  if (is_compressed) {
195  auto compressed_lv =
196  cgen_state->emitExternalCall("compress_y_coord_geoint",
197  llvm::Type::getInt32Ty(cgen_state->context_),
198  {args.back()});
199  builder.CreateStore(compressed_lv, y_coord_ptr);
200  } else {
201  builder.CreateStore(args.back(), y_coord_ptr);
202  }
203 
204  llvm::Value* ret = pt_local_storage_lv_;
205  if (is_nullable_) {
206  CHECK(nullcheck_codegen);
207  ret = nullcheck_codegen->finalize(ret, ret);
208  }
209  return {builder.CreateBitCast(ret,
210  geo_ti.get_compression() == kENCODING_GEOINT
211  ? llvm::Type::getInt32PtrTy(cgen_state->context_)
212  : llvm::Type::getDoublePtrTy(cgen_state->context_)),
213  cgen_state->llInt(static_cast<int32_t>(
214  geo_ti.get_compression() == kENCODING_GEOINT ? 8 : 16))};
215  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
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:217
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
llvm::LLVMContext & context_
Definition: CgenState.h:439
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
llvm::AllocaInst * pt_local_storage_lv_
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:306
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1437
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

std::tuple<std::vector<llvm::Value*>, llvm::Value*> spatial_type::PointConstructor::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 87 of file PointConstructor.h.

References CHECK, CHECK_EQ, Analyzer::Expr::get_type_info(), Analyzer::GeoOperator::getName(), spatial_type::Codegen::getOperand(), inline_fp_null_val(), inline_int_null_val(), is_null(), spatial_type::Codegen::is_nullable_, kENCODING_GEOINT, kENCODING_NONE, kPOINT, spatial_type::Codegen::operator_, pt_local_storage_lv_, and size().

90  {
91  CHECK_EQ(pos_lvs.size(),
92  size()); // note both pos arguments should be the same, as both inputs are
93  // expected to be from the same table, though this is moot in this
94  // function as position argumnts are not used here
95  CHECK_EQ(arg_lvs.size(), size_t(2));
96 
97  auto& builder = cgen_state->ir_builder_;
98 
99  llvm::Value* is_null{nullptr};
100  auto x_operand = getOperand(0);
101  const auto& x_ti = x_operand->get_type_info();
102  if (!x_ti.get_notnull()) {
103  CHECK(x_ti.is_integer() || x_ti.is_fp());
104  // TODO: centralize nullcheck logic for all sqltypes
105  is_null = x_ti.is_integer()
106  ? builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
107  arg_lvs.front(),
108  cgen_state->llInt(inline_int_null_val(x_ti)))
109  : builder.CreateFCmp(llvm::FCmpInst::FCMP_OEQ,
110  arg_lvs.front(),
111  cgen_state->llFp(inline_fp_null_val(x_ti)));
112  }
113 
114  auto y_operand = getOperand(1);
115  const auto& y_ti = y_operand->get_type_info();
116  if (!y_ti.get_notnull()) {
117  auto y_is_null =
118  y_ti.is_integer()
119  ? builder.CreateICmp(llvm::CmpInst::ICMP_EQ,
120  arg_lvs.front(),
121  cgen_state->llInt(inline_int_null_val(y_ti)))
122  : builder.CreateFCmp(llvm::FCmpInst::FCMP_OEQ,
123  arg_lvs.front(),
124  cgen_state->llFp(inline_fp_null_val(y_ti)));
125  if (is_null) {
126  // the point is null if at least one of its coordinate has null value
127  is_null = builder.CreateOr(is_null, y_is_null);
128  } else {
129  is_null = y_is_null;
130  }
131  }
132 
133  if (is_nullable_ && !is_null) {
134  // if the inputs are not null, set the output to be not null
135  // TODO: we should do this in the translator and just confirm it here
136  is_nullable_ = false;
137  }
138 
139  // do the alloca before nullcheck codegen, as either way we will return a point array
140  const auto& geo_ti = operator_->get_type_info();
141  CHECK(geo_ti.get_type() == kPOINT);
142 
143  llvm::ArrayType* arr_type{nullptr};
144  if (geo_ti.get_compression() == kENCODING_GEOINT) {
145  auto elem_ty = llvm::Type::getInt32Ty(cgen_state->context_);
146  arr_type = llvm::ArrayType::get(elem_ty, 2);
147  } else {
148  CHECK(geo_ti.get_compression() == kENCODING_NONE);
149  auto elem_ty = llvm::Type::getDoubleTy(cgen_state->context_);
150  arr_type = llvm::ArrayType::get(elem_ty, 2);
151  }
153  builder.CreateAlloca(arr_type, nullptr, operator_->getName() + "_Local_Storage");
154 
155  return std::make_tuple(arg_lvs, is_null);
156  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
llvm::IRBuilder ir_builder_
Definition: CgenState.h:441
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
llvm::LLVMContext & context_
Definition: CgenState.h:439
CONSTEXPR DEVICE bool is_null(const T &value)
const std::string & getName() const
Definition: Analyzer.h:2775
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:310
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
llvm::AllocaInst * pt_local_storage_lv_
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:306
#define CHECK(condition)
Definition: Logger.h:222
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:63
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

std::unique_ptr<CodeGenerator::NullCheckCodegen> spatial_type::PointConstructor::getNullCheckCodegen ( llvm::Value *  null_lv,
CgenState cgen_state,
Executor executor 
)
inlinefinalvirtual

Reimplemented from spatial_type::Codegen.

Definition at line 40 of file PointConstructor.h.

References CHECK, CHECK_EQ, Analyzer::Expr::get_type_info(), spatial_type::Codegen::getName(), getNullType(), inline_int_null_val(), spatial_type::Codegen::isNullable(), kENCODING_GEOINT, kINT, NULL_ARRAY_DOUBLE, spatial_type::Codegen::operator_, and pt_local_storage_lv_.

43  {
44  if (isNullable()) {
45  // do the standard nullcheck codegen, but modify the null basic block to emplace the
46  // null sentinel into the array
47  auto nullcheck_codegen = std::make_unique<CodeGenerator::NullCheckCodegen>(
48  cgen_state, executor, null_lv, getNullType(), getName() + "_nullcheck");
49 
50  auto& builder = cgen_state->ir_builder_;
52 
53  auto prev_insert_block = builder.GetInsertBlock();
54  auto crt_insert_block = nullcheck_codegen->null_check->cond_true_;
55  CHECK(crt_insert_block);
56  auto& instruction_list = crt_insert_block->getInstList();
57  CHECK_EQ(instruction_list.size(), size_t(1));
58  builder.SetInsertPoint(crt_insert_block, instruction_list.begin());
59 
60  auto x_coord_ptr = builder.CreateGEP(
61  pt_local_storage_lv_->getType()->getScalarType()->getPointerElementType(),
63  {cgen_state->llInt(0), cgen_state->llInt(0)},
64  "x_coord_ptr");
65  const auto& geo_ti = operator_->get_type_info();
66  if (geo_ti.get_compression() == kENCODING_GEOINT) {
67  // TODO: probably wrong
68  builder.CreateStore(cgen_state->llInt(inline_int_null_val(SQLTypeInfo(kINT))),
69  x_coord_ptr);
70  } else {
71  builder.CreateStore(cgen_state->llFp(static_cast<double>(NULL_ARRAY_DOUBLE)),
72  x_coord_ptr);
73  }
74  builder.SetInsertPoint(prev_insert_block);
75 
76  return nullcheck_codegen;
77  } else {
78  return nullptr;
79  }
80  }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
SQLTypeInfo getNullType() const final
auto isNullable() const
Definition: Codegen.h:35
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:82
llvm::AllocaInst * pt_local_storage_lv_
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:70
#define NULL_ARRAY_DOUBLE
#define CHECK(condition)
Definition: Logger.h:222
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
std::string getName() const
Definition: Codegen.h:39
Definition: sqltypes.h:59

+ Here is the call graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 84 of file PointConstructor.h.

References kBOOLEAN.

Referenced by getNullCheckCodegen().

84 { return SQLTypeInfo(kBOOLEAN); }

+ Here is the caller graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 82 of file PointConstructor.h.

Referenced by codegenLoads().

82 { return 2; }

+ Here is the caller graph for this function:

Member Data Documentation

llvm::AllocaInst* spatial_type::PointConstructor::pt_local_storage_lv_ {nullptr}
private

Definition at line 218 of file PointConstructor.h.

Referenced by codegen(), codegenLoads(), and getNullCheckCodegen().


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