OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 497 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

497  {
498  const auto& ret_ti = function_oper->get_type_info();
499  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
500  return true;
501  }
502  for (size_t i = 0; i < function_oper->getArity(); ++i) {
503  const auto arg = function_oper->getArg(i);
504  const auto& arg_ti = arg->get_type_info();
505  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
506  return true;
507  }
508  }
509  return false;
510 }
size_t getArity() const
Definition: Analyzer.h:2169
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:2171

+ 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 85 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, ColumnTimestamp, Double, Float, get_int_type(), Int16, Int32, Int64, Int8, and TextEncodingNone.

Referenced by CodeGenerator::codegenFunctionOper().

86  {
87  switch (ext_arg_type) {
88  case ExtArgumentType::Bool: // pass thru to Int8
90  return get_int_type(8, ctx);
92  return get_int_type(16, ctx);
94  return get_int_type(32, ctx);
96  return get_int_type(64, ctx);
98  return llvm::Type::getFloatTy(ctx);
100  return llvm::Type::getDoubleTy(ctx);
124  return llvm::Type::getVoidTy(ctx);
125  default:
126  CHECK(false);
127  }
128  CHECK(false);
129  return nullptr;
130 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define CHECK(condition)
Definition: Logger.h:223

+ 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 204 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::beginArgsNullcheck().

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

+ 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 30 of file ExtensionsIR.cpp.

References CHECK, and CgenState::context_.

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

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

+ 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 167 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().

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

+ 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 132 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().

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

+ Here is the caller graph for this function: