[PATCH] D51126: [ORC] Lock mutex in IRCompileLayer2::emit() to avoid calling into PassManager::run() in parallel.

Stefan Gränitz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 23 10:21:05 PDT 2018


sgraenitz updated this revision to Diff 162220.
sgraenitz added a comment.

Add LLJIT::CreateMultiThreaded() instead.


Repository:
  rL LLVM

https://reviews.llvm.org/D51126

Files:
  include/llvm/ExecutionEngine/Orc/LLJIT.h
  lib/ExecutionEngine/Orc/LLJIT.cpp


Index: lib/ExecutionEngine/Orc/LLJIT.cpp
===================================================================
--- lib/ExecutionEngine/Orc/LLJIT.cpp
+++ lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -22,6 +22,18 @@
       new LLJIT(std::move(ES), std::move(TM), std::move(DL)));
 }
 
+Expected<std::unique_ptr<LLJIT>>
+LLJIT::CreateMultiThreaded(std::unique_ptr<ExecutionSession> ES,
+                           JITTargetMachineBuilder JTMB) {
+  if (auto TM = JTMB.createTargetMachine()) {
+    auto DL = (**TM).createDataLayout();
+    return std::unique_ptr<LLJIT>(new LLJIT(std::move(ES), std::move(*TM),
+                                            std::move(JTMB), std::move(DL)));
+  } else {
+    return TM.takeError();
+  }
+}
+
 Error LLJIT::defineAbsolute(StringRef Name, JITEvaluatedSymbol Sym) {
   auto InternedName = ES->getSymbolStringPool().intern(Name);
   SymbolMap Symbols({{InternedName, Sym}});
@@ -52,6 +64,17 @@
       CompileLayer(*this->ES, ObjLinkingLayer, SimpleCompiler(*this->TM)),
       CtorRunner(Main), DtorRunner(Main) {}
 
+LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES,
+             std::unique_ptr<TargetMachine> TM, JITTargetMachineBuilder JTMB,
+             DataLayout DL)
+    : ES(std::move(ES)), Main(this->ES->createJITDylib("main")),
+      TM(std::move(TM)), DL(std::move(DL)),
+      ObjLinkingLayer(*this->ES,
+                      [this](VModuleKey K) { return getMemoryManager(K); }),
+      CompileLayer(*this->ES, ObjLinkingLayer,
+                   MultiThreadedSimpleCompiler(std::move(JTMB))),
+      CtorRunner(Main), DtorRunner(Main) {}
+
 std::shared_ptr<RuntimeDyld::MemoryManager>
 LLJIT::getMemoryManager(VModuleKey K) {
   return llvm::make_unique<SectionMemoryManager>();
Index: include/llvm/ExecutionEngine/Orc/LLJIT.h
===================================================================
--- include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -34,6 +34,11 @@
   Create(std::unique_ptr<ExecutionSession> ES,
          std::unique_ptr<TargetMachine> TM, DataLayout DL);
 
+  /// Create an LLJIT instance suitable for multithreaded compilation.
+  static Expected<std::unique_ptr<LLJIT>>
+  CreateMultiThreaded(std::unique_ptr<ExecutionSession> ES,
+                      JITTargetMachineBuilder JTMB);
+
   /// Returns a reference to the ExecutionSession for this JIT instance.
   ExecutionSession &getExecutionSession() { return *ES; }
 
@@ -83,6 +88,9 @@
   LLJIT(std::unique_ptr<ExecutionSession> ES, std::unique_ptr<TargetMachine> TM,
         DataLayout DL);
 
+  LLJIT(std::unique_ptr<ExecutionSession> ES, std::unique_ptr<TargetMachine> TM,
+        JITTargetMachineBuilder JTMB, DataLayout DL);
+
   std::shared_ptr<RuntimeDyld::MemoryManager> getMemoryManager(VModuleKey K);
 
   std::string mangle(StringRef UnmangledName);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51126.162220.patch
Type: text/x-patch
Size: 2830 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180823/7d529948/attachment.bin>


More information about the llvm-commits mailing list