1 | //===-------------- IRTransformLayer.cpp - IR Transform Layer -------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h" |
10 | #include "llvm/Support/MemoryBuffer.h" |
11 | |
12 | namespace llvm { |
13 | namespace orc { |
14 | |
15 | IRTransformLayer::IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer, |
16 | TransformFunction Transform) |
17 | : IRLayer(ES, BaseLayer.getManglingOptions()), BaseLayer(BaseLayer), |
18 | Transform(std::move(Transform)) {} |
19 | |
20 | void IRTransformLayer::emit(std::unique_ptr<MaterializationResponsibility> R, |
21 | ThreadSafeModule TSM) { |
22 | assert(TSM && "Module must not be null"); |
23 | |
24 | if (auto TransformedTSM = Transform(std::move(TSM), *R)) |
25 | BaseLayer.emit(R: std::move(R), TSM: std::move(*TransformedTSM)); |
26 | else { |
27 | R->failMaterialization(); |
28 | getExecutionSession().reportError(Err: TransformedTSM.takeError()); |
29 | } |
30 | } |
31 | |
32 | } // End namespace orc. |
33 | } // End namespace llvm. |
34 |