OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

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

Definition at line 419 of file ExtensionsIR.cpp.

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

Referenced by CodeGenerator::codegenFunctionOperWithCustomTypeHandling().

419  {
420  const auto& ret_ti = function_oper->get_type_info();
421  if (!ret_ti.is_integer() && !ret_ti.is_fp()) {
422  return true;
423  }
424  for (size_t i = 0; i < function_oper->getArity(); ++i) {
425  const auto arg = function_oper->getArg(i);
426  const auto& arg_ti = arg->get_type_info();
427  if (!arg_ti.is_integer() && !arg_ti.is_fp()) {
428  return true;
429  }
430  }
431  return false;
432 }
size_t getArity() const
Definition: Analyzer.h:1361
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1363

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

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

Referenced by CodeGenerator::codegenFunctionOper().

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);
102  return llvm::Type::getVoidTy(ctx);
104  return llvm::Type::getVoidTy(ctx);
106  return llvm::Type::getVoidTy(ctx);
107  default:
108  CHECK(false);
109  }
110  CHECK(false);
111  return nullptr;
112 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
CHECK(cgen_state)

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

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

Referenced by CodeGenerator::beginArgsNullcheck().

177  {
178  const auto& func_ti = function_oper->get_type_info();
179  for (size_t i = 0; i < function_oper->getArity(); ++i) {
180  const auto arg = function_oper->getArg(i);
181  const auto& arg_ti = arg->get_type_info();
182  if (func_ti.is_array() && arg_ti.is_array()) {
183  // If the function returns an array and any of the arguments are arrays, allow NULL
184  // scalars.
185  // TODO: Make this a property of the FunctionOper following `RETURN NULL ON NULL`
186  // semantics.
187  return false;
188  } else if (!arg_ti.get_notnull() && !arg_ti.is_array()) {
189  // Nullable geometry args will trigger a null check
190  return true;
191  } else {
192  continue;
193  }
194  }
195  return false;
196 }
size_t getArity() const
Definition: Analyzer.h:1361
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1363

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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(), CgenState::context_, and CgenState::module_.

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:314
llvm::LLVMContext & context_
Definition: CgenState.h:317
CHECK(cgen_state)
#define CHECK_LE(x, y)
Definition: Logger.h:208
std::string serialize_llvm_object(const T *llvm_obj)

+ Here is the call graph for this function:

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

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

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

150  {
151  CHECK(ti.is_array());
152  const auto& elem_ti = ti.get_elem_type();
153  if (elem_ti.is_fp()) {
154  switch (elem_ti.get_size()) {
155  case 4:
156  return llvm::Type::getFloatPtrTy(ctx);
157  case 8:
158  return llvm::Type::getDoublePtrTy(ctx);
159  }
160  }
161  CHECK(elem_ti.is_integer());
162  switch (elem_ti.get_size()) {
163  case 1:
164  return llvm::Type::getInt8PtrTy(ctx);
165  case 2:
166  return llvm::Type::getInt16PtrTy(ctx);
167  case 4:
168  return llvm::Type::getInt32PtrTy(ctx);
169  case 8:
170  return llvm::Type::getInt64PtrTy(ctx);
171  }
172 
173  UNREACHABLE();
174  return nullptr;
175 }
#define UNREACHABLE()
Definition: Logger.h:241
CHECK(cgen_state)
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:622
bool is_array() const
Definition: sqltypes.h:423

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function: