195 const auto stub_name =
name +
"_stub";
200 const auto compilation_context =
202 if (compilation_context) {
208 auto cgen_state = executor->getCgenStatePtr();
209 cgen_state->set_module_shallow_copy(executor->get_rt_module());
212 auto& ctx = cgen_state->context_;
213 std::vector<llvm::Value*> callee_args;
214 auto inputs_it =
function->arg_begin() + 1;
215 for (
size_t i = 0; i < arg_types.size(); ++i) {
216 const auto arg_type = arg_types[i];
218 const auto llvm_arg_type =
llvm_type(arg_type, ctx);
219 auto callee_arg = cgen_state->emitExternalCall(
220 read_arg_name, llvm_arg_type, {&*inputs_it, cgen_state->llInt<int32_t>(i)});
222 CHECK(llvm_arg_type->isIntegerTy());
223 callee_arg = cgen_state->ir_builder_.CreateTrunc(callee_arg, llvm_arg_type);
225 CHECK(llvm_arg_type->isPointerTy());
226 callee_arg = cgen_state->ir_builder_.CreateBitCast(callee_arg, llvm_arg_type);
228 callee_args.push_back(callee_arg);
230 const auto llvm_ret_type =
llvm_type(ret_type, ctx);
231 auto value = is_external
232 ? cgen_state->emitExternalCall(
name, llvm_ret_type, callee_args)
233 : cgen_state->emitCall(
name, callee_args);
234 auto output = &*(
function->arg_begin());
235 auto void_type = llvm::Type::getVoidTy(ctx);
236 std::string write_arg_name{
"write_stub_result_"};
239 write_arg_name +=
"int";
240 const auto i64_type =
get_int_type(64, cgen_state->context_);
241 value = cgen_state->ir_builder_.CreateSExt(value, i64_type);
245 write_arg_name +=
"int";
246 const auto i64_type =
get_int_type(64, cgen_state->context_);
247 value = cgen_state->ir_builder_.CreateSExt(value, i64_type);
255 LOG(
FATAL) <<
"Invalid type: " <<
static_cast<int>(ret_type);
259 cgen_state->emitExternalCall(write_arg_name, void_type, {output, value});
261 cgen_state->ir_builder_.CreateRetVoid();
266 auto cpu_compilation_context = std::make_shared<CpuCompilationContext>(std::move(ee));
267 cpu_compilation_context->setFunctionPointer(
function);
270 std::move(cpu_compilation_context));
std::vector< std::string > CodeCacheKey
static ExecutionEngineWrapper generateNativeCPUCode(llvm::Function *func, const std::unordered_set< llvm::Function * > &live_funcs, const CompilationOptions &co)
llvm::Type * get_int_type(const int width, llvm::LLVMContext &context)
static std::shared_ptr< Executor > getExecutor(const ExecutorId id, const std::string &debug_dir="", const std::string &debug_file="", const SystemParameters &system_parameters=SystemParameters())
void verify_function_ir(const llvm::Function *func)
llvm::Type * llvm_type(const Type type, llvm::LLVMContext &ctx)
std::string get_stub_read_argument_name(const Type arg_type)
ReductionInterpreter::EvalValue(*)(void *output_handle, const void *inputs_handle) Stub
static std::shared_ptr< QueryEngine > getInstance()
bool is_pointer_type(const Type type)
bool is_integer_type(const Type type)
llvm::Function * create_stub_function(const std::string &name, CgenState *cgen_state)