<div dir="ltr">Oops. Workflow fail: I was planning to tidy this up and add some comments before committing. I'll flesh this out with comments soon, but for the curious: I'll be adding new thread-safe versions of the existing layers (building on the work in Orc/Core.h and Orc/Layer.h). The aim is to replace the existing, non-thread-safe layers with the new ones over the next few weeks. This will involve some API breaking changes, but they should be reasonably easy to adapt to. The pay-off will be support for multi-threaded code and multi-core JITing.<div><br></div><div>-- Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 23, 2018 at 2:27 PM, Lang Hames via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: lhames<br>
Date: Wed May 23 14:27:01 2018<br>
New Revision: 333127<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=333127&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=333127&view=rev</a><br>
Log:<br>
[LKH] Add a new IRCompileLayer.<br>
<br>
Added:<br>
    llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.cpp<br>
Modified:<br>
    llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.h<br>
    llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>CMakeLists.txt<br>
    llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>RTDyldObjectLinkingLayer.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=333127&r1=333126&r2=333127&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/include/<wbr>llvm/ExecutionEngine/Orc/<wbr>IRCompileLayer.h?rev=333127&<wbr>r1=333126&r2=333127&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.h (original)<br>
+++ llvm/trunk/include/llvm/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.h Wed May 23 14:27:01 2018<br>
@@ -16,8 +16,9 @@<br>
<br>
 #include "llvm/ADT/STLExtras.h"<br>
 #include "llvm/ExecutionEngine/<wbr>JITSymbol.h"<br>
-#include "llvm/ExecutionEngine/Orc/<wbr>Core.h"<br>
+#include "llvm/ExecutionEngine/Orc/<wbr>Layer.h"<br>
 #include "llvm/Support/Error.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
 #include <memory><br>
 #include <string><br>
<br>
@@ -27,6 +28,29 @@ class Module;<br>
<br>
 namespace orc {<br>
<br>
+class IRCompileLayer2 : public IRLayer {<br>
+public:<br>
+  using CompileFunction =<br>
+      std::function<Expected<std::<wbr>unique_ptr<MemoryBuffer>>(<wbr>Module &)>;<br>
+<br>
+  using NotifyCompiledFunction =<br>
+      std::function<void(VModuleKey K, std::unique_ptr<Module>)>;<br>
+<br>
+  IRCompileLayer2(<wbr>ExecutionSession &ES, ObjectLayer &BaseLayer,<br>
+                  CompileFunction Compile);<br>
+<br>
+  void setNotifyCompiled(<wbr>NotifyCompiledFunction NotifyCompiled);<br>
+<br>
+  void emit(<wbr>MaterializationResponsibility R, VModuleKey K,<br>
+            std::unique_ptr<Module> M) override;<br>
+<br>
+private:<br>
+  mutable std::mutex IRLayerMutex;<br>
+  ObjectLayer &BaseLayer;<br>
+  CompileFunction Compile;<br>
+  NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();<br>
+};<br>
+<br>
 /// Eager IR compiling layer.<br>
 ///<br>
 ///   This layer immediately compiles each IR module added via addModule to an<br>
<br>
Modified: llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt?rev=333127&r1=333126&r2=333127&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>CMakeLists.txt?rev=333127&r1=<wbr>333126&r2=333127&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>CMakeLists.txt Wed May 23 14:27:01 2018<br>
@@ -2,6 +2,7 @@ add_llvm_library(LLVMOrcJIT<br>
   Core.cpp<br>
   ExecutionUtils.cpp<br>
   IndirectionUtils.cpp<br>
+  IRCompileLayer.cpp<br>
   Legacy.cpp<br>
   Layer.cpp<br>
   NullResolver.cpp<br>
<br>
Added: llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp?rev=333127&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.cpp?rev=333127&<wbr>view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.cpp (added)<br>
+++ llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>IRCompileLayer.cpp Wed May 23 14:27:01 2018<br>
@@ -0,0 +1,44 @@<br>
+//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "llvm/ExecutionEngine/Orc/<wbr>IRCompileLayer.h"<br>
+<br>
+namespace llvm {<br>
+namespace orc {<br>
+<br>
+IRCompileLayer2::<wbr>IRCompileLayer2(<wbr>ExecutionSession &ES, ObjectLayer &BaseLayer,<br>
+                                 CompileFunction Compile)<br>
+    : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}<br>
+<br>
+void IRCompileLayer2::<wbr>setNotifyCompiled(<wbr>NotifyCompiledFunction NotifyCompiled) {<br>
+  std::lock_guard<std::mutex> Lock(IRLayerMutex);<br>
+  this->NotifyCompiled = std::move(NotifyCompiled);<br>
+}<br>
+<br>
+void IRCompileLayer2::emit(<wbr>MaterializationResponsibility R, VModuleKey K,<br>
+                           std::unique_ptr<Module> M) {<br>
+  assert(M && "Module must not be null");<br>
+<br>
+  if (auto Obj = Compile(*M)) {<br>
+    {<br>
+      std::lock_guard<std::mutex> Lock(IRLayerMutex);<br>
+      if (NotifyCompiled)<br>
+        NotifyCompiled(K, std::move(M));<br>
+      else<br>
+        M = nullptr;<br>
+    }<br>
+    BaseLayer.emit(std::move(R), std::move(K), std::move(*Obj));<br>
+  } else {<br>
+    R.failMaterialization();<br>
+    getExecutionSession().<wbr>reportError(Obj.takeError());<br>
+  }<br>
+}<br>
+<br>
+} // End namespace orc.<br>
+} // End namespace llvm.<br>
<br>
Modified: llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>RTDyldObjectLinkingLayer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp?rev=333127&r1=333126&r2=333127&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>RTDyldObjectLinkingLayer.cpp?<wbr>rev=333127&r1=333126&r2=<wbr>333127&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>RTDyldObjectLinkingLayer.cpp (original)<br>
+++ llvm/trunk/lib/<wbr>ExecutionEngine/Orc/<wbr>RTDyldObjectLinkingLayer.cpp Wed May 23 14:27:01 2018<br>
@@ -22,7 +22,7 @@ RTDyldObjectLinkingLayer2::<wbr>RTDyldObjectL<br>
 void RTDyldObjectLinkingLayer2::<wbr>emit(<wbr>MaterializationResponsibility R,<br>
                                      VModuleKey K,<br>
                                      std::unique_ptr<MemoryBuffer> O) {<br>
-  assert(O && "Object has already been materialized");<br>
+  assert(O && "Object must not be null");<br>
<br>
   auto &ES = getExecutionSession();<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>