12#ifndef LLVM_EXECUTIONENGINE_ORC_REOPTIMIZELAYER_H
13#define LLVM_EXECUTIONENGINE_ORC_REOPTIMIZELAYER_H
52 BaseLayer(BaseLayer), RSManager(RM), ReOptFunc(
identity),
56 this->ReOptFunc = std::move(ReOptFunc);
60 this->ProfilerFunc = std::move(ProfilerFunc);
70 void emit(std::unique_ptr<MaterializationResponsibility> R,
97 class ReOptMaterializationUnitState {
99 ReOptMaterializationUnitState() =
default;
100 ReOptMaterializationUnitState(ReOptMaterializationUnitID
ID,
103 ReOptMaterializationUnitState(ReOptMaterializationUnitState &&
Other)
106 CurVersion(
Other.CurVersion) {}
108 ReOptMaterializationUnitID getID() {
return ID; }
110 const ThreadSafeModule &getThreadSafeModule() {
return TSM; }
113 std::unique_lock<std::mutex> Lock(Mutex);
117 void setResourceTracker(ResourceTrackerSP RT) {
118 std::unique_lock<std::mutex> Lock(Mutex);
122 uint32_t getCurVersion() {
123 std::unique_lock<std::mutex> Lock(Mutex);
128 LLVM_ABI void reoptimizeSucceeded();
133 ReOptMaterializationUnitID
ID;
134 ThreadSafeModule TSM;
136 bool Reoptimizing =
false;
137 uint32_t CurVersion = 0;
140 using SPSReoptimizeArgList =
141 shared::SPSArgList<ReOptMaterializationUnitID, uint32_t>;
142 using SendErrorFn = unique_function<void(Error)>;
144 Expected<SymbolMap> emitMUImplSymbols(ReOptMaterializationUnitState &MUState,
145 uint32_t Version, JITDylib &JD,
146 ThreadSafeModule TSM);
148 void rt_reoptimize(SendErrorFn SendResult, ReOptMaterializationUnitID MUID,
149 uint32_t CurVersion);
151 static Expected<Constant *>
152 createReoptimizeArgBuffer(
Module &M, ReOptMaterializationUnitID MUID,
153 uint32_t CurVersion);
155 ReOptMaterializationUnitState &
156 createMaterializationUnitState(
const ThreadSafeModule &TSM);
159 registerMaterializationUnitResource(ResourceKey Key,
160 ReOptMaterializationUnitState &State);
162 ReOptMaterializationUnitState &
163 getMaterializationUnitState(ReOptMaterializationUnitID MUID);
165 ExecutionSession &ES;
168 RedirectableSymbolManager &RSManager;
170 ReOptimizeFunc ReOptFunc;
171 AddProfilerFunc ProfilerFunc;
174 std::map<ReOptMaterializationUnitID, ReOptMaterializationUnitState> MUStates;
175 DenseMap<ResourceKey, DenseSet<ReOptMaterializationUnitID>> MUResources;
176 ReOptMaterializationUnitID NextID = 1;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Machine Check Debug Module
A parsed version of the target data layout string in and methods for querying it.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
A Module instance is used to store all the information related to an LLVM module.
An ExecutionSession represents a running JIT program.
IRLayer(ExecutionSession &ES, const IRSymbolMapper::ManglingOptions *&MO)
const IRSymbolMapper::ManglingOptions *& getManglingOptions() const
Get the mangling options for this layer.
Represents a JIT'd dynamic library.
unique_function< Error( ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned CurVersion, ResourceTrackerSP OldRT, ThreadSafeModule &TSM)> ReOptimizeFunc
ReOptimizeFunc will be called when ReOptimizeLayer reoptimization of a materialization unit was reque...
ReOptimizeLayer(ExecutionSession &ES, DataLayout &DL, IRLayer &BaseLayer, RedirectableSymbolManager &RM)
void setReoptimizeFunc(ReOptimizeFunc ReOptFunc)
static Error identity(ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned CurVersion, ResourceTrackerSP OldRT, ThreadSafeModule &TSM)
unique_function< Error( ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned CurVersion, ThreadSafeModule &TSM)> AddProfilerFunc
AddProfilerFunc will be called when ReOptimizeLayer emits the first version of a materialization unit...
void setAddProfilerFunc(AddProfilerFunc ProfilerFunc)
uint64_t ReOptMaterializationUnitID
static Error reoptimizeIfCallFrequent(ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned CurVersion, ThreadSafeModule &TSM)
Basic AddProfilerFunc that reoptimizes the function when the call count exceeds CallCountThreshold.
static const uint64_t CallCountThreshold
Base class for managing redirectable symbols in which a call gets redirected to another symbol in run...
Listens for ResourceTracker operations.
An LLVM Module together with a shared ThreadSafeContext.
unique_function is a type-erasing functor similar to std::function.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
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.
Implement std::hash so that hash_code can be used in STL containers.