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

#include <AreaPerimeter.h>

+ Inheritance diagram for spatial_type::AreaPerimeter:
+ Collaboration diagram for spatial_type::AreaPerimeter:

Public Member Functions

 AreaPerimeter (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 25 of file AreaPerimeter.h.

Constructor & Destructor Documentation

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

Definition at line 27 of file AreaPerimeter.h.

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

29  : Codegen(geo_operator, catalog) {
30  CHECK_EQ(operator_->size(), size_t(1));
31  const auto& ti = operator_->get_type_info();
32  is_nullable_ = !ti.get_notnull();
33  }
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 SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:77
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::AreaPerimeter::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 AreaPerimeter.h.

References run_benchmark_import::args, CHECK, Geospatial::get_compression_scheme(), kDOUBLE, kFLOAT, kGEOGRAPHY, kMULTIPOLYGON, kPOLYGON, and spatial_type::suffix().

93  {
94  auto operand_lvs = args;
95 
96  const auto& operand_ti = getOperand(0)->get_type_info();
97  CHECK(operand_ti.get_type() == kPOLYGON || operand_ti.get_type() == kMULTIPOLYGON);
98  const bool is_geodesic =
99  operand_ti.get_subtype() == kGEOGRAPHY && operand_ti.get_output_srid() == 4326;
100 
101  std::string func_name = getName() + suffix(operand_ti.get_type());
102  if (is_geodesic && getName() == "ST_Perimeter") {
103  func_name += "_Geodesic";
104  }
105 
106  // push back ic, isr, osr for now
107  operand_lvs.push_back(
108  cgen_state->llInt(Geospatial::get_compression_scheme(operand_ti))); // ic
109  operand_lvs.push_back(cgen_state->llInt(operand_ti.get_input_srid())); // in srid
110  operand_lvs.push_back(cgen_state->llInt(operand_ti.get_output_srid())); // out srid
111 
112  const auto& ret_ti = operator_->get_type_info();
113  CHECK(ret_ti.get_type() == kDOUBLE || ret_ti.get_type() == kFLOAT);
114 
115  auto ret = cgen_state->emitExternalCall(
116  func_name,
117  ret_ti.get_type() == kDOUBLE ? llvm::Type::getDoubleTy(cgen_state->context_)
118  : llvm::Type::getFloatTy(cgen_state->context_),
119  operand_lvs);
120  if (is_nullable_) {
121  CHECK(nullcheck_codegen);
122  ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(ret_ti), ret);
123  }
124  return {ret};
125  }
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
int32_t get_compression_scheme(const SQLTypeInfo &ti)
Definition: Compression.cpp:23
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:68
llvm::LLVMContext & context_
Definition: CgenState.h:338
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 getName() const
Definition: Codegen.h:39
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::AreaPerimeter::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 39 of file AreaPerimeter.h.

References CHECK, CHECK_EQ, get_int_type(), spatial_type::Codegen::getOperand(), i, spatial_type::Codegen::is_nullable_, kENCODING_GEOINT, log2_bytes(), and size().

42  {
43  CHECK_EQ(pos_lvs.size(), size());
44  const auto operand = getOperand(0);
45  CHECK(operand);
46  const auto& operand_ti = operand->get_type_info();
47 
48  std::string size_fn_name = "array_size";
49  if (is_nullable_) {
50  size_fn_name += "_nullable";
51  }
52 
53  const uint32_t coords_elem_sz_bytes =
54  operand_ti.get_compression() == kENCODING_GEOINT ? 1 : 8;
55 
56  std::vector<llvm::Value*> operand_lvs;
57  // iterate over column inputs
58  if (dynamic_cast<const Analyzer::ColumnVar*>(operand)) {
59  for (size_t i = 0; i < arg_lvs.size(); i++) {
60  auto lv = arg_lvs[i];
61  operand_lvs.push_back(
62  cgen_state->emitExternalCall("array_buff",
63  llvm::Type::getInt8PtrTy(cgen_state->context_),
64  {lv, pos_lvs.front()}));
65  const auto ptr_type = llvm::dyn_cast_or_null<llvm::PointerType>(lv->getType());
66  CHECK(ptr_type);
67  const auto elem_type = ptr_type->getElementType();
68  CHECK(elem_type);
69  std::vector<llvm::Value*> array_sz_args{
70  lv,
71  pos_lvs.front(),
72  cgen_state->llInt(log2_bytes(i == 0 ? coords_elem_sz_bytes : 4))};
73  if (is_nullable_) { // TODO: should we do this for all arguments, or just points?
74  array_sz_args.push_back(
75  cgen_state->llInt(static_cast<int32_t>(inline_int_null_value<int32_t>())));
76  }
77  operand_lvs.push_back(cgen_state->emitExternalCall(
78  size_fn_name, get_int_type(32, cgen_state->context_), array_sz_args));
79  }
80  } else {
81  operand_lvs = arg_lvs;
82  }
83  CHECK_EQ(operand_lvs.size(),
84  size_t(2 * operand_ti.get_physical_coord_cols())); // array ptr and size
85 
86  // use the points array size argument for nullability
87  return std::make_tuple(operand_lvs, is_nullable_ ? operand_lvs[1] : nullptr);
88  }
#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::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::LLVMContext & context_
Definition: CgenState.h:338
size_t size() const final
Definition: AreaPerimeter.h:35
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:307
#define CHECK(condition)
Definition: Logger.h:211
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:63
uint32_t log2_bytes(const uint32_t bytes)
Definition: Execute.h:176

+ Here is the call graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 37 of file AreaPerimeter.h.

References kINT.

37 { return SQLTypeInfo(kINT); }
Definition: sqltypes.h:45
size_t spatial_type::AreaPerimeter::size ( ) const
inlinefinalvirtual

Implements spatial_type::Codegen.

Definition at line 35 of file AreaPerimeter.h.

Referenced by codegenLoads().

35 { return 1; }

+ Here is the caller graph for this function:


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