Drop materializeAllPermanently.
[oota-llvm.git] / tools / lli / lli.cpp
index cc8117d6e7a8667bb5ad74c17a054d4725f4f28b..9f714060c17a5b36aec8fad810d04d789626d69a 100644 (file)
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/LLVMContext.h"
+#include "OrcLazyJIT.h"
 #include "RemoteMemoryManager.h"
 #include "RemoteTarget.h"
 #include "RemoteTargetExternal.h"
@@ -66,6 +67,9 @@ using namespace llvm;
 #define DEBUG_TYPE "lli"
 
 namespace {
+
+  enum class JITKind { MCJIT, OrcMCJITReplacement, OrcLazy };
+
   cl::opt<std::string>
   InputFile(cl::desc("<input bitcode>"), cl::Positional, cl::init("-"));
 
@@ -76,12 +80,19 @@ namespace {
                                  cl::desc("Force interpretation: disable JIT"),
                                  cl::init(false));
 
-  cl::opt<bool> UseOrcMCJITReplacement("use-orcmcjit",
-                                       cl::desc("Use the experimental "
-                                                "OrcMCJITReplacement as a "
-                                                "drop-in replacement for "
-                                                "MCJIT."),
-                                       cl::init(false));
+  cl::opt<JITKind> UseJITKind("jit-kind",
+                              cl::desc("Choose underlying JIT kind."),
+                              cl::init(JITKind::MCJIT),
+                              cl::values(
+                                clEnumValN(JITKind::MCJIT, "mcjit",
+                                           "MCJIT"),
+                                clEnumValN(JITKind::OrcMCJITReplacement,
+                                           "orc-mcjit",
+                                           "Orc-based MCJIT replacement"),
+                                clEnumValN(JITKind::OrcLazy,
+                                           "orc-lazy",
+                                           "Orc-based lazy JIT."),
+                                clEnumValEnd));
 
   // The MCJIT supports building for a target address space separate from
   // the JIT compilation process. Use a forked process and a copying
@@ -224,23 +235,6 @@ namespace {
                      clEnumValN(FloatABI::Hard, "hard",
                                 "Hard float ABI (uses FP registers)"),
                      clEnumValEnd));
-  cl::opt<bool>
-// In debug builds, make this default to true.
-#ifdef NDEBUG
-#define EMIT_DEBUG false
-#else
-#define EMIT_DEBUG true
-#endif
-  EmitJitDebugInfo("jit-emit-debug",
-    cl::desc("Emit debug information to debugger"),
-    cl::init(EMIT_DEBUG));
-#undef EMIT_DEBUG
-
-  static cl::opt<bool>
-  EmitJitDebugInfoToDisk("jit-emit-debug-to-disk",
-    cl::Hidden,
-    cl::desc("Emit debug info objfiles to disk"),
-    cl::init(false));
 }
 
 //===----------------------------------------------------------------------===//
@@ -260,7 +254,7 @@ public:
         this->CacheDir[this->CacheDir.size() - 1] != '/')
       this->CacheDir += '/';
   }
-  virtual ~LLIObjectCache() {}
+  ~LLIObjectCache() override {}
 
   void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) override {
     const std::string ModuleID = M->getModuleIdentifier();
@@ -268,8 +262,7 @@ public:
     if (!getCacheFilename(ModuleID, CacheName))
       return;
     if (!CacheDir.empty()) { // Create user-defined cache dir.
-      SmallString<128> dir(CacheName);
-      sys::path::remove_filename(dir);
+      SmallString<128> dir(sys::path::parent_path(CacheName));
       sys::fs::create_directories(Twine(dir));
     }
     std::error_code EC;
@@ -371,6 +364,19 @@ static void addCygMingExtraModule(ExecutionEngine *EE,
   EE->addModule(std::move(M));
 }
 
+CodeGenOpt::Level getOptLevel() {
+  switch (OptLevel) {
+  default:
+    errs() << "lli: Invalid optimization level.\n";
+    exit(1);
+  case '0': return CodeGenOpt::None;
+  case '1': return CodeGenOpt::Less;
+  case ' ':
+  case '2': return CodeGenOpt::Default;
+  case '3': return CodeGenOpt::Aggressive;
+  }
+  llvm_unreachable("Unrecognized opt level.");
+}
 
 //===----------------------------------------------------------------------===//
 // main Driver function
@@ -404,6 +410,9 @@ int main(int argc, char **argv, char * const *envp) {
     return 1;
   }
 
+  if (UseJITKind == JITKind::OrcLazy)
+    return runOrcLazyJIT(std::move(Owner), argc, argv);
+
   if (EnableCacheManager) {
     std::string CacheName("file:");
     CacheName.append(InputFile);
@@ -412,7 +421,7 @@ int main(int argc, char **argv, char * const *envp) {
 
   // If not jitting lazily, load the whole bitcode file eagerly too.
   if (NoLazyCompilation) {
-    if (std::error_code EC = Mod->materializeAllPermanently()) {
+    if (std::error_code EC = Mod->materializeAll()) {
       errs() << argv[0] << ": bitcode didn't read correctly.\n";
       errs() << "Reason: " << EC.message() << "\n";
       exit(1);
@@ -430,7 +439,7 @@ int main(int argc, char **argv, char * const *envp) {
   builder.setEngineKind(ForceInterpreter
                         ? EngineKind::Interpreter
                         : EngineKind::JIT);
-  builder.setUseOrcMCJITReplacement(UseOrcMCJITReplacement);
+  builder.setUseOrcMCJITReplacement(UseJITKind == JITKind::OrcMCJITReplacement);
 
   // If we are supposed to override the target triple, do so now.
   if (!TargetTriple.empty())
@@ -454,31 +463,11 @@ int main(int argc, char **argv, char * const *envp) {
     exit(1);
   }
 
-  CodeGenOpt::Level OLvl = CodeGenOpt::Default;
-  switch (OptLevel) {
-  default:
-    errs() << argv[0] << ": invalid optimization level.\n";
-    return 1;
-  case ' ': break;
-  case '0': OLvl = CodeGenOpt::None; break;
-  case '1': OLvl = CodeGenOpt::Less; break;
-  case '2': OLvl = CodeGenOpt::Default; break;
-  case '3': OLvl = CodeGenOpt::Aggressive; break;
-  }
-  builder.setOptLevel(OLvl);
+  builder.setOptLevel(getOptLevel());
 
   TargetOptions Options;
-  Options.UseSoftFloat = GenerateSoftFloatCalls;
   if (FloatABIForCalls != FloatABI::Default)
     Options.FloatABIType = FloatABIForCalls;
-  if (GenerateSoftFloatCalls)
-    FloatABIForCalls = FloatABI::Soft;
-
-  // Remote target execution doesn't handle EH or debug registration.
-  if (!RemoteMCJIT) {
-    Options.JITEmitDebugInfo = EmitJitDebugInfo;
-    Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk;
-  }
 
   builder.setTargetOptions(Options);