OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{ExtensionsIR.cpp} Namespace Reference

Functions

llvm::StructType * get_buffer_struct_type (CgenState *cgen_state, const std::string &ext_func_name, size_t param_num, llvm::Type *elem_type, bool has_is_null)
 
llvm::Typeext_arg_type_to_llvm_type (const ExtArgumentType ext_arg_type, llvm::LLVMContext &ctx)
 
SQLTypeInfo get_sql_type_from_llvm_type (const llvm::Type *ll_type)
 
llvm::Typeget_llvm_type_from_sql_array_type (const SQLTypeInfo ti, llvm::LLVMContext &ctx)
 
bool ext_func_call_requires_nullcheck (const Analyzer::FunctionOper *function_oper)
 
bool call_requires_custom_type_handling (const Analyzer::FunctionOper *function_oper)
 

Function Documentation

bool anonymous_namespace{ExtensionsIR.cpp}::call_requires_custom_type_handling ( const Analyzer::FunctionOper function_oper)

Definition at line 486 of file ExtensionsIR.cpp.

References Analyzer::Expr::get_type_info(), Analyzer::FunctionOper::getArg(), Analyzer::FunctionOper::getArity(), and i.

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

486  {
487  const auto& ret_ti = function_oper->get_type_info();
488  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
489  return true;
490  }
491  for (size_t i = 0; i < function_oper->getArity(); ++i) {
492  const auto arg = function_oper->getArg(i);
493  const auto& arg_ti = arg->get_type_info();
494  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
495  return true;
496  }
497  }
498  return false;
499 }
size_t getArity() const
Definition: Analyzer.h:1360
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1362

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Type* anonymous_namespace{ExtensionsIR.cpp}::ext_arg_type_to_llvm_type ( const ExtArgumentType  ext_arg_type,
llvm::LLVMContext &  ctx 
)

Definition at line 82 of file ExtensionsIR.cpp.

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, CHECK, ColumnBool, ColumnDouble, ColumnFloat, ColumnInt16, ColumnInt32, ColumnInt64, ColumnInt8, ColumnListBool, ColumnListDouble, ColumnListFloat, ColumnListInt16, ColumnListInt32, ColumnListInt64, ColumnListInt8, Double, Float, get_int_type(), Int16, Int32, Int64, Int8, and TextEncodingNone.

Referenced by CodeGenerator::codegenFunctionOper().

