OmniSciDB  0264ff685a
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

◆ call_requires_custom_type_handling()

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

Definition at line 478 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

478  {
479  const auto& ret_ti = function_oper->get_type_info();
480  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
481  return true;
482  }
483  for (size_t i = 0; i < function_oper->getArity(); ++i) {
484  const auto arg = function_oper->getArg(i);
485  const auto& arg_ti = arg->get_type_info();
486  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
487  return true;
488  }
489  }
490  return false;
491 }
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1362
size_t getArity() const
Definition: Analyzer.h:1360
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ext_arg_type_to_llvm_type()

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

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

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);
113  return llvm::Type::getVoidTy(ctx);
114  default:
115  CHECK(false);
116  }
117  CHECK(false);
118  return nullptr;
119 }
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:

◆ ext_func_call_requires_nullcheck()

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

Definition at line 193 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::beginArgsNullcheck().

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

◆ get_buffer_struct_type()

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, CHECK_EQ, CHECK_GE, CHECK_LE, CgenState::context_, CgenState::module_, serialize_llvm_object(), and toString().

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:322
llvm::LLVMContext & context_
Definition: CgenState.h:331
#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 call graph for this function:
+ Here is the caller graph for this function:

◆ get_llvm_type_from_sql_array_type()

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

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

157  {
158  CHECK(ti.is_buffer());
159  if (ti.is_bytes()) {
160  return llvm::Type::getInt8PtrTy(ctx);
161  }
162 
163  const auto& elem_ti = ti.get_elem_type();
164  if (elem_ti.is_fp()) {
165  switch (elem_ti.get_size()) {
166  case 4:
167  return llvm::Type::getFloatPtrTy(ctx);
168  case 8:
169  return llvm::Type::getDoublePtrTy(ctx);
170  }
171  }
172 
173  if (elem_ti.is_boolean()) {
174  return llvm::Type::getInt8PtrTy(ctx);
175  }
176 
177  CHECK(elem_ti.is_integer());
178  switch (elem_ti.get_size()) {
179  case 1:
180  return llvm::Type::getInt8PtrTy(ctx);
181  case 2:
182  return llvm::Type::getInt16PtrTy(ctx);
183  case 4:
184  return llvm::Type::getInt32PtrTy(ctx);
185  case 8:
186  return llvm::Type::getInt64PtrTy(ctx);
187  }
188 
189  UNREACHABLE();
190  return nullptr;
191 }
bool is_bytes() const
Definition: sqltypes.h:492
#define UNREACHABLE()
Definition: Logger.h:241
bool is_buffer() const
Definition: sqltypes.h:495
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_sql_type_from_llvm_type()

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

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

121  {
122  CHECK(ll_type);
123  const auto bits = ll_type->getPrimitiveSizeInBits();
124 
125  if (ll_type->isFloatingPointTy()) {
126  switch (bits) {
127  case 32:
128  return SQLTypeInfo(kFLOAT, false);
129  case 64:
130  return SQLTypeInfo(kDOUBLE, false);
131  default:
132  LOG(FATAL) << "Unsupported llvm floating point type: " << bits
133  << ", only 32 and 64 bit floating point is supported.";
134  }
135  } else {
136  switch (bits) {
137  case 1:
138  return SQLTypeInfo(kBOOLEAN, false);
139  case 8:
140  return SQLTypeInfo(kTINYINT, false);
141  case 16:
142  return SQLTypeInfo(kSMALLINT, false);
143  case 32:
144  return SQLTypeInfo(kINT, false);
145  case 64:
146  return SQLTypeInfo(kBIGINT, false);
147  default:
148  LOG(FATAL) << "Unrecognized llvm type for SQL type: "
149  << bits; // TODO let's get the real name here
150  }
151  }
152  UNREACHABLE();
153  return SQLTypeInfo();
154 }
#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: