OmniSciDB  6686921089
 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 496 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

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

+ 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, 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);
123  return llvm::Type::getVoidTy(ctx);
124  default:
125  CHECK(false);
126  }
127  CHECK(false);
128  return nullptr;
129 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
#define CHECK(condition)
Definition: Logger.h:209

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

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

Referenced by CodeGenerator::beginArgsNullcheck().

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

+ 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:217
std::string toString(const ExtArgumentType &sig_type)
#define CHECK_GE(x, y)
Definition: Logger.h:222
llvm::Module * module_
Definition: CgenState.h:329
llvm::LLVMContext & context_
Definition: CgenState.h:338
#define CHECK_LE(x, y)
Definition: Logger.h:220
std::string serialize_llvm_object(const T *llvm_obj)
#define CHECK(condition)
Definition: Logger.h:209

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

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

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

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

+ Here is the caller graph for this function: