summaryrefslogtreecommitdiffstats
path: root/llvm/tools/lli/OrcLazyJIT.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-04-13 22:12:54 +0000
committerLang Hames <lhames@gmail.com>2015-04-13 22:12:54 +0000
commitcd3fd83c3a84dec41b352e526407d8bc8b7a21f3 (patch)
treeaff28ac22c6c42736ae166f0bc03f76f6bd3054a /llvm/tools/lli/OrcLazyJIT.cpp
parent3e1d483e0efb64e2e6af5407bd3d1c8db2150b35 (diff)
downloadbcm5719-llvm-cd3fd83c3a84dec41b352e526407d8bc8b7a21f3.tar.gz
bcm5719-llvm-cd3fd83c3a84dec41b352e526407d8bc8b7a21f3.zip
[Orc] Add an Orc layer for applying arbitrary transforms to IR, use it to add
debugging output to the LLI orc-lazy JIT, and update the orc-lazy "hello.ll" test to actually test for lazy compilation. llvm-svn: 234805
Diffstat (limited to 'llvm/tools/lli/OrcLazyJIT.cpp')
-rw-r--r--llvm/tools/lli/OrcLazyJIT.cpp81
1 files changed, 78 insertions, 3 deletions
diff --git a/llvm/tools/lli/OrcLazyJIT.cpp b/llvm/tools/lli/OrcLazyJIT.cpp
index 236de7c31d2..519bd72ccd4 100644
--- a/llvm/tools/lli/OrcLazyJIT.cpp
+++ b/llvm/tools/lli/OrcLazyJIT.cpp
@@ -9,26 +9,101 @@
#include "OrcLazyJIT.h"
#include "llvm/ExecutionEngine/Orc/OrcTargetSupport.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/DynamicLibrary.h"
+#include <system_error>
using namespace llvm;
+namespace {
+
+ enum class DumpKind { NoDump, DumpFuncsToStdErr, DumpModsToStdErr,
+ DumpModsToDisk };
+
+ cl::opt<DumpKind> OrcDumpKind("orc-lazy-debug",
+ cl::desc("Debug dumping for the orc-lazy JIT."),
+ cl::init(DumpKind::NoDump),
+ cl::values(
+ clEnumValN(DumpKind::NoDump, "no-dump",
+ "Don't dump anything."),
+ clEnumValN(DumpKind::DumpFuncsToStdErr,
+ "funcs-to-stderr",
+ "Dump function names to stderr."),
+ clEnumValN(DumpKind::DumpModsToStdErr,
+ "mods-to-stderr",
+ "Dump modules to stderr."),
+ clEnumValN(DumpKind::DumpModsToDisk,
+ "mods-to-disk",
+ "Dump modules to the current "
+ "working directory. (WARNING: "
+ "will overwrite existing files)."),
+ clEnumValEnd));
+}
+
OrcLazyJIT::CallbackManagerBuilder
OrcLazyJIT::createCallbackManagerBuilder(Triple T) {
switch (T.getArch()) {
default: return nullptr;
case Triple::x86_64: {
- typedef orc::JITCompileCallbackManager<CompileLayerT,
+ typedef orc::JITCompileCallbackManager<IRDumpLayerT,
orc::OrcX86_64> CCMgrT;
- return [](CompileLayerT &CompileLayer, RuntimeDyld::MemoryManager &MemMgr,
+ return [](IRDumpLayerT &IRDumpLayer, RuntimeDyld::MemoryManager &MemMgr,
LLVMContext &Context) {
- return make_unique<CCMgrT>(CompileLayer, MemMgr, Context, 0, 64);
+ return make_unique<CCMgrT>(IRDumpLayer, MemMgr, Context, 0, 64);
};
}
}
}
+OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() {
+
+ switch (OrcDumpKind) {
+ case DumpKind::NoDump:
+ return [](std::unique_ptr<Module> M) { return std::move(M); };
+
+ case DumpKind::DumpFuncsToStdErr:
+ return [](std::unique_ptr<Module> M) {
+ dbgs() << "[ ";
+
+ for (const auto &F : *M) {
+ if (F.isDeclaration())
+ continue;
+
+ if (F.hasName())
+ dbgs() << F.getName() << " ";
+ else
+ dbgs() << "<anon> ";
+ }
+
+ dbgs() << "]\n";
+ return std::move(M);
+ };
+
+ case DumpKind::DumpModsToStdErr:
+ return [](std::unique_ptr<Module> M) {
+ dbgs() << "----- Module Start -----\n" << *M
+ << "----- Module End -----\n";
+
+ return std::move(M);
+ };
+
+ case DumpKind::DumpModsToDisk:
+ return [](std::unique_ptr<Module> M) {
+ std::error_code EC;
+ raw_fd_ostream Out(M->getModuleIdentifier() + ".ll", EC,
+ sys::fs::F_Text);
+ if (EC) {
+ errs() << "Couldn't open " << M->getModuleIdentifier()
+ << " for dumping.\nError:" << EC.message() << "\n";
+ exit(1);
+ }
+ Out << *M;
+ return std::move(M);
+ };
+ }
+}
+
int llvm::runOrcLazyJIT(std::unique_ptr<Module> M, int ArgC, char* ArgV[]) {
// Add the program's symbols into the JIT's search space.
if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) {
OpenPOWER on IntegriCloud