OmniSciDB  a5dc49c757
 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)
 
void initialize_ptr_member (llvm::Value *member_ptr, llvm::Type *member_llvm_type, llvm::Value *value_ptr, llvm::IRBuilder<> &ir_builder)
 
template<typename T >
void initialize_int_member (llvm::Value *member_ptr, llvm::Value *value, int64_t default_value, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
 
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::Value *data_str_dict_proxy_ptr, 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::Value *data_str_dict_proxy_ptrs, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
 
llvm::Value * alloc_array (std::string arr_name, const size_t index, const SQLTypeInfo &data_target_info, llvm::Value *data_ptr, llvm::Value *data_size, llvm::Value *data_is_null, llvm::LLVMContext &ctx, llvm::IRBuilder<> &ir_builder)
 
std::string exprsKey (const std::vector< Analyzer::Expr * > &exprs)
 

Function Documentation

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

Definition at line 275 of file TableFunctionCompilationContext.cpp.

References SQLTypeInfo::get_elem_type(), get_llvm_type_from_sql_column_type(), and initialize_ptr_member().

Referenced by TableFunctionCompilationContext::generateEntryPoint().

282  {
283  /*
284  Creates a new Array instance of given element type and initialize
285  its data ptr and sz members when specified. If data ptr or sz are
286  unspecified (have nullptr values) then the corresponding members
287  are initialized with NULL and -1, respectively.
288 
289  Return a pointer to Array instance.
290  */
291  llvm::StructType* arr_struct_type;
292  llvm::Type* data_ptr_llvm_type =
293  get_llvm_type_from_sql_column_type(data_target_info.get_elem_type(), ctx);
294  arr_struct_type =
295  llvm::StructType::get(ctx,
296  {
297  data_ptr_llvm_type, /* T* ptr_ */
298  llvm::Type::getInt64Ty(ctx), /* int64_t size_ */
299  llvm::Type::getInt8Ty(ctx) /* int8_t is_null_ */
300  });
301 
302  auto arr = ir_builder.CreateAlloca(arr_struct_type);
303  arr->setName(arr_name);
304  auto arr_ptr_ptr = ir_builder.CreateStructGEP(arr_struct_type, arr, 0);
305  auto arr_sz_ptr = ir_builder.CreateStructGEP(arr_struct_type, arr, 1);
306  auto arr_is_null_ptr = ir_builder.CreateStructGEP(arr_struct_type, arr, 2);
307  arr_ptr_ptr->setName(arr_name + ".ptr");
308  arr_sz_ptr->setName(arr_name + ".size");
309  arr_is_null_ptr->setName(arr_name + ".is_null");
310 
311  initialize_ptr_member(arr_ptr_ptr, data_ptr_llvm_type, data_ptr, ir_builder);
312  initialize_int_member<int64_t>(arr_sz_ptr, data_size, -1, ctx, ir_builder);
313  initialize_int_member<int8_t>(arr_is_null_ptr, data_is_null, -1, ctx, ir_builder);
314  auto arr_ptr = ir_builder.CreatePointerCast(
315  arr_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
316  arr_ptr->setName(arr_name + "_pointer");
317  return arr_ptr;
318 }
void initialize_ptr_member(llvm::Value *member_ptr, llvm::Type *member_llvm_type, llvm::Value *value_ptr, llvm::IRBuilder<> &ir_builder)
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:977

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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::Value *  data_str_dict_proxy_ptr,
llvm::LLVMContext &  ctx,
llvm::IRBuilder<> &  ir_builder 
)

Definition at line 129 of file TableFunctionCompilationContext.cpp.

References SQLTypeInfo::get_compression(), get_llvm_type_from_sql_column_type(), initialize_ptr_member(), SQLTypeInfo::is_string(), and kENCODING_DICT.

Referenced by TableFunctionCompilationContext::generateEntryPoint().

136  {
137  /*
138  Creates a new Column instance of given element type and initialize
139  its data ptr and sz members when specified. If data ptr or sz are
140  unspecified (have nullptr values) then the corresponding members
141  are initialized with NULL and -1, respectively.
142 
143  If we are allocating a TextEncodingDict Column type, this function
144  adds and populates a int8* pointer to a StringDictProxy object.
145 
146  Return a pair of Column allocation (caller should apply
147  builder.CreateLoad to it in order to construct a Column instance
148  as a value) and a pointer to the Column instance.
149  */
150  const bool is_text_encoding_dict_type =
151  data_target_info.is_string() &&
152  data_target_info.get_compression() == kENCODING_DICT;
153  llvm::StructType* col_struct_type;
154  llvm::Type* data_ptr_llvm_type =
155  get_llvm_type_from_sql_column_type(data_target_info, ctx);
156  if (is_text_encoding_dict_type) {
157  col_struct_type = llvm::StructType::get(
158  ctx,
159  {
160  data_ptr_llvm_type, /* T* ptr */
161  llvm::Type::getInt64Ty(ctx), /* int64_t sz */
162  llvm::Type::getInt8PtrTy(ctx) /* int8_t* string_dictionary_ptr */
163  });
164  } else {
165  col_struct_type =
166  llvm::StructType::get(ctx,
167  {
168  data_ptr_llvm_type, /* T* ptr */
169  llvm::Type::getInt64Ty(ctx) /* int64_t sz */
170  });
171  }
172 
173  auto col = ir_builder.CreateAlloca(col_struct_type);
174  col->setName(col_name);
175  auto col_ptr_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 0);
176  auto col_sz_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 1);
177  auto col_str_dict_ptr = is_text_encoding_dict_type
178  ? ir_builder.CreateStructGEP(col_struct_type, col, 2)
179  : nullptr;
180  col_ptr_ptr->setName(col_name + ".ptr");
181  col_sz_ptr->setName(col_name + ".sz");
182  if (is_text_encoding_dict_type) {
183  col_str_dict_ptr->setName(col_name + ".string_dict_proxy");
184  }
185 
186  initialize_ptr_member(col_ptr_ptr, data_ptr_llvm_type, data_ptr, ir_builder);
187  initialize_int_member<int64_t>(col_sz_ptr, data_size, -1, ctx, ir_builder);
188  if (is_text_encoding_dict_type) {
189  initialize_ptr_member(col_str_dict_ptr,
190  llvm::Type::getInt8PtrTy(ctx),
191  data_str_dict_proxy_ptr,
192  ir_builder);
193  }
194  auto col_ptr = ir_builder.CreatePointerCast(
195  col_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
196  col_ptr->setName(col_name + "_ptr");
197  return {col, col_ptr};
198 }
void initialize_ptr_member(llvm::Value *member_ptr, llvm::Type *member_llvm_type, llvm::Value *value_ptr, llvm::IRBuilder<> &ir_builder)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo elem_ti, llvm::LLVMContext &ctx)
bool is_string() const
Definition: sqltypes.h:561

+ 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::Value *  data_str_dict_proxy_ptrs,
llvm::LLVMContext &  ctx,
llvm::IRBuilder<> &  ir_builder 
)

Definition at line 200 of file TableFunctionCompilationContext.cpp.

References CHECK, SQLTypeInfo::get_compression(), initialize_ptr_member(), SQLTypeInfo::is_string(), and kENCODING_DICT.

Referenced by TableFunctionCompilationContext::generateEntryPoint().

207  {
208  /*
209  Creates a new ColumnList instance of given element type and initialize
210  its members. If data ptr or size are unspecified (have nullptr
211  values) then the corresponding members are initialized with NULL
212  and -1, respectively.
213  */
214  llvm::Type* data_ptrs_llvm_type = llvm::Type::getInt8PtrTy(ctx);
215  const bool is_text_encoding_dict_type =
216  data_target_info.is_string() &&
217  data_target_info.get_compression() == kENCODING_DICT;
218 
219  llvm::StructType* col_list_struct_type =
220  is_text_encoding_dict_type
221  ? llvm::StructType::get(
222  ctx,
223  {
224  data_ptrs_llvm_type, /* int8_t* ptrs */
225  llvm::Type::getInt64Ty(ctx), /* int64_t length */
226  llvm::Type::getInt64Ty(ctx), /* int64_t size */
227  data_ptrs_llvm_type /* int8_t* str_dict_proxy_ptrs */
228  })
229  : llvm::StructType::get(ctx,
230  {
231  data_ptrs_llvm_type, /* int8_t* ptrs */
232  llvm::Type::getInt64Ty(ctx), /* int64_t length */
233  llvm::Type::getInt64Ty(ctx) /* int64_t size */
234  });
235 
236  auto col_list = ir_builder.CreateAlloca(col_list_struct_type);
237  col_list->setName(col_list_name);
238  auto col_list_ptr_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 0);
239  auto col_list_length_ptr =
240  ir_builder.CreateStructGEP(col_list_struct_type, col_list, 1);
241  auto col_list_size_ptr = ir_builder.CreateStructGEP(col_list_struct_type, col_list, 2);
242  auto col_str_dict_ptr_ptr =
243  is_text_encoding_dict_type
244  ? ir_builder.CreateStructGEP(col_list_struct_type, col_list, 3)
245  : nullptr;
246 
247  col_list_ptr_ptr->setName(col_list_name + ".ptrs");
248  col_list_length_ptr->setName(col_list_name + ".length");
249  col_list_size_ptr->setName(col_list_name + ".size");
250  if (is_text_encoding_dict_type) {
251  col_str_dict_ptr_ptr->setName(col_list_name + ".string_dict_proxies");
252  }
253 
254  initialize_ptr_member(col_list_ptr_ptr, data_ptrs_llvm_type, data_ptrs, ir_builder);
255 
256  CHECK(length >= 0);
257  auto const_length = llvm::ConstantInt::get(llvm::Type::getInt64Ty(ctx), length, true);
258  ir_builder.CreateStore(const_length, col_list_length_ptr);
259 
260  initialize_int_member<int64_t>(col_list_size_ptr, data_size, -1, ctx, ir_builder);
261 
262  if (is_text_encoding_dict_type) {
263  initialize_ptr_member(col_str_dict_ptr_ptr,
264  data_str_dict_proxy_ptrs->getType(),
265  data_str_dict_proxy_ptrs,
266  ir_builder);
267  }
268 
269  auto col_list_ptr = ir_builder.CreatePointerCast(
270  col_list_ptr_ptr, llvm::PointerType::get(llvm::Type::getInt8Ty(ctx), 0));
271  col_list_ptr->setName(col_list_name + "_ptrs");
272  return col_list_ptr;
273 }
void initialize_ptr_member(llvm::Value *member_ptr, llvm::Type *member_llvm_type, llvm::Value *value_ptr, llvm::IRBuilder<> &ir_builder)
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
#define CHECK(condition)
Definition: Logger.h:291
bool is_string() const
Definition: sqltypes.h:561

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string anonymous_namespace{TableFunctionCompilationContext.cpp}::exprsKey ( const std::vector< Analyzer::Expr * > &  exprs)

