1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 13:11:39 +01:00
llvm-mirror/tools/lli/OrcLazyJIT.cpp
Lang Hames 66e55d58ea [Orc][lli] Add a very simple Orc-based lazy JIT to lli.
This ensures that we're building and testing the CompileOnDemand layer, at least
in a basic way.

Currently x86-64 only, and with limited to no library calls enabled (depending
on host platform). Patches welcome. ;)

To enable access to the lazy JIT, this patch replaces the '-use-orcmcjit' lli
option with a new option:
'-jit-kind={ mcjit | orc-mcjit | orc-lazy }'.

All regression tests are updated to use the new option, and one trivial test of
the new lazy JIT is added.

llvm-svn: 233182
2015-03-25 12:11:48 +00:00

54 lines
1.5 KiB
C++

//===------ OrcLazyJIT.cpp - Basic Orc-based JIT for lazy execution -------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "OrcLazyJIT.h"
#include "llvm/ExecutionEngine/Orc/OrcTargetSupport.h"
using namespace llvm;
std::unique_ptr<OrcLazyJIT::CompileCallbackMgr>
OrcLazyJIT::createCallbackMgr(Triple T, LLVMContext &Context) {
switch (T.getArch()) {
default:
// Flag error.
Error = true;
return nullptr;
case Triple::x86_64: {
typedef orc::JITCompileCallbackManager<CompileLayerT,
orc::OrcX86_64> CCMgrT;
return make_unique<CCMgrT>(CompileLayer, Context, 0, 64);
}
}
}
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
OrcLazyJIT J(std::unique_ptr<TargetMachine>(EngineBuilder().selectTarget()),
getGlobalContext());
if (!J.Ok()) {
errs() << "Could not construct JIT.\n";
return 1;
}
auto MainHandle = J.addModule(std::move(M));
auto MainSym = J.findSymbolIn(MainHandle, "main");
if (!MainSym) {
errs() << "Could not find main function.\n";
return 1;
}
typedef int (*MainFnPtr)(int, char*[]);
auto Main = reinterpret_cast<MainFnPtr>(
static_cast<uintptr_t>(MainSym.getAddress()));
return Main(ArgC, ArgV);
}