blob: f8fdb171bbf9ff01a247572332017160444999d4 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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 Scull5e1ddfa2018-08-14 10:06:54 +01006//
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 Scullcdfcccc2018-10-05 20:58:37 +010018#include "llvm/ExecutionEngine/Orc/Layer.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010019#include "llvm/Support/Error.h"
Andrew Scullcdfcccc2018-10-05 20:58:37 +010020#include "llvm/Support/MemoryBuffer.h"
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010021#include <memory>
22#include <string>
23
24namespace llvm {
25
26class Module;
27
28namespace orc {
29
Andrew Walbran16937d02019-10-22 13:54:20 +010030class IRCompileLayer : public IRLayer {
Andrew Scullcdfcccc2018-10-05 20:58:37 +010031public:
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020032 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 Scullcdfcccc2018-10-05 20:58:37 +010040
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020041 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 Scullcdfcccc2018-10-05 20:58:37 +010050
Andrew Walbran16937d02019-10-22 13:54:20 +010051 IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020052 std::unique_ptr<IRCompiler> Compile);
53
54 IRCompiler &getCompiler() { return *Compile; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010055
56 void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
57
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020058 void emit(std::unique_ptr<MaterializationResponsibility> R,
59 ThreadSafeModule TSM) override;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010060
61private:
62 mutable std::mutex IRLayerMutex;
63 ObjectLayer &BaseLayer;
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020064 std::unique_ptr<IRCompiler> Compile;
65 const IRSymbolMapper::ManglingOptions *ManglingOpts;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010066 NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
67};
68
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010069} // end namespace orc
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010070} // end namespace llvm
71
72#endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H