OmniSciDB  c1a53651b2
 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)
 
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 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)
 
- Protected Attributes inherited from spatial_type::Codegen
const Analyzer::GeoOperatoroperator_
 
bool is_nullable_ {true}
 

Detailed Description

Definition at line 24 of file AreaPerimeter.h.

Constructor & Destructor Documentation

spatial_type::AreaPerimeter::AreaPerimeter ( const Analyzer::GeoOperator geo_operator)
inline

Definition at line 26 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().

26  : Codegen(geo_operator) {
27  CHECK_EQ(operator_->size(), size_t(1));
28  const auto& ti = operator_->get_type_info();
29  is_nullable_ = !ti.get_notnull();
30  }
#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:67
size_t size() const
Definition: Analyzer.cpp:3982
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::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 84 of file AreaPerimeter.h.

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

87  {
88  auto operand_lvs = args;
89 
90  const auto& operand_ti = getOperand(0)->get_type_info();
91  CHECK(operand_ti.get_type() == kPOLYGON || operand_ti.get_type() == kMULTIPOLYGON);
92  const bool is_geodesic =
93  operand_ti.get_subtype() == kGEOGRAPHY && operand_ti.get_output_srid() == 4326;
94 
95  std::string func_name = getName() + suffix(operand_ti.get_type());
96  if (is_geodesic && getName() == "ST_Perimeter") {
97  func_name += "_Geodesic";
98  }
99 
100  // push back ic, isr, osr for now
101  operand_lvs.push_back(
102  cgen_state->llInt(Geospatial::get_compression_scheme(operand_ti))); // ic
103  operand_lvs.push_back(cgen_state->llInt(operand_ti.get_input_srid())); // in srid
104  auto output_srid = operand_ti.get_output_srid();
105  if (const auto srid_override = operator_->getOutputSridOverride()) {
106  output_srid = *srid_override;
107  }
108  operand_lvs.push_back(cgen_state->llInt(output_srid)); // out srid
109 
110  const auto& ret_ti = operator_->get_type_info();
111  CHECK(ret_ti.get_type() == kDOUBLE || ret_ti.get_type() == kFLOAT);
112 
113  auto ret = cgen_state->emitExternalCall(
114  func_name,
115  ret_ti.get_type() == kDOUBLE ? llvm::Type::getDoubleTy(cgen_state->context_)
116  : llvm::Type::getFloatTy(cgen_state->context_),
117  operand_lvs);
118  if (is_nullable_) {
119  CHECK(nullcheck_codegen);
120  ret = nullcheck_codegen->finalize(cgen_state->inlineFpNull(ret_ti), ret);
121  }
122  return {ret};
123  }
auto getOutputSridOverride() const
Definition: Analyzer.h:2964
int32_t get_compression_scheme(const SQLTypeInfo &ti)
Definition: Compression.cpp:23
std::string suffix(SQLTypes type)
Definition: Codegen.cpp:69
llvm::LLVMContext & context_
Definition: CgenState.h:375
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:396
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
const Analyzer::GeoOperator * operator_
Definition: Codegen.h:67
llvm::ConstantInt * llInt(const T v) const
Definition: CgenState.h:242
llvm::Value * finalize(llvm::Value *null_lv, llvm::Value *notnull_lv)
Definition: IRCodegen.cpp:1463
#define CHECK(condition)
Definition: Logger.h:291
virtual const Analyzer::Expr * getOperand(const size_t index)
Definition: Codegen.cpp:64
std::string getName() const
Definition: Codegen.h:36
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:103

+ 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 36 of file AreaPerimeter.h.

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

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

+ Here is the call graph for this function:

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

Implements spatial_type::Codegen.

Definition at line 34 of file AreaPerimeter.h.

References kINT.

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

Implements spatial_type::Codegen.

Definition at line 32 of file AreaPerimeter.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: