Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [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 |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Contains the definition for a basic, eagerly compiling layer of the JIT. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H |
| 14 | #define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H |
| 15 | |
| 16 | #include "llvm/ADT/STLExtras.h" |
| 17 | #include "llvm/ExecutionEngine/JITSymbol.h" |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 18 | #include "llvm/ExecutionEngine/Orc/Layer.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 19 | #include "llvm/Support/Error.h" |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 20 | #include "llvm/Support/MemoryBuffer.h" |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 21 | #include <memory> |
| 22 | #include <string> |
| 23 | |
| 24 | namespace llvm { |
| 25 | |
| 26 | class Module; |
| 27 | |
| 28 | namespace orc { |
| 29 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 30 | class IRCompileLayer : public IRLayer { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 31 | public: |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 32 | class IRCompiler { |
| 33 | public: |
| 34 | IRCompiler(IRSymbolMapper::ManglingOptions MO) : MO(std::move(MO)) {} |
| 35 | virtual ~IRCompiler(); |
| 36 | const IRSymbolMapper::ManglingOptions &getManglingOptions() const { |
| 37 | return MO; |
| 38 | } |
| 39 | virtual Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) = 0; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 40 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 41 | protected: |
| 42 | IRSymbolMapper::ManglingOptions &manglingOptions() { return MO; } |
| 43 | |
| 44 | private: |
| 45 | IRSymbolMapper::ManglingOptions MO; |
| 46 | }; |
| 47 | |
| 48 | using NotifyCompiledFunction = std::function<void( |
| 49 | MaterializationResponsibility &R, ThreadSafeModule TSM)>; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 50 | |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 51 | IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 52 | std::unique_ptr<IRCompiler> Compile); |
| 53 | |
| 54 | IRCompiler &getCompiler() { return *Compile; } |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 55 | |
| 56 | void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled); |
| 57 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 58 | void emit(std::unique_ptr<MaterializationResponsibility> R, |
| 59 | ThreadSafeModule TSM) override; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 60 | |
| 61 | private: |
| 62 | mutable std::mutex IRLayerMutex; |
| 63 | ObjectLayer &BaseLayer; |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 64 | std::unique_ptr<IRCompiler> Compile; |
| 65 | const IRSymbolMapper::ManglingOptions *ManglingOpts; |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 66 | NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction(); |
| 67 | }; |
| 68 | |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 69 | } // end namespace orc |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 70 | } // end namespace llvm |
| 71 | |
| 72 | #endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H |