X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Flli%2FOrcLazyJIT.cpp;h=bda5d6dcd26c85b955b6bb75d26bd3ffe9533f8e;hb=b63d8107f0f58418387cbc5445ad3b9341d0e30b;hp=236de7c31d26d547239bb712d6fe7b64d9c65129;hpb=14ef491582a945b98f1c16648e008335fdf5952c;p=oota-llvm.git diff --git a/tools/lli/OrcLazyJIT.cpp b/tools/lli/OrcLazyJIT.cpp index 236de7c31d2..bda5d6dcd26 100644 --- a/tools/lli/OrcLazyJIT.cpp +++ b/tools/lli/OrcLazyJIT.cpp @@ -9,26 +9,105 @@ #include "OrcLazyJIT.h" #include "llvm/ExecutionEngine/Orc/OrcTargetSupport.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" +#include +#include using namespace llvm; +namespace { + + enum class DumpKind { NoDump, DumpFuncsToStdOut, 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::DumpFuncsToStdOut, + "funcs-to-stdout", + "Dump function names to stdout."), + 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 llvm::make_unique(IRDumpLayer, MemMgr, Context, 0, + 64); }; } } } +OrcLazyJIT::TransformFtor OrcLazyJIT::createDebugDumper() { + + switch (OrcDumpKind) { + case DumpKind::NoDump: + return [](std::unique_ptr M) { return M; }; + + case DumpKind::DumpFuncsToStdOut: + return [](std::unique_ptr M) { + printf("[ "); + + for (const auto &F : *M) { + if (F.isDeclaration()) + continue; + + if (F.hasName()) { + std::string Name(F.getName()); + printf("%s ", Name.c_str()); + } else + printf(" "); + } + + printf("]\n"); + return M; + }; + + case DumpKind::DumpModsToStdErr: + return [](std::unique_ptr M) { + dbgs() << "----- Module Start -----\n" << *M + << "----- Module End -----\n"; + + return 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 M; + }; + } + llvm_unreachable("Unknown DumpKind"); +} + 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)) {