Definition at line 320 of file TableFunctionCompilationContext.cpp.

References run_benchmark_import::result.

Referenced by TableFunctionCompilationContext::compile().

320  {
321  std::string result;
322  for (const auto& expr : exprs) {
323  const auto& ti = expr->get_type_info();
324  result += ti.to_string() + ", ";
325  }
326  return result;
327 }

+ 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,
41  {pi8_type, ppi8_type, pi64_type, ppi8_type, ppi64_type, ppi8_type, pi64_type},
42  false);
43 
44  auto func = llvm::Function::Create(func_type,
45  llvm::Function::ExternalLinkage,
46  "call_table_function",
47  cgen_state->module_);
48  auto arg_it = func->arg_begin();
49  const auto mgr_arg = &*arg_it;
50  mgr_arg->setName("mgr_ptr");
51  const auto input_cols_arg = &*(++arg_it);
52  input_cols_arg->setName("input_col_buffers");
53  const auto input_row_counts = &*(++arg_it);
54  input_row_counts->setName("input_row_counts");
55  const auto input_str_dict_proxies = &*(++arg_it);
56  input_str_dict_proxies->setName("input_str_dict_proxies");
57  const auto output_buffers = &*(++arg_it);
58  output_buffers->setName("output_buffers");
59  const auto output_str_dict_proxies = &*(++arg_it);
60  output_str_dict_proxies->setName("output_str_dict_proxies");
61  const auto output_row_count = &*(++arg_it);
62  output_row_count->setName("output_row_count");
63  return func;
64 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:373
llvm::LLVMContext & context_
Definition: CgenState.h:382

