OmniSciDB  a987f07e93
 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)
 
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 507 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

507  {
508  const auto& ret_ti = function_oper->get_type_info();
509  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
510  return true;
511  }
512  for (size_t i = 0; i < function_oper->getArity(); ++i) {
513  const auto arg = function_oper->getArg(i);
514  const auto& arg_ti = arg->get_type_info();
515  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
516  return true;
517  }
518  }
519  return false;
520 }
size_t getArity() const
Definition: Analyzer.h:2404
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:83
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:2406

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

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, ArrayTextEncodingDict, 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, TextEncodingDict, and TextEncodingNone.

Referenced by CodeGenerator::codegenFunctionOper().

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

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

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

Referenced by CodeGenerator::beginArgsNullcheck().

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

+ 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 
)

Definition at line 30 of file ExtensionsIR.cpp.

References CHECK, and CgenState::context_.

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

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

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

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

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

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

+ Here is the caller graph for this function: