OmniSciDB  340b00dbf6
 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)
 

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:197

+ Here is the call graph for this function:

+ 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_count = &*(++arg_it);
51  input_row_count->setName("input_row_count");
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:318
llvm::LLVMContext & context_
Definition: CgenState.h:327

+ 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:340
std::string toString(const ExtArgumentType &sig_type)
#define LOG(tag)
Definition: Logger.h:188
bool is_fp() const
Definition: sqltypes.h:491
bool is_integer() const
Definition: sqltypes.h:489
bool is_boolean() const
Definition: sqltypes.h:494
#define CHECK(condition)
Definition: Logger.h:197

+ Here is the call graph for this function:

+ Here is the caller graph for this function: