1//===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===//
2//
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
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"
18#include "llvm/ExecutionEngine/Orc/Layer.h"
19#include "llvm/Support/Error.h"
20#include "llvm/Support/MemoryBuffer.h"
21#include <memory>
22#include <string>
23
24namespace llvm {
25
26class Module;
27
28namespace orc {
29
30class IRCompileLayer : public IRLayer {
31public:
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;
40
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)>;
50
51 IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
52 std::unique_ptr<IRCompiler> Compile);
53
54 IRCompiler &getCompiler() { return *Compile; }
55
56 void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
57
58 void emit(std::unique_ptr<MaterializationResponsibility> R,
59 ThreadSafeModule TSM) override;
60
61private:
62 mutable std::mutex IRLayerMutex;
63 ObjectLayer &BaseLayer;
64 std::unique_ptr<IRCompiler> Compile;
65 const IRSymbolMapper::ManglingOptions *ManglingOpts;
66 NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
67};
68
69} // end namespace orc
70} // end namespace llvm
71
72#endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
73