From cd3fd83c3a84dec41b352e526407d8bc8b7a21f3 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 13 Apr 2015 22:12:54 +0000 Subject: [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 --- llvm/tools/lli/OrcLazyJIT.cpp | 81 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) (limited to 'llvm/tools/lli/OrcLazyJIT.cpp') 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 using namespace llvm; +namespace { + + enum class DumpKind { NoDump, DumpFuncsToStdErr, DumpModsToStdErr, + DumpModsToDisk }; + + cl::opt 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 CCMgrT; - return [](CompileLayerT &CompileLayer, RuntimeDyld::MemoryManager &MemMgr, + return [](IRDumpLayerT &IRDumpLayer, RuntimeDyld::MemoryManager &MemMgr, LLVMContext &Context) { - return make_unique(CompileLayer, MemMgr, Context, 0, 64); + return make_unique(IRDumpLayer, MemMgr, Context, 0, 64); }; } } } +OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { + + switch (OrcDumpKind) { + case DumpKind::NoDump: + return [](std::unique_ptr M) { return std::move(M); }; + + case DumpKind::DumpFuncsToStdErr: + return [](std::unique_ptr M) { + dbgs() << "[ "; + + for (const auto &F : *M) { + if (F.isDeclaration()) + continue; + + if (F.hasName()) + dbgs() << F.getName() << " "; + else + dbgs() << " "; + } + + dbgs() << "]\n"; + return std::move(M); + }; + + case DumpKind::DumpModsToStdErr: + return [](std::unique_ptr M) { + dbgs() << "----- Module Start -----\n" << *M + << "----- Module End -----\n"; + + return std::move(M); + }; + + case DumpKind::DumpModsToDisk: + return [](std::unique_ptr 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 M, int ArgC, char* ArgV[]) { // Add the program's symbols into the JIT's search space. if (sys::DynamicLibrary::LoadLibraryPermanently(nullptr)) { -- cgit v1.2.3