OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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)
 
std::tuple< llvm::Value
*, llvm::Value * > 
alloc_column (std::string col_name, const size_t index, const SQLTypeInfo &data_target_info, llvm::Value *data_ptr, llvm::Value *data_size, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
 
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

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

Definition at line 80 of file TableFunctionCompilationContext.cpp.

References CHECK, and get_llvm_type_from_sql_column_type().

Referenced by TableFunctionCompilationContext::generateEntryPoint().

86  {
87  /*
88  Creates a new Column instance of given element type and initialize
89  its data ptr and sz members when specified. If data ptr or sz are
90  unspecified (have nullptr values) then the corresponding members
91  are initialized with NULL and -1, respectively.
92 
93  Return a pair of Column allocation (caller should apply
94  builder.CreateLoad to it in order to construct a Column instance
95  as a value) and a pointer to the Column instance.
96  */
97  llvm::Type* data_ptr_llvm_type =
98  get_llvm_type_from_sql_column_type(data_target_info, ctx);
99  llvm::StructType* col_struct_type =
100  llvm::StructType::get(ctx,
101  {
102  data_ptr_llvm_type, /* T* ptr */
103  llvm::Type::getInt64Ty(ctx) /* int64_t sz */
104  });
105  auto col = ir_builder.CreateAlloca(col_struct_type);
106  col->setName(col_name);
107  auto col_ptr_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 0);
108  auto col_sz_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 1);
109  col_ptr_ptr->setName(col_name + ".ptr");
110  col_sz_ptr->setName(col_name + ".sz");
111 
112  if (data_ptr != nullptr) {
113  if (data_ptr->getType() == data_ptr_llvm_type->getPointerElementType()) {
114  ir_builder.CreateStore(data_ptr, col_ptr_ptr);
115  } else {
116  auto tmp = ir_builder.CreateBitCast(data_ptr, data_ptr_llvm_type);
117  ir_builder.CreateStore(tmp, col_ptr_ptr);
118  }
119  } else {
120  ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptr_llvm_type), col_ptr_ptr);
121  }
122  if (data_size != nullptr) {
123  auto data_size_type = data_size->getType();
124  llvm::Value* size_val = nullptr;
125  if (data_size_type->isPointerTy()) {
126  CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
127  size_val = ir_builder.CreateLoad(data_size);
128  } else {
129  CHECK(data_size_type->isIntegerTy(64));
130  size_val = data_size;
131  }
132  ir_builder.CreateStore(size_val, col_sz_ptr);
133  } else {
134  auto const_minus1 = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), -1, true);
135  ir_builder.CreateStore(const_minus1, col_sz_ptr);
136  }
137  auto col_ptr = ir_builder.CreatePointerCast(
138  col_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
139  col_ptr->setName(col_name + "_ptr");
140  return {col, col_ptr};
141 }
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
#define CHECK(condition)
Definition: Logger.h:209

+ 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 143 of file TableFunctionCompilationContext.cpp.

References CHECK.

Referenced by TableFunctionCompilationContext::generateEntryPoint().

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

+ Here is the caller graph for this function:

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

Definition at line 31 of file TableFunctionCompilationContext.cpp.

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

Referenced by TableFunctionCompilationContext::compile().

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

+ 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 60 of file TableFunctionCompilationContext.cpp.

References CHECK, logger::FATAL, SQLTypeInfo::get_compression(), get_fp_ptr_type(), get_int_ptr_type(), SQLTypeInfo::get_size(), SQLTypeInfo::is_boolean(), SQLTypeInfo::is_bytes(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), kENCODING_DICT, LOG, and toString().

Referenced by alloc_column().

61  {
62  if (elem_ti.is_fp()) {
63  return get_fp_ptr_type(elem_ti.get_size() * 8, ctx);
64  } else if (elem_ti.is_boolean()) {
65  return get_int_ptr_type(8, ctx);
66  } else if (elem_ti.is_integer()) {
67  return get_int_ptr_type(elem_ti.get_size() * 8, ctx);
68  } else if (elem_ti.is_string()) {
69  if (elem_ti.get_compression() == kENCODING_DICT) {
70  return get_int_ptr_type(elem_ti.get_size() * 8, ctx);
71  }
72  CHECK(elem_ti.is_bytes()); // None encoded string
73  return get_int_ptr_type(8, ctx);
74  }
75  LOG(FATAL) << "get_llvm_type_from_sql_column_type: not implemented for "
76  << ::toString(elem_ti);
77  return nullptr;
78 }
llvm::Type * get_fp_ptr_type(const int width, llvm::LLVMContext &context)
HOST DEVICE int get_size() const
Definition: sqltypes.h:339
std::string toString(const ExtArgumentType &sig_type)
#define LOG(tag)
Definition: Logger.h:203
bool is_fp() const
Definition: sqltypes.h:513
bool is_integer() const
Definition: sqltypes.h:511
bool is_boolean() const
Definition: sqltypes.h:516
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
bool is_bytes() const
Definition: sqltypes.h:524
#define CHECK(condition)
Definition: Logger.h:209
bool is_string() const
Definition: sqltypes.h:509
llvm::Type * get_int_ptr_type(const int width, llvm::LLVMContext &context)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: