OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 *llvm_module, llvm::IRBuilder<> &builder)
 
llvm::Function * create_loop_test_function (llvm::LLVMContext &context, llvm::Module *llvm_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 > &llvm_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 *  llvm_module,
const std::vector< JoinLoop > &  join_loops 
)

Definition at line 73 of file JoinLoopTest.cpp.

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

Referenced by main().

75  {
76  std::vector<llvm::Type*> argument_types;
77  const auto ft =
78  llvm::FunctionType::get(llvm::Type::getVoidTy(context), argument_types, false);
79  const auto func = llvm::Function::Create(
80  ft, llvm::Function::ExternalLinkage, "loop_test_func", llvm_module);
81  const auto entry_bb = llvm::BasicBlock::Create(context, "entry", func);
82  const auto exit_bb = llvm::BasicBlock::Create(context, "exit", func);
83  llvm::IRBuilder<> builder(context);
84  builder.SetInsertPoint(exit_bb);
85  builder.CreateRetVoid();
86  const auto loop_body_bb = JoinLoop::codegen(
87  join_loops,
88  [&builder, llvm_module](const std::vector<llvm::Value*>& iterators) {
89  const auto loop_body_bb = llvm::BasicBlock::Create(
90  builder.getContext(), "loop_body", builder.GetInsertBlock()->getParent());
91  builder.SetInsertPoint(loop_body_bb);
92  const std::vector<llvm::Value*> args(iterators.begin() + 1, iterators.end());
93  emit_external_call("print_iterators",
94  llvm::Type::getVoidTy(builder.getContext()),
95  args,
96  llvm_module,
97  builder);
98  return loop_body_bb;
99  },
100  nullptr,
101  exit_bb,
102  builder);
103  builder.SetInsertPoint(entry_bb);
104  builder.CreateBr(loop_body_bb);
105  verify_function_ir(func);
106  return func;
107 }
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 *llvm_module, llvm::IRBuilder<> &builder)
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, CgenState *cgen_state)
Definition: JoinLoop.cpp:50

+ 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 109 of file JoinLoopTest.cpp.

References anonymous_namespace{LLVMGlobalContext.cpp}::g_global_context.

Referenced by main().

109  {
110  return std::make_unique<llvm::Module>("Nested loops JIT", g_global_context);
111 }
llvm::ManagedStatic< llvm::LLVMContext > g_global_context

+ 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 *  llvm_module,
llvm::IRBuilder<> &  builder 
)

Definition at line 55 of file JoinLoopTest.cpp.

References CHECK, CHECK_EQ, and run_benchmark_import::result.

Referenced by create_loop_test_function().

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

+ 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 142 of file JoinLoopTest.cpp.

References CHECK, CHECK_EQ, anonymous_namespace{LLVMGlobalContext.cpp}::g_global_context, INNER, ll_int(), Singleton, JoinLoopDomain::slot_lookup_result, to_string(), JoinLoopDomain::upper_bound, gpu_enabled::upper_bound(), and UpperBound.

Referenced by main().

144  {
145  std::vector<JoinLoop> join_loops;
146  size_t cond_idx{0};
147  for (size_t i = 0; i < upper_bounds.size(); ++i) {
148  if (mask & (1 << i)) {
149  const bool cond_is_true = cond_mask & (1 << cond_idx);
150  join_loops.emplace_back(
153  [i, cond_is_true](const std::vector<llvm::Value*>& v) {
154  CHECK_EQ(i + 1, v.size());
155  CHECK(!v.front());
156  JoinLoopDomain domain{{0}};
157  domain.slot_lookup_result = cond_is_true
158  ? ll_int(int64_t(99), g_global_context)
159  : ll_int(int64_t(-1), g_global_context);
160  return domain;
161  },
162  nullptr,
163  nullptr,
164  nullptr,
165  false,
166  "i" + std::to_string(i));
167  ++cond_idx;
168  } else {
169  const auto upper_bound = upper_bounds[i];
170  join_loops.emplace_back(
173  [i, upper_bound](const std::vector<llvm::Value*>& v) {
174  CHECK_EQ(i + 1, v.size());
175  CHECK(!v.front());
176  JoinLoopDomain domain{{0}};
177  domain.upper_bound = ll_int<int64_t>(upper_bound, g_global_context);
178  return domain;
179  },
180  nullptr,
181  nullptr,
182  nullptr,
183  false,
184  "i" + std::to_string(i));
185  }
186  }
187  return join_loops;
188 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::ConstantInt * ll_int(const T v, llvm::LLVMContext &context)
std::string to_string(char const *&&v)
llvm::Value * slot_lookup_result
Definition: JoinLoop.h:47
llvm::ManagedStatic< llvm::LLVMContext > g_global_context
llvm::Value * upper_bound
Definition: JoinLoop.h:45
#define CHECK(condition)
Definition: Logger.h:291

+ 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 > &  llvm_module,
llvm::Function *  func 
)

Definition at line 113 of file JoinLoopTest.cpp.

References CHECK.

Referenced by main().

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

+ Here is the caller graph for this function:

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

Definition at line 46 of file JoinLoopTest.cpp.

References logger::FATAL, and LOG.

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

Variable Documentation

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

Definition at line 44 of file JoinLoopTest.cpp.