83  {
84  switch (ext_arg_type) {
85  case ExtArgumentType::Bool: // pass thru to Int8
87  return get_int_type(8, ctx);
89  return get_int_type(16, ctx);
91  return get_int_type(32, ctx);
93  return get_int_type(64, ctx);
95  return llvm::Type::getFloatTy(ctx);
97  return llvm::Type::getDoubleTy(ctx);
120  return llvm::Type::getVoidTy(ctx);
121  default:
122  CHECK(false);
123  }
124  CHECK(false);
125  return nullptr;
126 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{ExtensionsIR.cpp}::ext_func_call_requires_nullcheck ( const Analyzer::FunctionOper function_oper)

Definition at line 200 of file ExtensionsIR.cpp.

References Analyzer::Expr::get_type_info(), Analyzer::FunctionOper::getArg(), Analyzer::FunctionOper::getArity(), and i.

Referenced by CodeGenerator::beginArgsNullcheck().

200  {
201  const auto& func_ti = function_oper->get_type_info();
202  for (size_t i = 0; i < function_oper->getArity(); ++i) {
203  const auto arg = function_oper->getArg(i);
204  const auto& arg_ti = arg->get_type_info();
205  if ((func_ti.is_array() && arg_ti.is_array()) ||
206  (func_ti.is_bytes() && arg_ti.is_bytes())) {
207  // If the function returns an array and any of the arguments are arrays, allow NULL
208  // scalars.
209  // TODO: Make this a property of the FunctionOper following `RETURN NULL ON NULL`
210  // semantics.
211  return false;
212  } else if (!arg_ti.get_notnull() && !arg_ti.is_buffer()) {
213  // Nullable geometry args will trigger a null check
214  return true;
215  } else {
216  continue;
217  }
218  }
219  return false;
220 }
size_t getArity() const
Definition: Analyzer.h:1360
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1362

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::StructType* anonymous_namespace{ExtensionsIR.cpp}::get_buffer_struct_type ( CgenState cgen_state,
const std::string &  ext_func_name,
size_t  param_num,
llvm::Type elem_type,
bool  has_is_null 
)

Definition at line 31 of file ExtensionsIR.cpp.

References CHECK, and CgenState::context_.

Referenced by CodeGenerator::beginArgsNullcheck(), CodeGenerator::codegenBufferArgs(), CodeGenerator::codegenFunctionOper(), and CodeGenerator::endArgsNullcheck().

35  {
36  CHECK(elem_type);
37  CHECK(elem_type->isPointerTy());
38  llvm::StructType* generated_struct_type =
39  (has_is_null ? llvm::StructType::get(cgen_state->context_,
40  {elem_type,
41  llvm::Type::getInt64Ty(cgen_state->context_),
42  llvm::Type::getInt8Ty(cgen_state->context_)},
43  false)
44  : llvm::StructType::get(
45  cgen_state->context_,
46  {elem_type, llvm::Type::getInt64Ty(cgen_state->context_)},
47  false));
48  llvm::Function* udf_func = cgen_state->module_->getFunction(ext_func_name);
49  if (udf_func) {
50  // Compare expected array struct type with type from the function
51  // definition from the UDF module, but use the type from the
52  // module
53  llvm::FunctionType* udf_func_type = udf_func->getFunctionType();
54  CHECK_LE(param_num, udf_func_type->getNumParams());
55  llvm::Type* param_pointer_type = udf_func_type->getParamType(param_num);
56  CHECK(param_pointer_type->isPointerTy());
57  llvm::Type* param_type = param_pointer_type->getPointerElementType();
58  CHECK(param_type->isStructTy());
59  llvm::StructType* struct_type = llvm::cast<llvm::StructType>(param_type);
60  CHECK_GE(struct_type->getStructNumElements(),
61  generated_struct_type->getStructNumElements())
62  << serialize_llvm_object(struct_type);
63 
64  const auto expected_elems = generated_struct_type->elements();
65  const auto current_elems = struct_type->elements();
66  for (size_t i = 0; i < expected_elems.size(); i++) {
67  CHECK_EQ(expected_elems[i], current_elems[i])
68  << "[" << ::toString(expected_elems[i]) << ", " << ::toString(current_elems[i])
69  << "]";
70  }
71 
72  if (struct_type->isLiteral()) {
73  return struct_type;
74  }
75 
76  llvm::StringRef struct_name = struct_type->getStructName();
77  return cgen_state->module_->getTypeByName(struct_name);
78  }
79  return generated_struct_type;
80 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
std::string toString(const ExtArgumentType &sig_type)
#define CHECK_GE(x, y)
Definition: Logger.h:210
llvm::Module * module_
Definition: CgenState.h:318
llvm::LLVMContext & context_
Definition: CgenState.h:327
#define CHECK_LE(x, y)
Definition: Logger.h:208
std::string serialize_llvm_object(const T *llvm_obj)
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the caller graph for this function:

llvm::Type* anonymous_namespace{ExtensionsIR.cpp}::get_llvm_type_from_sql_array_type ( const SQLTypeInfo  ti,
llvm::LLVMContext &  ctx 
)
inline

Definition at line 163 of file ExtensionsIR.cpp.

References CHECK, SQLTypeInfo::get_elem_type(), SQLTypeInfo::is_buffer(), SQLTypeInfo::is_bytes(), and UNREACHABLE.

Referenced by CodeGenerator::beginArgsNullcheck(), CodeGenerator::codegenFunctionOper(), and CodeGenerator::endArgsNullcheck().

164  {
165  CHECK(ti.is_buffer());
166  if (ti.is_bytes()) {
167  return llvm::Type::getInt8PtrTy(ctx);
168  }
169 
170  const auto& elem_ti = ti.get_elem_type();
171  if (elem_ti.is_fp()) {
172  switch (elem_ti.get_size()) {
173  case 4:
174  return llvm::Type::getFloatPtrTy(ctx);
175  case 8:
176  return llvm::Type::getDoublePtrTy(ctx);
177  }
178  }
179 
180  if (elem_ti.is_boolean()) {
181  return llvm::Type::getInt8PtrTy(ctx);
182  }
183 
184  CHECK(elem_ti.is_integer());
185  switch (elem_ti.get_size()) {
186  case 1:
187  return llvm::Type::getInt8PtrTy(ctx);
188  case 2:
189  return llvm::Type::getInt16PtrTy(ctx);
190  case 4:
191  return llvm::Type::getInt32PtrTy(ctx);
192  case 8:
193  return llvm::Type::getInt64PtrTy(ctx);
194  }
195 
196  UNREACHABLE();
197  return nullptr;
198 }
#define UNREACHABLE()
Definition: Logger.h:241
bool is_buffer() const
Definition: sqltypes.h:506
bool is_bytes() const
Definition: sqltypes.h:503
#define CHECK(condition)
Definition: Logger.h:197
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:712

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SQLTypeInfo anonymous_namespace{ExtensionsIR.cpp}::get_sql_type_from_llvm_type ( const llvm::Type ll_type)
inline

Definition at line 128 of file ExtensionsIR.cpp.

References CHECK, logger::FATAL, kBIGINT, kBOOLEAN, kDOUBLE, kFLOAT, kINT, kSMALLINT, kTINYINT, LOG, and UNREACHABLE.

Referenced by CodeGenerator::codegenFunctionOper(), and CodeGenerator::endArgsNullcheck().

128  {
129  CHECK(ll_type);
130  const auto bits = ll_type->getPrimitiveSizeInBits();
131 
132  if (ll_type->isFloatingPointTy()) {
133  switch (bits) {
134  case 32:
135  return SQLTypeInfo(kFLOAT, false);
136  case 64:
137  return SQLTypeInfo(kDOUBLE, false);
138  default:
139  LOG(FATAL) << "Unsupported llvm floating point type: " << bits
140  << ", only 32 and 64 bit floating point is supported.";
141  }
142  } else {
143  switch (bits) {
144  case 1:
145  return SQLTypeInfo(kBOOLEAN, false);
146  case 8:
147  return SQLTypeInfo(kTINYINT, false);
148  case 16:
149  return SQLTypeInfo(kSMALLINT, false);
150  case 32:
151  return SQLTypeInfo(kINT, false);
152  case 64:
153  return SQLTypeInfo(kBIGINT, false);
154  default:
155  LOG(FATAL) << "Unrecognized llvm type for SQL type: "
156  << bits; // TODO let's get the real name here
157  }
158  }
159  UNREACHABLE();
160  return SQLTypeInfo();
161 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqltypes.h:44

+ Here is the caller graph for this function: