15216ac96SLang Hames //===-------------- IRTransformLayer.cpp - IR Transform Layer -------------===//
25216ac96SLang Hames //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65216ac96SLang Hames //
75216ac96SLang Hames //===----------------------------------------------------------------------===//
85216ac96SLang Hames 
95216ac96SLang Hames #include "llvm/ExecutionEngine/Orc/IRTransformLayer.h"
105216ac96SLang Hames #include "llvm/Support/MemoryBuffer.h"
115216ac96SLang Hames 
125216ac96SLang Hames namespace llvm {
135216ac96SLang Hames namespace orc {
145216ac96SLang Hames 
IRTransformLayer(ExecutionSession & ES,IRLayer & BaseLayer,TransformFunction Transform)15ce2207abSLang Hames IRTransformLayer::IRTransformLayer(ExecutionSession &ES, IRLayer &BaseLayer,
165216ac96SLang Hames                                    TransformFunction Transform)
17ce2207abSLang Hames     : IRLayer(ES, BaseLayer.getManglingOptions()), BaseLayer(BaseLayer),
18ce2207abSLang Hames       Transform(std::move(Transform)) {}
195216ac96SLang Hames 
emit(std::unique_ptr<MaterializationResponsibility> R,ThreadSafeModule TSM)20*7dcd0042SLang Hames void IRTransformLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
218d76c711SLang Hames                             ThreadSafeModule TSM) {
22809e9d1eSLang Hames   assert(TSM && "Module must not be null");
235216ac96SLang Hames 
24*7dcd0042SLang Hames   if (auto TransformedTSM = Transform(std::move(TSM), *R))
258b94274fSLang Hames     BaseLayer.emit(std::move(R), std::move(*TransformedTSM));
265216ac96SLang Hames   else {
27*7dcd0042SLang Hames     R->failMaterialization();
288d76c711SLang Hames     getExecutionSession().reportError(TransformedTSM.takeError());
295216ac96SLang Hames   }
305216ac96SLang Hames }
315216ac96SLang Hames 
325216ac96SLang Hames } // End namespace orc.
335216ac96SLang Hames } // End namespace llvm.
34