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