+ 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 66 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_fp(), SQLTypeInfo::is_integer(), SQLTypeInfo::is_string(), SQLTypeInfo::is_text_encoding_none(), SQLTypeInfo::is_timestamp(), kENCODING_DICT, LOG, toString(), and SQLTypeInfo::usesFlatBuffer().

Referenced by alloc_array(), and alloc_column().

67  {
68  if (elem_ti.is_fp()) {
69  return get_fp_ptr_type(elem_ti.get_size() * 8, ctx);
70  } else if (elem_ti.is_boolean()) {
71  return get_int_ptr_type(8, ctx);
72  } else if (elem_ti.is_integer()) {
73  return get_int_ptr_type(elem_ti.get_size() * 8, ctx);
74  } else if (elem_ti.is_string()) {
75  if (elem_ti.get_compression() == kENCODING_DICT) {
76  return get_int_ptr_type(elem_ti.get_size() * 8, ctx);
77  }
78  CHECK(elem_ti.is_text_encoding_none());
79  return get_int_ptr_type(8, ctx);
80  } else if (elem_ti.is_timestamp()) {
81  return get_int_ptr_type(elem_ti.get_size() * 8, ctx);
82  } else if (elem_ti.usesFlatBuffer()) {
83  return get_int_ptr_type(8, ctx);
84  }
85  LOG(FATAL) << "get_llvm_type_from_sql_column_type: not implemented for "
86  << ::toString(elem_ti);
87  return nullptr;
88 }
llvm::Type * get_fp_ptr_type(const int width, llvm::LLVMContext &context)
HOST DEVICE int get_size() const
Definition: sqltypes.h:403
bool is_timestamp() const
Definition: sqltypes.h:1046
#define LOG(tag)
Definition: Logger.h:285
bool is_fp() const
Definition: sqltypes.h:573
bool is_integer() const
Definition: sqltypes.h:567
bool usesFlatBuffer() const
Definition: sqltypes.h:1083
bool is_boolean() const
Definition: sqltypes.h:582
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
#define CHECK(condition)
Definition: Logger.h:291
bool is_string() const
Definition: sqltypes.h:561
bool is_text_encoding_none() const
Definition: sqltypes.h:614
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:

template<typename T >
void anonymous_namespace{TableFunctionCompilationContext.cpp}::initialize_int_member ( llvm::Value *  member_ptr,
llvm::Value *  value,
int64_t  default_value,
llvm::LLVMContext &  ctx,
llvm::IRBuilder<> &  ir_builder 
)

Definition at line 107 of file TableFunctionCompilationContext.cpp.

References CHECK, and heavydb.dtypes::T.

111  {
112  llvm::Value* val = nullptr;
113  if (value != nullptr) {
114  auto value_type = value->getType();
115  if (value_type->isPointerTy()) {
116  CHECK(value_type->getPointerElementType()->isIntegerTy(sizeof(T) * 8));
117  val = ir_builder.CreateLoad(value->getType()->getPointerElementType(), value);
118  } else {
119  CHECK(value_type->isIntegerTy(sizeof(T) * 8));
120  val = value;
121  }
122  ir_builder.CreateStore(val, member_ptr);
123  } else {
124  auto const_default = ll_int<T>(default_value, ctx);
125  ir_builder.CreateStore(const_default, member_ptr);
126  }
127 }
#define CHECK(condition)
Definition: Logger.h:291
void anonymous_namespace{TableFunctionCompilationContext.cpp}::initialize_ptr_member ( llvm::Value *  member_ptr,
llvm::Type member_llvm_type,
llvm::Value *  value_ptr,
llvm::IRBuilder<> &  ir_builder 
)

Definition at line 90 of file TableFunctionCompilationContext.cpp.

Referenced by alloc_array(), alloc_column(), and alloc_column_list().

93  {
94  if (value_ptr != nullptr) {
95  if (value_ptr->getType() == member_llvm_type->getPointerElementType()) {
96  ir_builder.CreateStore(value_ptr, member_ptr);
97  } else {
98  auto tmp = ir_builder.CreateBitCast(value_ptr, member_llvm_type);
99  ir_builder.CreateStore(tmp, member_ptr);
100  }
101  } else {
102  ir_builder.CreateStore(llvm::Constant::getNullValue(member_llvm_type), member_ptr);
103  }
104 }

+ Here is the caller graph for this function: