OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{TableFunctionCompilationContext.cpp} Namespace Reference

Functions

llvm::Function * generate_entry_point (const CgenState *cgen_state)
 
llvm::Typeget_llvm_type_from_sql_column_type (const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
 
llvm::Value * alloc_column (std::string col_name, const SQLTypeInfo &data_target_info, llvm::Value *data_ptr, llvm::Value *data_size, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder, bool byval)
 
llvm::Value * alloc_column_list (std::string col_list_name, const SQLTypeInfo &data_target_info, llvm::Value *data_ptrs, int length, llvm::Value *data_size, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
 

Function Documentation

llvm::Value* anonymous_namespace{TableFunctionCompilationContext.cpp}::alloc_column ( std::string  col_name,
const SQLTypeInfo data_target_info,
llvm::Value *  data_ptr,
llvm::Value *  data_size,
llvm::LLVMContext &  ctx,
llvm::IRBuilder<> &  ir_builder,
bool  byval 
)

Definition at line 88 of file TableFunctionCompilationContext.cpp.

References CHECK, and get_llvm_type_from_sql_column_type().

Referenced by TableFunctionCompilationContext::generateEntryPoint().

94  {
95  /*
96  Creates a new Column instance of given element type and initialize
97  its data ptr and sz members. If data ptr or sz are unspecified
98  (have nullptr values) then the corresponding members are
99  initialized with NULL and -1, respectively.
100  */
101  llvm::Type* data_ptr_llvm_type =
102  get_llvm_type_from_sql_column_type(data_target_info, ctx);
103  llvm::StructType* col_struct_type =
104  llvm::StructType::get(ctx,
105  {
106  data_ptr_llvm_type, /* T* ptr */
107  llvm::Type::getInt64Ty(ctx) /* int64_t sz */
108  });
109  auto col = ir_builder.CreateAlloca(col_struct_type);
110  col->setName(col_name);
111  auto col_ptr_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 0);
112  auto col_sz_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 1);
113  col_ptr_ptr->setName(col_name + ".ptr");
114  col_sz_ptr->setName(col_name + ".sz");
115 
116  if (data_ptr != nullptr) {
117  if (data_ptr->getType() == data_ptr_llvm_type->getPointerElementType()) {
118  ir_builder.CreateStore(data_ptr, col_ptr_ptr);
119  } else {
120  auto tmp = ir_builder.CreateBitCast(data_ptr, data_ptr_llvm_type);
121  ir_builder.CreateStore(tmp, col_ptr_ptr);
122  }
123  } else {
124  ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptr_llvm_type), col_ptr_ptr);
125  }
126  if (data_size != nullptr) {
127  auto data_size_type = data_size->getType();
128  if (data_size_type->isPointerTy()) {
129  CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
130  auto val = ir_builder.CreateLoad(data_size);
131  ir_builder.CreateStore(val, col_sz_ptr);
132  } else {
133  CHECK(data_size_type->isIntegerTy(64));
134  ir_builder.CreateStore(data_size, col_sz_ptr);
135  }
136  } else {
137  auto const_minus1 = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), -1, true);
138  ir_builder.CreateStore(const_minus1, col_sz_ptr);
139  }
140 
141  if (byval) {
142  return ir_builder.CreateLoad(col);
143  } else {
144  auto col_ptr = ir_builder.CreatePointerCast(
145  col_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
146  col_ptr->setName(col_name + "_ptr");
147  return col_ptr;
148  }
149 }
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Value* anonymous_namespace{TableFunctionCompilationContext.cpp}::alloc_column_list ( std::string  col_list_name,
const SQLTypeInfo data_target_info,
llvm::Value *  data_ptrs,
int  length,
llvm::Value *  data_size,
llvm::LLVMContext &  ctx,
llvm::IRBuilder<> &  ir_builder 
)

Definition at line 151 of file TableFunctionCompilationContext.cpp.

References CHECK.

Referenced by TableFunctionCompilationContext::generateEntryPoint().

157  {
158  /*
159  Creates a new ColumnList instance of given element type and initialize
160  its members. If data ptr or size are unspecified (have nullptr
161  values) then the corresponding members are initialized with NULL
162  and -1, respectively.
163  */
164  llvm::Type* data_ptrs_llvm_type = llvm::Type::getInt8PtrTy(ctx);
165 
166  llvm::StructType* col_list_struct_type =
167  llvm::StructType::get(ctx,
168  {
169  data_ptrs_llvm_type, /* int8_t* ptrs */
170  llvm::Type::getInt64Ty(ctx), /* int64_t length */
171  llvm::Type::getInt64Ty(ctx) /* int64_t size */
172  });
173  auto col_list = ir_builder.CreateAlloca(col_list_struct_type);
174  col_list->setName(col_list_name);
175  auto col_list_ptr_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 0);
176  auto col_list_length_ptr =
177  ir_builder.CreateStructGEP(col_list_struct_type, col_list, 1);
178  auto col_list_size_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 2);
179 
180  col_list_ptr_ptr->setName(col_list_name + ".ptrs");
181  col_list_length_ptr->setName(col_list_name + ".length");
182  col_list_size_ptr->setName(col_list_name + ".size");
183 
184  CHECK(length >= 0);
185  auto const_length = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), length, true);
186 
187  if (data_ptrs != nullptr) {
188  if (data_ptrs->getType() == data_ptrs_llvm_type->getPointerElementType()) {
189  ir_builder.CreateStore(data_ptrs, col_list_ptr_ptr);
190  } else {
191  auto tmp = ir_builder.CreateBitCast(data_ptrs, data_ptrs_llvm_type);
192  ir_builder.CreateStore(tmp, col_list_ptr_ptr);
193  }
194  } else {
195  ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptrs_llvm_type),
196  col_list_ptr_ptr);
197  }
198 
199  ir_builder.CreateStore(const_length, col_list_length_ptr);
200 
201  if (data_size != nullptr) {
202  auto data_size_type = data_size->getType();
203  if (data_size_type->isPointerTy()) {
204  CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
205  auto size_val = ir_builder.CreateLoad(data_size);
206  ir_builder.CreateStore(size_val, col_list_size_ptr);
207  } else {
208  CHECK(data_size_type->isIntegerTy(64));
209  ir_builder.CreateStore(data_size, col_list_size_ptr);
210  }
211  } else {
212  auto const_minus1 = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), -1, true);
213  ir_builder.CreateStore(const_minus1, col_list_size_ptr);
214  }
215 
216  auto col_list_ptr = ir_builder.CreatePointerCast(
217  col_list_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
218  col_list_ptr->setName(col_list_name + "_ptrs");
219  return col_list_ptr;
220 }
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the caller graph for this function:

llvm::Function* anonymous_namespace{TableFunctionCompilationContext.cpp}::generate_entry_point ( const CgenState cgen_state)

Definition at line 32 of file TableFunctionCompilationContext.cpp.

References CgenState::context_, get_int_type(), and CgenState::module_.

Referenced by TableFunctionCompilationContext::TableFunctionCompilationContext().

32  {
33  auto& ctx = cgen_state->context_;
34  const auto pi8_type = llvm::PointerType::get(get_int_type(8, ctx), 0);
35  const auto ppi8_type = llvm::PointerType::get(pi8_type, 0);
36  const auto pi64_type = llvm::PointerType::get(get_int_type(64, ctx), 0);
37  const auto ppi64_type = llvm::PointerType::get(pi64_type, 0);
38  const auto i32_type = get_int_type(32, ctx);
39 
40  const auto func_type = llvm::FunctionType::get(
41  i32_type, {ppi8_type, pi64_type, ppi64_type, pi64_type}, false);
42 
43  auto func = llvm::Function::Create(func_type,
44  llvm::Function::ExternalLinkage,
45  "call_table_function",
46  cgen_state->module_);
47  auto arg_it = func->arg_begin();
48  const auto input_cols_arg = &*arg_it;
49  input_cols_arg->setName("input_col_buffers");
50  const auto input_row_counts = &*(++arg_it);
51  input_row_counts->setName("input_row_counts");
52  const auto output_buffers = &*(++arg_it);
53  output_buffers->setName("output_buffers");
54  const auto output_row_count = &*(++arg_it);
55  output_row_count->setName("output_row_count");
56  return func;
57 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:324
llvm::LLVMContext & context_
Definition: CgenState.h:333

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Type* anonymous_namespace{TableFunctionCompilationContext.cpp}::get_llvm_type_from_sql_column_type ( const SQLTypeInfo  elem_ti,
llvm::LLVMContext &  ctx 
)
inline

Definition at line 59 of file TableFunctionCompilationContext.cpp.

References CHECK, logger::FATAL, SQLTypeInfo::get_size(), SQLTypeInfo::is_boolean(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_integer(), LOG, and toString().

Referenced by alloc_column().

60  {
61  if (elem_ti.is_fp()) {
62  switch (elem_ti.get_size()) {
63  case 4:
64  return llvm::Type::getFloatPtrTy(ctx);
65  case 8:
66  return llvm::Type::getDoublePtrTy(ctx);
67  }
68  }
69  if (elem_ti.is_boolean()) {
70  return llvm::Type::getInt8PtrTy(ctx);
71  }
72  CHECK(elem_ti.is_integer());
73  switch (elem_ti.get_size()) {
74  case 1:
75  return llvm::Type::getInt8PtrTy(ctx);
76  case 2:
77  return llvm::Type::getInt16PtrTy(ctx);
78  case 4:
79  return llvm::Type::getInt32PtrTy(ctx);
80  case 8:
81  return llvm::Type::getInt64PtrTy(ctx);
82  }
83  LOG(FATAL) << "get_llvm_type_from_sql_column_type: not implemented for "
84  << ::toString(elem_ti);
85  return nullptr;
86 }
HOST DEVICE int get_size() const
Definition: sqltypes.h:324
std::string toString(const ExtArgumentType &sig_type)
#define LOG(tag)
Definition: Logger.h:194
bool is_fp() const
Definition: sqltypes.h:493
bool is_integer() const
Definition: sqltypes.h:491
bool is_boolean() const
Definition: sqltypes.h:496
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function: