Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 1 | //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" |
| 10 | |
| 11 | namespace llvm { |
| 12 | namespace orc { |
| 13 | |
Lang Hames | ce2207a | 2020-01-21 16:28:30 -0800 | [diff] [blame] | 14 | IRCompileLayer::IRCompiler::~IRCompiler() {} |
| 15 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 16 | IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, |
Lang Hames | ce2207a | 2020-01-21 16:28:30 -0800 | [diff] [blame] | 17 | std::unique_ptr<IRCompiler> Compile) |
| 18 | : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer), |
| 19 | Compile(std::move(Compile)) { |
| 20 | ManglingOpts = &this->Compile->getManglingOptions(); |
| 21 | } |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 22 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 23 | void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) { |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 24 | std::lock_guard<std::mutex> Lock(IRLayerMutex); |
| 25 | this->NotifyCompiled = std::move(NotifyCompiled); |
| 26 | } |
| 27 | |
Lang Hames | 7dcd004 | 2020-09-11 09:23:14 -0700 | [diff] [blame] | 28 | void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R, |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 29 | ThreadSafeModule TSM) { |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 30 | assert(TSM && "Module must not be null"); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 31 | |
Lang Hames | ce2207a | 2020-01-21 16:28:30 -0800 | [diff] [blame] | 32 | if (auto Obj = TSM.withModuleDo(*Compile)) { |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 33 | { |
| 34 | std::lock_guard<std::mutex> Lock(IRLayerMutex); |
| 35 | if (NotifyCompiled) |
Lang Hames | 0aec49c | 2020-09-11 09:50:41 -0700 | [diff] [blame^] | 36 | NotifyCompiled(*R, std::move(TSM)); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 37 | else |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 38 | TSM = ThreadSafeModule(); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 39 | } |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 40 | BaseLayer.emit(std::move(R), std::move(*Obj)); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 41 | } else { |
Lang Hames | 7dcd004 | 2020-09-11 09:23:14 -0700 | [diff] [blame] | 42 | R->failMaterialization(); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 43 | getExecutionSession().reportError(Obj.takeError()); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | } // End namespace orc. |
| 48 | } // End namespace llvm. |