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 <functional>
22#include <memory>
23#include <mutex>
24
25namespace llvm {
26
27class Module;
28
29namespace orc {
30
31class IRCompileLayer : public IRLayer {
32public:
33 class IRCompiler {
34 public:
35 IRCompiler(IRSymbolMapper::ManglingOptions MO) : MO(std::move(MO)) {}
36 virtual ~IRCompiler();
37 const IRSymbolMapper::ManglingOptions &getManglingOptions() const {
38 return MO;
39 }
40 virtual Expected<std::unique_ptr<MemoryBuffer>> operator()(Module &M) = 0;
41
42 protected:
43 IRSymbolMapper::ManglingOptions &manglingOptions() { return MO; }
44
45 private:
46 IRSymbolMapper::ManglingOptions MO;
47 };
48
49 using NotifyCompiledFunction = std::function<void(
50 MaterializationResponsibility &R, ThreadSafeModule TSM)>;
51
52 IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
53 std::unique_ptr<IRCompiler> Compile);
54
55 IRCompiler &getCompiler() { return *Compile; }
56
57 void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled);
58
59 void emit(std::unique_ptr<MaterializationResponsibility> R,
60 ThreadSafeModule TSM) override;
61
62private:
63 mutable std::mutex IRLayerMutex;
64 ObjectLayer &BaseLayer;
65 std::unique_ptr<IRCompiler> Compile;
66 const IRSymbolMapper::ManglingOptions *ManglingOpts;
67 NotifyCompiledFunction NotifyCompiled = NotifyCompiledFunction();
68};
69
70} // end namespace orc
71} // end namespace llvm
72
73#endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
74

source code of llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h