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

Classes

class  Params
 

Functions

template<typename... ATTRS>
llvm::AttributeList make_attribute_list (llvm::Module const *const mod, unsigned const index, ATTRS const ...attrs)
 
template<bool IS_GROUP_BY, size_t NTYPES = 13u>
Params< NTYPES > make_params (llvm::Module const *const mod, bool const hoist_literals)
 
llvm::Typeget_pointer_element_type (llvm::Value *value)
 
llvm::Function * default_func_builder (llvm::Module *mod, const std::string &name)
 
llvm::Function * pos_start (llvm::Module *mod)
 
llvm::Function * group_buff_idx (llvm::Module *mod)
 
llvm::Function * pos_step (llvm::Module *mod)
 
llvm::Function * row_process (llvm::Module *mod, const size_t aggr_col_count, const bool hoist_literals)
 

Function Documentation

llvm::Function* anonymous_namespace{QueryTemplateGenerator.cpp}::default_func_builder ( llvm::Module *  mod,
const std::string &  name 
)

Definition at line 154 of file QueryTemplateGenerator.cpp.

References make_attribute_list().

Referenced by group_buff_idx(), and pos_start().

154  {
155  using namespace llvm;
156 
157  std::vector<Type*> func_args;
158  FunctionType* func_type = FunctionType::get(
159  /*Result=*/IntegerType::get(mod->getContext(), 32),
160  /*Params=*/func_args,
161  /*isVarArg=*/false);
162 
163  auto func_ptr = mod->getFunction(name);
164  if (!func_ptr) {
165  func_ptr = Function::Create(
166  /*Type=*/func_type,
167  /*Linkage=*/GlobalValue::ExternalLinkage,
168  /*Name=*/name,
169  mod); // (external, no body)
170  func_ptr->setCallingConv(CallingConv::C);
171  }
172  func_ptr->setAttributes(
173  make_attribute_list(mod, llvm::AttributeList::AttrIndex::FunctionIndex));
174  return func_ptr;
175 }
llvm::AttributeList make_attribute_list(llvm::Module const *const mod, unsigned const index, ATTRS const ...attrs)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Type* anonymous_namespace{QueryTemplateGenerator.cpp}::get_pointer_element_type ( llvm::Value *  value)
inline

Definition at line 145 of file QueryTemplateGenerator.cpp.

References CHECK, pointer_type(), and run_benchmark_import::type.

Referenced by query_group_by_template(), and query_template().

145  {
146  CHECK(value);
147  auto type = value->getType();
148  CHECK(type && type->isPointerTy());
149  auto pointer_type = llvm::dyn_cast<llvm::PointerType>(type);
150  CHECK(pointer_type);
151  return pointer_type->getPointerElementType();
152 }
Type pointer_type(const Type pointee)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Function* anonymous_namespace{QueryTemplateGenerator.cpp}::group_buff_idx ( llvm::Module *  mod)

Definition at line 181 of file QueryTemplateGenerator.cpp.

References default_func_builder().

Referenced by query_group_by_template(), and query_template().

181  {
182  return default_func_builder(mod, "group_buff_idx");
183 }
llvm::Function * default_func_builder(llvm::Module *mod, const std::string &name)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename... ATTRS>
llvm::AttributeList anonymous_namespace{QueryTemplateGenerator.cpp}::make_attribute_list ( llvm::Module const *const  mod,
unsigned const  index,
ATTRS const ...  attrs 
)

Definition at line 33 of file QueryTemplateGenerator.cpp.

Referenced by anonymous_namespace{QueryTemplateGenerator.cpp}::Params< NTYPES >::addAttributes(), default_func_builder(), pos_step(), and row_process().

35  {
36  static_assert((std::is_same_v<llvm::Attribute::AttrKind, ATTRS> && ...));
37  // llvm::AttrBuilder basically wraps a llvm::SmallVector<llvm::Attribute, 8>.
38  static_assert(sizeof...(ATTRS) <= 8, "Use a llvm::SmallVector with a larger size.");
39 #if 14 <= LLVM_VERSION_MAJOR
40  llvm::AttrBuilder attr_builder(mod->getContext());
41 #else
42  llvm::AttrBuilder attr_builder;
43 #endif
44  (attr_builder.addAttribute(attrs), ...);
45  return llvm::AttributeList::get(mod->getContext(), index, attr_builder);
46 }

+ Here is the caller graph for this function:

template<bool IS_GROUP_BY, size_t NTYPES = 13u>
Params<NTYPES> anonymous_namespace{QueryTemplateGenerator.cpp}::make_params ( llvm::Module const *const  mod,
bool const  hoist_literals 
)

Definition at line 92 of file QueryTemplateGenerator.cpp.

References anonymous_namespace{QueryTemplateGenerator.cpp}::Params< NTYPES >::addAttributes(), report::params, and anonymous_namespace{QueryTemplateGenerator.cpp}::Params< NTYPES >::pushBack().

92  {
93  constexpr llvm::Attribute::AttrKind NoCapture = llvm::Attribute::NoCapture;
94  auto* const i8_type = llvm::IntegerType::get(mod->getContext(), 8);
95  auto* const i32_type = llvm::IntegerType::get(mod->getContext(), 32);
96  auto* const i64_type = llvm::IntegerType::get(mod->getContext(), 64);
97  auto* const pi8_type = llvm::PointerType::get(i8_type, 0);
98  auto* const ppi8_type = llvm::PointerType::get(pi8_type, 0);
99  auto* const pi32_type = llvm::PointerType::get(i32_type, 0);
100  auto* const pi64_type = llvm::PointerType::get(i64_type, 0);
101  auto* const ppi64_type = llvm::PointerType::get(pi64_type, 0);
102 
103  // Must match parameter order in QueryExecutionContext::launchCpuCode()
104  // hoist_literals is true iff literals is included in the parameter list.
105  // NTYPES should equal the max number of parameters to avoid dynamic memory allocation.
106  Params<NTYPES> params(mod);
107  params.pushBack(pi32_type, "error_code");
108  params.pushBack(pi32_type, "total_matched");
109  params.pushBack(ppi64_type, IS_GROUP_BY ? "group_by_buffers" : "out");
110  params.pushBack(i32_type, "frag_idx");
111  if constexpr (IS_GROUP_BY) {
112  constexpr llvm::Attribute::AttrKind ReadOnly = llvm::Attribute::ReadOnly;
113  constexpr llvm::Attribute::AttrKind UWTable = llvm::Attribute::UWTable;
114  params.pushBack(pi32_type, "row_index_resume", NoCapture, ReadOnly);
115  params.pushBack(ppi8_type, "byte_stream", NoCapture, ReadOnly);
116  if (hoist_literals) {
117  params.pushBack(pi8_type, "literals", NoCapture, ReadOnly);
118  }
119  params.pushBack(pi64_type, "row_count_ptr", NoCapture, ReadOnly);
120  params.pushBack(pi64_type, "frag_row_off_ptr", NoCapture, ReadOnly);
121  params.pushBack(pi32_type, "max_matched_ptr", NoCapture, ReadOnly);
122  params.pushBack(pi64_type, "agg_init_val", NoCapture, ReadOnly);
123  params.pushBack(pi64_type, "join_hash_tables", NoCapture, ReadOnly);
124  params.pushBack(pi8_type, "row_func_mgr", NoCapture, ReadOnly);
125  params.addAttributes(llvm::AttributeList::AttrIndex::FunctionIndex, UWTable);
126  } else {
127  // For an unknown reason, commit 70ab189189cc0599d973f3f021169a6846298cf5
128  // removed the ReadOnly and UWTable attributes for (non-group_by) query_template()
129  // but kept them for query_group_by_template().
130  params.pushBack(pi32_type, "row_index_resume", NoCapture); // start_rowid
131  params.pushBack(ppi8_type, "byte_stream", NoCapture); // col_buffers
132  if (hoist_literals) {
133  params.pushBack(pi8_type, "literals", NoCapture);
134  }
135  params.pushBack(pi64_type, "row_count_ptr", NoCapture); // num_rows
136  params.pushBack(pi64_type, "frag_row_off_ptr", NoCapture);
137  params.pushBack(pi32_type, "max_matched_ptr", NoCapture);
138  params.pushBack(pi64_type, "agg_init_val", NoCapture);
139  params.pushBack(pi64_type, "join_hash_tables", NoCapture);
140  params.pushBack(pi8_type, "row_func_mgr", NoCapture);
141  }
142  return params;
143 }
dictionary params
Definition: report.py:27

+ Here is the call graph for this function:

llvm::Function* anonymous_namespace{QueryTemplateGenerator.cpp}::pos_start ( llvm::Module *  mod)

Definition at line 177 of file QueryTemplateGenerator.cpp.

References default_func_builder().

Referenced by query_group_by_template(), and query_template().

177  {
178  return default_func_builder(mod, "pos_start");
179 }
llvm::Function * default_func_builder(llvm::Module *mod, const std::string &name)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Function* anonymous_namespace{QueryTemplateGenerator.cpp}::pos_step ( llvm::Module *  mod)

Definition at line 185 of file QueryTemplateGenerator.cpp.

References make_attribute_list().

Referenced by query_group_by_template(), and query_template().

185  {
186  using namespace llvm;
187 
188  std::vector<Type*> func_args;
189  FunctionType* func_type = FunctionType::get(
190  /*Result=*/IntegerType::get(mod->getContext(), 32),
191  /*Params=*/func_args,
192  /*isVarArg=*/false);
193 
194  auto func_ptr = mod->getFunction("pos_step");
195  if (!func_ptr) {
196  func_ptr = Function::Create(
197  /*Type=*/func_type,
198  /*Linkage=*/GlobalValue::ExternalLinkage,
199  /*Name=*/"pos_step",
200  mod); // (external, no body)
201  func_ptr->setCallingConv(CallingConv::C);
202  }
203  func_ptr->setAttributes(
204  make_attribute_list(mod, llvm::AttributeList::AttrIndex::FunctionIndex));
205  return func_ptr;
206 }
llvm::AttributeList make_attribute_list(llvm::Module const *const mod, unsigned const index, ATTRS const ...attrs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

llvm::Function* anonymous_namespace{QueryTemplateGenerator.cpp}::row_process ( llvm::Module *  mod,
const size_t  aggr_col_count,
const bool  hoist_literals 
)

Definition at line 208 of file QueryTemplateGenerator.cpp.

References make_attribute_list().

Referenced by query_group_by_template(), and query_template().

210  {
211  using namespace llvm;
212 
213  std::vector<Type*> func_args;
214  auto i8_type = IntegerType::get(mod->getContext(), 8);
215  auto i32_type = IntegerType::get(mod->getContext(), 32);
216  auto i64_type = IntegerType::get(mod->getContext(), 64);
217  auto pi32_type = PointerType::get(i32_type, 0);
218  auto pi64_type = PointerType::get(i64_type, 0);
219 
220  if (aggr_col_count) {
221  for (size_t i = 0; i < aggr_col_count; ++i) {
222  func_args.push_back(pi64_type);
223  }
224  } else { // group by query
225  func_args.push_back(pi64_type); // groups buffer
226  func_args.push_back(pi64_type); // varlen output buffer
227  func_args.push_back(pi32_type); // 1 iff current row matched, else 0
228  func_args.push_back(pi32_type); // total rows matched from the caller
229  func_args.push_back(pi32_type); // total rows matched before atomic increment
230  func_args.push_back(pi32_type); // max number of slots in the output buffer
231  }
232 
233  func_args.push_back(pi64_type); // aggregate init values
234 
235  func_args.push_back(i64_type); // pos
236  func_args.push_back(pi64_type); // frag_row_off_ptr
237  func_args.push_back(pi64_type); // row_count_ptr
238  if (hoist_literals) {
239  func_args.push_back(PointerType::get(i8_type, 0)); // literals
240  }
241  FunctionType* func_type = FunctionType::get(
242  /*Result=*/i32_type,
243  /*Params=*/func_args,
244  /*isVarArg=*/false);
245 
246  std::string func_name{"row_process"};
247  auto func_ptr = mod->getFunction(func_name);
248 
249  if (!func_ptr) {
250  func_ptr = Function::Create(
251  /*Type=*/func_type,
252  /*Linkage=*/GlobalValue::ExternalLinkage,
253  /*Name=*/func_name,
254  mod); // (external, no body)
255  func_ptr->setCallingConv(CallingConv::C);
256  func_ptr->setAttributes(
257  make_attribute_list(mod, llvm::AttributeList::AttrIndex::FunctionIndex));
258  }
259 
260  return func_ptr;
261 }
llvm::AttributeList make_attribute_list(llvm::Module const *const mod, unsigned const index, ATTRS const ...attrs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: