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 | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 14 | IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 15 | CompileFunction Compile) |
| 16 | : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {} |
| 17 | |
Lang Hames | 079df9a | 2018-10-15 22:56:10 +0000 | [diff] [blame] | 18 | void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) { |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 19 | std::lock_guard<std::mutex> Lock(IRLayerMutex); |
| 20 | this->NotifyCompiled = std::move(NotifyCompiled); |
| 21 | } |
| 22 | |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 23 | void IRCompileLayer::emit(MaterializationResponsibility R, |
| 24 | ThreadSafeModule TSM) { |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 25 | assert(TSM && "Module must not be null"); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 26 | |
Lang Hames | 809e9d1 | 2019-08-02 15:21:37 +0000 | [diff] [blame] | 27 | if (auto Obj = TSM.withModuleDo(Compile)) { |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 28 | { |
| 29 | std::lock_guard<std::mutex> Lock(IRLayerMutex); |
| 30 | if (NotifyCompiled) |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 31 | NotifyCompiled(R.getVModuleKey(), std::move(TSM)); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 32 | else |
Lang Hames | 8d76c71 | 2018-09-26 01:24:12 +0000 | [diff] [blame] | 33 | TSM = ThreadSafeModule(); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 34 | } |
Lang Hames | 8b94274 | 2018-10-16 20:13:06 +0000 | [diff] [blame] | 35 | BaseLayer.emit(std::move(R), std::move(*Obj)); |
Lang Hames | 4caa2f7 | 2018-05-23 21:27:01 +0000 | [diff] [blame] | 36 | } else { |
| 37 | R.failMaterialization(); |
| 38 | getExecutionSession().reportError(Obj.takeError()); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | } // End namespace orc. |
| 43 | } // End namespace llvm. |