[llvm] r333127 - [LKH] Add a new IRCompileLayer.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 14:27:02 PDT 2018
Author: lhames
Date: Wed May 23 14:27:01 2018
New Revision: 333127
URL: http://llvm.org/viewvc/llvm-project?rev=333127&view=rev
Log:
[LKH] Add a new IRCompileLayer.
Added:
llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt
llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h?rev=333127&r1=333126&r2=333127&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h Wed May 23 14:27:01 2018
@@ -16,8 +16,9 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
#include <memory>
#include <string>
@@ -27,6 +28,29 @@ class Module;
namespace orc {
+class IRCompileLayer2 : public IRLayer {
+public:
+ using CompileFunction =
+ std::function<Expected<std::unique_ptr<MemoryBuffer>>(Module &)>;
+
+ using NotifyCompiledFunction =
+ std::function<void(VModuleKey K, std::unique_ptr<Module>)>;
+
+ IRCompileLayer2(ExecutionSession &ES, ObjectLayer &BaseLayer,
+ CompileFunction Compile);
+
+ void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
+
+ void emit(MaterializationResponsibility R, VModuleKey K,
+ std::unique_ptr<Module> M) override;
+
+private:
+ mutable std::mutex IRLayerMutex;
+ ObjectLayer &BaseLayer;
+ CompileFunction Compile;
+ NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
+};
+
/// Eager IR compiling layer.
///
/// This layer immediately compiles each IR module added via addModule to an
Modified: llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt?rev=333127&r1=333126&r2=333127&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt Wed May 23 14:27:01 2018
@@ -2,6 +2,7 @@ add_llvm_library(LLVMOrcJIT
Core.cpp
ExecutionUtils.cpp
IndirectionUtils.cpp
+ IRCompileLayer.cpp
Legacy.cpp
Layer.cpp
NullResolver.cpp
Added: llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp?rev=333127&view=auto
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp (added)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IRCompileLayer.cpp Wed May 23 14:27:01 2018
@@ -0,0 +1,44 @@
+//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
+
+namespace llvm {
+namespace orc {
+
+IRCompileLayer2::IRCompileLayer2(ExecutionSession &ES, ObjectLayer &BaseLayer,
+ CompileFunction Compile)
+ : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
+
+void IRCompileLayer2::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
+ std::lock_guard<std::mutex> Lock(IRLayerMutex);
+ this->NotifyCompiled = std::move(NotifyCompiled);
+}
+
+void IRCompileLayer2::emit(MaterializationResponsibility R, VModuleKey K,
+ std::unique_ptr<Module> M) {
+ assert(M && "Module must not be null");
+
+ if (auto Obj = Compile(*M)) {
+ {
+ std::lock_guard<std::mutex> Lock(IRLayerMutex);
+ if (NotifyCompiled)
+ NotifyCompiled(K, std::move(M));
+ else
+ M = nullptr;
+ }
+ BaseLayer.emit(std::move(R), std::move(K), std::move(*Obj));
+ } else {
+ R.failMaterialization();
+ getExecutionSession().reportError(Obj.takeError());
+ }
+}
+
+} // End namespace orc.
+} // End namespace llvm.
Modified: llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp?rev=333127&r1=333126&r2=333127&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp Wed May 23 14:27:01 2018
@@ -22,7 +22,7 @@ RTDyldObjectLinkingLayer2::RTDyldObjectL
void RTDyldObjectLinkingLayer2::emit(MaterializationResponsibility R,
VModuleKey K,
std::unique_ptr<MemoryBuffer> O) {
- assert(O && "Object has already been materialized");
+ assert(O && "Object must not be null");
auto &ES = getExecutionSession();
More information about the llvm-commits
mailing list