OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{JoinLoopTest.cpp} Namespace Reference

Functions

void verify_function_ir (const llvm::Function *func)
 
llvm::Value * emit_external_call (const std::string &fname, llvm::Type *ret_type, const std::vector< llvm::Value * > args, llvm::Module *module, llvm::IRBuilder<> &builder)
 
llvm::Function * create_loop_test_function (llvm::LLVMContext &context, llvm::Module *module, const std::vector< JoinLoop > &join_loops)
 
std::unique_ptr< llvm::Module > create_loop_test_module ()
 
std::pair< void
*, std::unique_ptr
< llvm::ExecutionEngine > > 
native_codegen (std::unique_ptr< llvm::Module > &module, llvm::Function *func)
 
std::vector< JoinLoopgenerate_descriptors (const unsigned mask, const unsigned cond_mask, const std::vector< int64_t > &upper_bounds)
 

Variables

llvm::LLVMContext g_global_context
 

Function Documentation

llvm::Function* anonymous_namespace{JoinLoopTest.cpp}::create_loop_test_function ( llvm::LLVMContext &  context,
llvm::Module *  module,
const std::vector< JoinLoop > &  join_loops 
)

Definition at line 71 of file JoinLoopTest.cpp.

References run_benchmark_import::args, JoinLoop::codegen(), emit_external_call(), and verify_function_ir().

Referenced by main().

73  {
74  std::vector<llvm::Type*> argument_types;
75  const auto ft =
76  llvm::FunctionType::get(llvm::Type::getVoidTy(context), argument_types, false);
77  const auto func = llvm::Function::Create(
78  ft, llvm::Function::ExternalLinkage, "loop_test_func", module);
79  const auto entry_bb = llvm::BasicBlock::Create(context, "entry", func);
80  const auto exit_bb = llvm::BasicBlock::Create(context, "exit", func);
81  llvm::IRBuilder<> builder(context);
82  builder.SetInsertPoint(exit_bb);
83  builder.CreateRetVoid();
84  const auto loop_body_bb = JoinLoop::codegen(
85  join_loops,
86  [&builder, module](const std::vector<llvm::Value*>& iterators) {
87  const auto loop_body_bb = llvm::BasicBlock::Create(
88  builder.getContext(), "loop_body", builder.GetInsertBlock()->getParent());
89  builder.SetInsertPoint(loop_body_bb);
90  const std::vector<llvm::Value*> args(iterators.begin() + 1, iterators.end());
91  emit_external_call("print_iterators",
92  llvm::Type::getVoidTy(builder.getContext()),
93  args,
94  module,
95  builder);
96  return loop_body_bb;
97  },
98  nullptr,
99  exit_bb,
100  builder);
101  builder.SetInsertPoint(entry_bb);
102  builder.CreateBr(loop_body_bb);
103  verify_function_ir(func);
104  return func;
105 }
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
void verify_function_ir(const llvm::Function *func)
static llvm::BasicBlock * codegen(const std::vector< JoinLoop > &join_loops, const std::function< llvm::BasicBlock *(const std::vector< llvm::Value * > &)> &body_codegen, llvm::Value *outer_iter, llvm::BasicBlock *exit_bb, llvm::IRBuilder<> &builder)
Definition: JoinLoop.cpp:45
llvm::Value * emit_external_call(const std::string &fname, llvm::Type *ret_type, const std::vector< llvm::Value * > args, llvm::Module *module, llvm::IRBuilder<> &builder)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr<llvm::Module> anonymous_namespace{JoinLoopTest.cpp}::create_loop_test_module ( )

Definition at line 107 of file JoinLoopTest.cpp.

References g_global_context.

Referenced by main().

107  {
108  return llvm::make_unique<llvm::Module>("Nested loops JIT", g_global_context);
109 }

+ Here is the caller graph for this function:

llvm::Value* anonymous_namespace{JoinLoopTest.cpp}::emit_external_call ( const std::string &  fname,
llvm::Type ret_type,
const std::vector< llvm::Value * >  args,
llvm::Module *  module,
llvm::IRBuilder<> &  builder 
)

Definition at line 53 of file JoinLoopTest.cpp.

References CHECK(), CHECK_EQ, and run_benchmark_import::result.

Referenced by create_loop_test_function().

57  {
58  std::vector<llvm::Type*> arg_types;
59  for (const auto arg : args) {
60  arg_types.push_back(arg->getType());
61  }
62  auto func_ty = llvm::FunctionType::get(ret_type, arg_types, false);
63  auto func_p = module->getOrInsertFunction(fname, func_ty);
64  CHECK(func_p);
65  llvm::Value* result = builder.CreateCall(func_p, args);
66  // check the assumed type
67  CHECK_EQ(result->getType(), ret_type);
68  return result;
69 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<JoinLoop> anonymous_namespace{JoinLoopTest.cpp}::generate_descriptors ( const unsigned  mask,
const unsigned  cond_mask,
const std::vector< int64_t > &  upper_bounds 
)

Definition at line 140 of file JoinLoopTest.cpp.

References CHECK(), CHECK_EQ, g_global_context, INNER, ll_int(), Singleton, JoinLoopDomain::slot_lookup_result, to_string(), JoinLoopDomain::upper_bound, and UpperBound.

Referenced by main().

142  {
143  std::vector<JoinLoop> join_loops;
144  size_t cond_idx{0};
145  for (size_t i = 0; i < upper_bounds.size(); ++i) {
146  if (mask & (1 << i)) {
147  const bool cond_is_true = cond_mask & (1 << cond_idx);
148  join_loops.emplace_back(
151  [i, cond_is_true](const std::vector<llvm::Value*>& v) {
152  CHECK_EQ(i + 1, v.size());
153  CHECK(!v.front());
154  JoinLoopDomain domain{{0}};
155  domain.slot_lookup_result = cond_is_true
156  ? ll_int(int64_t(99), g_global_context)
157  : ll_int(int64_t(-1), g_global_context);
158  return domain;
159  },
160  nullptr,
161  nullptr,
162  nullptr,
163  "i" + std::to_string(i));
164  ++cond_idx;
165  } else {
166  const auto upper_bound = upper_bounds[i];
167  join_loops.emplace_back(
170  [i, upper_bound](const std::vector<llvm::Value*>& v) {
171  CHECK_EQ(i + 1, v.size());
172  CHECK(!v.front());
173  JoinLoopDomain domain{{0}};
174  domain.upper_bound = ll_int<int64_t>(upper_bound, g_global_context);
175  return domain;
176  },
177  nullptr,
178  nullptr,
179  nullptr,
180  "i" + std::to_string(i));
181  }
182  }
183  return join_loops;
184 }
#define CHECK_EQ(x, y)
Definition: Logger.h:198
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
CHECK(cgen_state)
llvm::Value * slot_lookup_result
Definition: JoinLoop.h:45
llvm::Value * upper_bound
Definition: JoinLoop.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::pair<void*, std::unique_ptr<llvm::ExecutionEngine> > anonymous_namespace{JoinLoopTest.cpp}::native_codegen ( std::unique_ptr< llvm::Module > &  module,
llvm::Function *  func 
)

Definition at line 111 of file JoinLoopTest.cpp.

References CHECK().

Referenced by main().

113  {
114  llvm::ExecutionEngine* execution_engine{nullptr};
115 
116  auto init_err = llvm::InitializeNativeTarget();
117  CHECK(!init_err);
118 
119  llvm::InitializeAllTargetMCs();
120  llvm::InitializeNativeTargetAsmPrinter();
121  llvm::InitializeNativeTargetAsmParser();
122 
123  std::string err_str;
124  llvm::EngineBuilder eb(std::move(module));
125  eb.setErrorStr(&err_str);
126  eb.setEngineKind(llvm::EngineKind::JIT);
127  llvm::TargetOptions to;
128  to.EnableFastISel = true;
129  eb.setTargetOptions(to);
130  execution_engine = eb.create();
131  CHECK(execution_engine);
132 
133  execution_engine->finalizeObject();
134  auto native_code = execution_engine->getPointerToFunction(func);
135 
136  CHECK(native_code);
137  return {native_code, std::unique_ptr<llvm::ExecutionEngine>(execution_engine)};
138 }
std::unique_ptr< llvm::Module > module(runtime_module_shallow_copy(cgen_state))
CHECK(cgen_state)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{JoinLoopTest.cpp}::verify_function_ir ( const llvm::Function *  func)

Definition at line 44 of file JoinLoopTest.cpp.

References logger::FATAL, and LOG.

44  {
45  std::stringstream err_ss;
46  llvm::raw_os_ostream err_os(err_ss);
47  if (llvm::verifyFunction(*func, &err_os)) {
48  func->print(llvm::outs());
49  LOG(FATAL) << err_ss.str();
50  }
51 }
#define LOG(tag)
Definition: Logger.h:185

Variable Documentation

llvm::LLVMContext anonymous_namespace{JoinLoopTest.cpp}::g_global_context

Definition at line 42 of file JoinLoopTest.cpp.

Referenced by create_loop_test_module(), and generate_descriptors().