OmniSciDB  dfae7c3b14
anonymous_namespace{ExtensionsIR.cpp} Namespace Reference

Functions

llvm::StructType * get_arr_struct_type (CgenState *cgen_state, const std::string &ext_func_name, llvm::Type *array_type, size_t param_num)
 
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 428 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

428  {
429  const auto& ret_ti = function_oper->get_type_info();
430  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
431  return true;
432  }
433  for (size_t i = 0; i < function_oper->getArity(); ++i) {
434  const auto arg = function_oper->getArg(i);
435  const auto& arg_ti = arg->get_type_info();
436  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
437  return true;
438  }
439  }
440  return false;
441 }
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 79 of file ExtensionsIR.cpp.

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, CHECK, Double, Float, get_int_type(), Int16, Int32, Int64, and Int8.

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

80  {
81  switch (ext_arg_type) {
82  case ExtArgumentType::Bool: // pass thru to Int8
84  return get_int_type(8, ctx);
86  return get_int_type(16, ctx);
88  return get_int_type(32, ctx);
90  return get_int_type(64, ctx);
92  return llvm::Type::getFloatTy(ctx);
94  return llvm::Type::getDoubleTy(ctx);
96  return llvm::Type::getVoidTy(ctx);
98  return llvm::Type::getVoidTy(ctx);
100  return llvm::Type::getVoidTy(ctx);
101  case ExtArgumentType::ArrayBool: // pass thru to Array<Int8>
103  return llvm::Type::getVoidTy(ctx);
105  return llvm::Type::getVoidTy(ctx);
107  return llvm::Type::getVoidTy(ctx);
108  default:
109  CHECK(false);
110  }
111  CHECK(false);
112  return nullptr;
113 }
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 183 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::beginArgsNullcheck().

183  {
184  const auto& func_ti = function_oper->get_type_info();
185  for (size_t i = 0; i < function_oper->getArity(); ++i) {
186  const auto arg = function_oper->getArg(i);
187  const auto& arg_ti = arg->get_type_info();
188  if (func_ti.is_array() && arg_ti.is_array()) {
189  // If the function returns an array and any of the arguments are arrays, allow NULL
190  // scalars.
191  // TODO: Make this a property of the FunctionOper following `RETURN NULL ON NULL`
192  // semantics.
193  return false;
194  } else if (!arg_ti.get_notnull() && !arg_ti.is_array()) {
195  // Nullable geometry args will trigger a null check
196  return true;
197  } else {
198  continue;
199  }
200  }
201  return false;
202 }
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_arr_struct_type()

llvm::StructType* anonymous_namespace{ExtensionsIR.cpp}::get_arr_struct_type ( CgenState cgen_state,
const std::string &  ext_func_name,
llvm::Type array_type,
size_t  param_num 
)

Definition at line 35 of file ExtensionsIR.cpp.

References CHECK, CHECK_EQ, CHECK_GE, CHECK_LE, CgenState::context_, CgenState::module_, and serialize_llvm_object().

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

38  {
39  llvm::Function* udf_func = cgen_state->module_->getFunction(ext_func_name);
40  CHECK(array_type);
41  CHECK(array_type->isPointerTy());
42 
43  llvm::StructType* generated_struct_type =
44  llvm::StructType::get(cgen_state->context_,
45  {array_type,
46  llvm::Type::getInt64Ty(cgen_state->context_),
47  llvm::Type::getInt8Ty(cgen_state->context_)},
48  false);
49  if (udf_func) {
50  // Compare expected array struct type with type from the function definition from the
51  // UDF module, but use the type from the 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(), size_t(3))
60  << serialize_llvm_object(struct_type);
61 
62  const auto expected_elems = generated_struct_type->elements();
63  const auto current_elems = struct_type->elements();
64  for (size_t i = 0; i < expected_elems.size(); i++) {
65  CHECK_EQ(expected_elems[i], current_elems[i]);
66  }
67 
68  if (struct_type->isLiteral()) {
69  return struct_type;
70  }
71 
72  llvm::StringRef struct_name = struct_type->getStructName();
73  return cgen_state->module_->getTypeByName(struct_name);
74  }
75 
76  return generated_struct_type;
77 }
#define CHECK_EQ(x, y)
Definition: Logger.h:205
#define CHECK_GE(x, y)
Definition: Logger.h:210
llvm::Module * module_
Definition: CgenState.h:330
llvm::LLVMContext & context_
Definition: CgenState.h:339
#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 150 of file ExtensionsIR.cpp.

References CHECK, SQLTypeInfo::get_elem_type(), SQLTypeInfo::is_array(), and UNREACHABLE.

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

151  {
152  CHECK(ti.is_array());
153  const auto& elem_ti = ti.get_elem_type();
154  if (elem_ti.is_fp()) {
155  switch (elem_ti.get_size()) {
156  case 4:
157  return llvm::Type::getFloatPtrTy(ctx);
158  case 8:
159  return llvm::Type::getDoublePtrTy(ctx);
160  }
161  }
162 
163  if (elem_ti.is_boolean()) {
164  return llvm::Type::getInt8PtrTy(ctx);
165  }
166 
167  CHECK(elem_ti.is_integer());
168  switch (elem_ti.get_size()) {
169  case 1:
170  return llvm::Type::getInt8PtrTy(ctx);
171  case 2:
172  return llvm::Type::getInt16PtrTy(ctx);
173  case 4:
174  return llvm::Type::getInt32PtrTy(ctx);
175  case 8:
176  return llvm::Type::getInt64PtrTy(ctx);
177  }
178 
179  UNREACHABLE();
180  return nullptr;
181 }
bool is_array() const
Definition: sqltypes.h:425
#define UNREACHABLE()
Definition: Logger.h:241
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:624
#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 115 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().

115  {
116  CHECK(ll_type);
117  const auto bits = ll_type->getPrimitiveSizeInBits();
118 
119  if (ll_type->isFloatingPointTy()) {
120  switch (bits) {
121  case 32:
122  return SQLTypeInfo(kFLOAT, false);
123  case 64:
124  return SQLTypeInfo(kDOUBLE, false);
125  default:
126  LOG(FATAL) << "Unsupported llvm floating point type: " << bits
127  << ", only 32 and 64 bit floating point is supported.";
128  }
129  } else {
130  switch (bits) {
131  case 1:
132  return SQLTypeInfo(kBOOLEAN, false);
133  case 8:
134  return SQLTypeInfo(kTINYINT, false);
135  case 16:
136  return SQLTypeInfo(kSMALLINT, false);
137  case 32:
138  return SQLTypeInfo(kINT, false);
139  case 64:
140  return SQLTypeInfo(kBIGINT, false);
141  default:
142  LOG(FATAL) << "Unrecognized llvm type for SQL type: "
143  << bits; // TODO let's get the real name here
144  }
145  }
146  UNREACHABLE();
147  return SQLTypeInfo();
148 }
#define LOG(tag)
Definition: Logger.h:188
#define UNREACHABLE()
Definition: Logger.h:241
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqltypes.h:47
+ Here is the caller graph for this function: