OmniSciDB  fe05a0c208
 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 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", 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, 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  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)
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:48
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 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 *  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 = 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:211
#define CHECK(condition)
Definition: Logger.h:203

+ 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, i, 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  "i" + std::to_string(i));
166  ++cond_idx;
167  } else {
168  const auto upper_bound = upper_bounds[i];
169  join_loops.emplace_back(
172  [i, upper_bound](const std::vector<llvm::Value*>& v) {
173  CHECK_EQ(i + 1, v.size());
174  CHECK(!v.front());
175  JoinLoopDomain domain{{0}};
176  domain.upper_bound = ll_int<int64_t>(upper_bound, g_global_context);
177  return domain;
178  },
179  nullptr,
180  nullptr,
181  nullptr,
182  "i" + std::to_string(i));
183  }
184  }
185  return join_loops;
186 }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
#define CHECK_EQ(x, y)
Definition: Logger.h:211
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:46
llvm::ManagedStatic< llvm::LLVMContext > g_global_context
llvm::Value * upper_bound
Definition: JoinLoop.h:44
#define CHECK(condition)
Definition: Logger.h:203

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

References CHECK, and to.

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(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 }
char * to
#define CHECK(condition)
Definition: Logger.h:203

+ 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:194

Variable Documentation

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

Definition at line 44 of file JoinLoopTest.cpp.