OmniSciDB  a5dc49c757
 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)
 
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)
 
auto isNullable () const
 
auto getTypeInfo () const
 
std::string getName () const
 
virtual const Analyzer::ExprgetOperand (const size_t index)
 
virtual ~Codegen ()
 

Private Member Functions

llvm::Value * codegenOperandIsNull (size_t idx, llvm::Value *value, CgenState *cgen_state)
 

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

Constructor & Destructor Documentation

spatial_type::PointConstructor::PointConstructor ( const Analyzer::GeoOperator geo_operator)
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().

28  : Codegen(geo_operator) {
29  CHECK_EQ(operator_->size(), size_t(2));
30  const auto& ti = geo_operator->get_type_info();
31  if (ti.get_notnull()) {
32  is_nullable_ = false;
33  } else {
34  is_nullable_ = true;
35  }
36  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
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::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 127 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_.

130  {
131  CHECK_EQ(args.size(), size_t(2));
132 
133  const auto& geo_ti = operator_->get_type_info();
134  CHECK(geo_ti.get_type() == kPOINT);
135 
136  auto& builder = cgen_state->ir_builder_;
138 
139  const bool is_compressed = geo_ti.get_compression() == kENCODING_GEOINT;
140 
141  // store x coord
142  auto x_coord_ptr = builder.CreateGEP(
143  pt_local_storage_lv_->getType()->getScalarType()->getPointerElementType(),
145  {cgen_state->llInt(0), cgen_state->llInt(0)},
146  "x_coord_ptr");
147  if (is_compressed) {
148  auto compressed_lv =
149  cgen_state->emitExternalCall("compress_x_coord_geoint",
150  llvm::Type::getInt32Ty(cgen_state->context_),
151  {args.front()});
152  builder.CreateStore(compressed_lv, x_coord_ptr);
153  } else {
154  builder.CreateStore(args.front(), x_coord_ptr);
155  }
156 
157  // store y coord
158  auto y_coord_ptr = builder.CreateGEP(
159  pt_local_storage_lv_->getType()->getScalarType()->getPointerElementType(),
161  {cgen_state->llInt(0), cgen_state->llInt(1)},
162  "y_coord_ptr");
163  if (is_compressed) {
164  auto compressed_lv =
165  cgen_state->emitExternalCall("compress_y_coord_geoint",
166  llvm::Type::getInt32Ty(cgen_state->context_),
167  {args.back()});
168  builder.CreateStore(compressed_lv, y_coord_ptr);
169  } else {
170  builder.CreateStore(args.back(), y_coord_ptr);
171  }
172 
173  llvm::Value* ret = pt_local_storage_lv_;
174  if (is_nullable_) {
175  CHECK(nullcheck_codegen);
176  ret = nullcheck_codegen->finalize(ret, ret);
177  }
178  return {builder.CreateBitCast(ret,
179  geo_ti.get_compression() == kENCODING_GEOINT
180  ? llvm::Type::getInt32PtrTy(cgen_state->context_)
181  : llvm::Type::getDoublePtrTy(cgen_state->context_)),
182  cgen_state->llInt(static_cast<int32_t>(
183  geo_ti.get_compression() == kENCODING_GEOINT ? 8 : 16))};
184  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
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 SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
llvm::AllocaInst * pt_local_storage_lv_
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

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

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

88  {
89  CHECK_EQ(pos_lvs.size(),
90  size()); // note both pos arguments should be the same, as both inputs are
91  // expected to be from the same table, though this is moot in this
92  // function as position argumnts are not used here
93  CHECK_EQ(arg_lvs.size(), size_t(2));
94 
95  // TODO(adb): centralize nullcheck logic for all sqltypes
96  llvm::Value* const x_is_null = codegenOperandIsNull(0u, arg_lvs[0], cgen_state);
97  llvm::Value* const y_is_null = codegenOperandIsNull(1u, arg_lvs[1], cgen_state);
98  llvm::Value* const is_null =
99  x_is_null && y_is_null ? cgen_state->ir_builder_.CreateOr(x_is_null, y_is_null)
100  : std::max(x_is_null, y_is_null);
101 
102  if (is_nullable_ && !is_null) {
103  // if the inputs are not null, set the output to be not null
104  // TODO: we should do this in the translator and just confirm it here
105  is_nullable_ = false;
106  }
107 
108  // do the alloca before nullcheck codegen, as either way we will return a point array
109  const auto& geo_ti = operator_->get_type_info();
110  CHECK(geo_ti.get_type() == kPOINT);
111 
112  llvm::ArrayType* arr_type{nullptr};
113  if (geo_ti.get_compression() == kENCODING_GEOINT) {
114  auto elem_ty = llvm::Type::getInt32Ty(cgen_state->context_);
115  arr_type = llvm::ArrayType::get(elem_ty, 2);
116  } else {
117  CHECK(geo_ti.get_compression() == kENCODING_NONE);
118  auto elem_ty = llvm::Type::getDoubleTy(cgen_state->context_);
119  arr_type = llvm::ArrayType::get(elem_ty, 2);
120  }
121  pt_local_storage_lv_ = cgen_state->ir_builder_.CreateAlloca(
122  arr_type, nullptr, operator_->getName() + "_Local_Storage");
123 
124  return std::make_tuple(arg_lvs, is_null);
125  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::Value * codegenOperandIsNull(size_t idx, llvm::Value *value, CgenState *cgen_state)
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
llvm::LLVMContext & context_
Definition: CgenState.h:382
CONSTEXPR DEVICE bool is_null(const T &value)
const std::string & getName() const
Definition: Analyzer.h:3298
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
llvm::AllocaInst * pt_local_storage_lv_
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:69
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

llvm::Value* spatial_type::PointConstructor::codegenOperandIsNull ( size_t  idx,
llvm::Value *  value,
CgenState cgen_state 
)
inlineprivate

Definition at line 187 of file PointConstructor.h.

References inline_fp_null_val(), inline_int_null_val(), CgenState::ir_builder_, CgenState::llFp(), CgenState::llInt(), and UNREACHABLE.

Referenced by codegenLoads().

189  {
190  auto const& ti = getOperand(idx)->get_type_info();
191  if (ti.get_notnull()) {
192  return nullptr;
193  } else if (ti.is_integer()) {
194  return cgen_state->ir_builder_.CreateICmpEQ(
195  value, cgen_state->llInt(inline_int_null_val(ti)));
196  } else if (ti.is_fp()) {
197  return cgen_state->ir_builder_.CreateFCmpOEQ(
198  value, cgen_state->llFp(inline_fp_null_val(ti)));
199  } else {
200  UNREACHABLE() << "Type is expected to be integer or floating point.";
201  return {};
202  }
203  }
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
#define UNREACHABLE()
Definition: Logger.h:338
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
llvm::ConstantFP * llFp(const float v) const
Definition: CgenState.h:253
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:249
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:64
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

+ Here is the caller 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 38 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_.

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

+ Here is the call graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 82 of file PointConstructor.h.

References kBOOLEAN.

Referenced by getNullCheckCodegen().

82 { 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 80 of file PointConstructor.h.

Referenced by codegenLoads().

80 { 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 205 of file PointConstructor.h.

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


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