[llvm] r333128 - [LKH] Add ObjectTransformLayer2.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed May 23 14:27:06 PDT 2018
Author: lhames
Date: Wed May 23 14:27:06 2018
New Revision: 333128
URL: http://llvm.org/viewvc/llvm-project?rev=333128&view=rev
Log:
[LKH] Add ObjectTransformLayer2.
Added:
llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
Modified:
llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt
Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h?rev=333128&r1=333127&r2=333128&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h Wed May 23 14:27:06 2018
@@ -15,7 +15,7 @@
#define LLVM_EXECUTIONENGINE_ORC_OBJECTTRANSFORMLAYER_H
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/Orc/Core.h"
+#include "llvm/ExecutionEngine/Orc/Layer.h"
#include <algorithm>
#include <memory>
#include <string>
@@ -23,6 +23,23 @@
namespace llvm {
namespace orc {
+class ObjectTransformLayer2 : public ObjectLayer {
+public:
+ using TransformFunction =
+ std::function<Expected<std::unique_ptr<MemoryBuffer>>(
+ std::unique_ptr<MemoryBuffer>)>;
+
+ ObjectTransformLayer2(ExecutionSession &ES, ObjectLayer &BaseLayer,
+ TransformFunction Transform);
+
+ void emit(MaterializationResponsibility R, VModuleKey K,
+ std::unique_ptr<MemoryBuffer> O) override;
+
+private:
+ ObjectLayer &BaseLayer;
+ TransformFunction Transform;
+};
+
/// Object mutating layer.
///
/// This layer accepts sets of ObjectFiles (via addObject). It
Modified: llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt?rev=333128&r1=333127&r2=333128&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CMakeLists.txt Wed May 23 14:27:06 2018
@@ -6,6 +6,7 @@ add_llvm_library(LLVMOrcJIT
Legacy.cpp
Layer.cpp
NullResolver.cpp
+ ObjectTransformLayer.cpp
OrcABISupport.cpp
OrcCBindings.cpp
OrcError.cpp
Added: llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp?rev=333128&view=auto
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp (added)
+++ llvm/trunk/lib/ExecutionEngine/Orc/ObjectTransformLayer.cpp Wed May 23 14:27:06 2018
@@ -0,0 +1,34 @@
+//===---------- ObjectTransformLayer.cpp - Object Transform 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/ObjectTransformLayer.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+namespace llvm {
+namespace orc {
+
+ObjectTransformLayer2::ObjectTransformLayer2(ExecutionSession &ES,
+ ObjectLayer &BaseLayer,
+ TransformFunction Transform)
+ : ObjectLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
+
+void ObjectTransformLayer2::emit(MaterializationResponsibility R, VModuleKey K,
+ std::unique_ptr<MemoryBuffer> O) {
+ assert(O && "Module must not be null");
+
+ if (auto TransformedObj = Transform(std::move(O)))
+ BaseLayer.emit(std::move(R), std::move(K), std::move(*TransformedObj));
+ else {
+ R.failMaterialization();
+ getExecutionSession().reportError(TransformedObj.takeError());
+ }
+}
+
+} // End namespace orc.
+} // End namespace llvm.
More information about the llvm-commits
mailing list