LLVM 22.0.0git
CompileOnDemandLayer.h
Go to the documentation of this file.
1//===- CompileOnDemandLayer.h - Compile each function on demand -*- 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// JIT layer for breaking up modules and inserting callbacks to allow
10// individual functions to be compiled on demand.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H
15#define LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H
16
17#include "llvm/ADT/APInt.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/StringRef.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/Constant.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/DataLayout.h"
31#include "llvm/IR/Function.h"
32#include "llvm/IR/GlobalAlias.h"
33#include "llvm/IR/GlobalValue.h"
35#include "llvm/IR/Instruction.h"
36#include "llvm/IR/Mangler.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/Type.h"
43#include <algorithm>
44#include <cassert>
45#include <functional>
46#include <iterator>
47#include <list>
48#include <memory>
49#include <optional>
50#include <set>
51#include <utility>
52
53namespace llvm {
54namespace orc {
55
57public:
58 /// Builder for IndirectStubsManagers.
60 std::function<std::unique_ptr<IndirectStubsManager>()>;
61
62 /// Construct a CompileOnDemandLayer.
65 IndirectStubsManagerBuilder BuildIndirectStubsManager);
66 /// Sets the ImplSymbolMap
67 void setImplMap(ImplSymbolMap *Imp);
68
69 /// Emits the given module. This should not be called by clients: it will be
70 /// called by the JIT when a definition added via the add method is requested.
71 void emit(std::unique_ptr<MaterializationResponsibility> R,
72 ThreadSafeModule TSM) override;
73
74private:
75 struct PerDylibResources {
76 public:
77 PerDylibResources(JITDylib &ImplD,
78 std::unique_ptr<IndirectStubsManager> ISMgr)
79 : ImplD(ImplD), ISMgr(std::move(ISMgr)) {}
80 JITDylib &getImplDylib() { return ImplD; }
81 IndirectStubsManager &getISManager() { return *ISMgr; }
82
83 private:
84 JITDylib &ImplD;
85 std::unique_ptr<IndirectStubsManager> ISMgr;
86 };
87
88 using PerDylibResourcesMap = std::map<const JITDylib *, PerDylibResources>;
89
90 PerDylibResources &getPerDylibResources(JITDylib &TargetD);
91
92 mutable std::mutex CODLayerMutex;
93
94 IRLayer &BaseLayer;
95 LazyCallThroughManager &LCTMgr;
96 IndirectStubsManagerBuilder BuildIndirectStubsManager;
97 PerDylibResourcesMap DylibResources;
98 ImplSymbolMap *AliaseeImpls = nullptr;
99};
100
101} // end namespace orc
102} // end namespace llvm
103
104#endif // LLVM_EXECUTIONENGINE_ORC_COMPILEONDEMANDLAYER_H
This file implements a class to represent arbitrary precision integral constant values and operations...
This file contains the simple types necessary to represent the attributes associated with functions a...
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This file contains some templates that are useful if you are working with the STL at all.
void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM) override
Emits the given module.
CompileOnDemandLayer(ExecutionSession &ES, IRLayer &BaseLayer, LazyCallThroughManager &LCTMgr, IndirectStubsManagerBuilder BuildIndirectStubsManager)
Construct a CompileOnDemandLayer.
void setImplMap(ImplSymbolMap *Imp)
Sets the ImplSymbolMap.
std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilder
Builder for IndirectStubsManagers.
An ExecutionSession represents a running JIT program.
Definition Core.h:1355
IRLayer(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions *&MO)
Definition Layer.h:70
Represents a JIT'd dynamic library.
Definition Core.h:902
Manages a set of 'lazy call-through' trampolines.
An LLVM Module together with a shared ThreadSafeContext.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851