1 //===-------------- IRTransformLayer.cpp - IR Transform Layer -------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
11 #include "llvm/Support/MemoryBuffer.h"
12
13 namespace llvm {
14 namespace orc {
15
IRTransformLayer2(ExecutionSession & ES,IRLayer & BaseLayer,TransformFunction Transform)16 IRTransformLayer2::IRTransformLayer2(ExecutionSession &ES,
17 IRLayer &BaseLayer,
18 TransformFunction Transform)
19 : IRLayer(ES), BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
20
emit(MaterializationResponsibility R,VModuleKey K,std::unique_ptr<Module> M)21 void IRTransformLayer2::emit(MaterializationResponsibility R, VModuleKey K,
22 std::unique_ptr<Module> M) {
23 assert(M && "Module must not be null");
24
25 if (auto TransformedMod = Transform(std::move(M)))
26 BaseLayer.emit(std::move(R), std::move(K), std::move(*TransformedMod));
27 else {
28 R.failMaterialization();
29 getExecutionSession().reportError(TransformedMod.takeError());
30 }
31 }
32
33 } // End namespace orc.
34 } // End namespace llvm.
35