OmniSciDB  8a228a1076
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 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)
 

Function Documentation

◆ alloc_column()

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 
)

Definition at line 86 of file TableFunctionCompilationContext.cpp.

References CHECK, and get_llvm_type_from_sql_column_type().

Referenced by TableFunctionCompilationContext::generateEntryPoint().

91  {
92  /*
93  Creates a new Column instance of given element type and initialize
94  its data ptr and sz members. If data ptr or sz are unspecified
95  (have nullptr values) then the corresponding members are
96  initialized with NULL and -1, respectively.
97  */
98  llvm::Type* data_ptr_llvm_type =
99  get_llvm_type_from_sql_column_type(data_target_info, ctx);
100  llvm::StructType* col_struct_type =
101  llvm::StructType::get(ctx,
102  {
103  data_ptr_llvm_type, /* T* ptr */
104  llvm::Type::getInt64Ty(ctx) /* int64_t sz */
105  });
106  auto col = ir_builder.CreateAlloca(col_struct_type);
107  col->setName(col_name);
108  auto col_ptr_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 0);
109  auto col_sz_ptr = ir_builder.CreateStructGEP(col_struct_type, col, 1);
110  col_ptr_ptr->setName(col_name + ".ptr");
111  col_sz_ptr->setName(col_name + ".sz");
112 
113  if (data_ptr != nullptr) {
114  if (data_ptr->getType() == data_ptr_llvm_type->getPointerElementType()) {
115  ir_builder.CreateStore(data_ptr, col_ptr_ptr);
116  } else {
117  auto tmp = ir_builder.CreateBitCast(data_ptr, data_ptr_llvm_type);
118  ir_builder.CreateStore(tmp, col_ptr_ptr);
119  }
120  } else {
121  ir_builder.CreateStore(llvm::Constant::getNullValue(data_ptr_llvm_type), col_ptr_ptr);
122  }
123  if (data_size != nullptr) {
124  auto data_size_type = data_size->getType();
125  if (data_size_type->isPointerTy()) {
126  CHECK(data_size_type->getPointerElementType()->isIntegerTy(64));
127  auto val = ir_builder.CreateLoad(data_size);
128  ir_builder.CreateStore(val, col_sz_ptr);
129  } else {
130  CHECK(data_size_type->isIntegerTy(64));
131  ir_builder.CreateStore(data_size, col_sz_ptr);
132  }
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  return col;
138 }
llvm::Type * get_llvm_type_from_sql_column_type(const SQLTypeInfo 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:

◆ generate_entry_point()

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::TableFunctionCompilationContext().

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, {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 input_cols_arg = &*arg_it;
48  input_cols_arg->setName("input_col_buffers");
49  const auto input_row_count = &*(++arg_it);
50  input_row_count->setName("input_row_count");
51  const auto output_buffers = &*(++arg_it);
52  output_buffers->setName("output_buffers");
53  const auto output_row_count = &*(++arg_it);
54  output_row_count->setName("output_row_count");
55  return func;
56 }
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
llvm::Module * module_
Definition: CgenState.h:314
llvm::LLVMContext & context_
Definition: CgenState.h:317
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_llvm_type_from_sql_column_type()

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

Definition at line 58 of file TableFunctionCompilationContext.cpp.

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

Referenced by alloc_column().

59  {
60  CHECK(ti.is_column());
61  const auto& elem_ti = ti.get_elem_type();
62  if (elem_ti.is_fp()) {
63  switch (elem_ti.get_size()) {
64  case 4:
65  return llvm::Type::getFloatPtrTy(ctx);
66  case 8:
67  return llvm::Type::getDoublePtrTy(ctx);
68  }
69  }
70  CHECK(elem_ti.is_integer());
71  switch (elem_ti.get_size()) {
72  case 1:
73  return llvm::Type::getInt8PtrTy(ctx);
74  case 2:
75  return llvm::Type::getInt16PtrTy(ctx);
76  case 4:
77  return llvm::Type::getInt32PtrTy(ctx);
78  case 8:
79  return llvm::Type::getInt64PtrTy(ctx);
80  }
81 
82  UNREACHABLE();
83  return nullptr;
84 }
#define UNREACHABLE()
Definition: Logger.h:241
bool is_column() const
Definition: sqltypes.h:429
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:623
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the call graph for this function:
+ Here is the caller graph for this function: