12#ifndef LLVM_EXECUTIONENGINE_ORC_REOPTIMIZELAYER_H
13#define LLVM_EXECUTIONENGINE_ORC_REOPTIMIZELAYER_H
51 BaseLayer(BaseLayer), RSManager(RM), ReOptFunc(
identity),
55 this->ReOptFunc = std::move(ReOptFunc);
59 this->ProfilerFunc = std::move(ProfilerFunc);
69 void emit(std::unique_ptr<MaterializationResponsibility> R,
96 class ReOptMaterializationUnitState {
98 ReOptMaterializationUnitState() =
default;
102 ReOptMaterializationUnitState(ReOptMaterializationUnitState &&
Other)
105 CurVersion(
Other.CurVersion) {}
109 const ThreadSafeModule &getThreadSafeModule() {
return TSM; }
112 std::unique_lock<std::mutex> Lock(Mutex);
117 std::unique_lock<std::mutex> Lock(Mutex);
122 std::unique_lock<std::mutex> Lock(Mutex);
126 bool tryStartReoptimize();
127 void reoptimizeSucceeded();
128 void reoptimizeFailed();
133 ThreadSafeModule TSM;
135 bool Reoptimizing =
false;
139 using SPSReoptimizeArgList =
140 shared::SPSArgList<ReOptMaterializationUnitID, uint32_t>;
141 using SendErrorFn = unique_function<void(Error)>;
143 Expected<SymbolMap> emitMUImplSymbols(ReOptMaterializationUnitState &MUState,
145 ThreadSafeModule TSM);
150 static Expected<Constant *>
154 ReOptMaterializationUnitState &
155 createMaterializationUnitState(
const ThreadSafeModule &TSM);
158 registerMaterializationUnitResource(
ResourceKey Key,
159 ReOptMaterializationUnitState &State);
161 ReOptMaterializationUnitState &
164 ExecutionSession &ES;
165 MangleAndInterner Mangle;
167 RedirectableSymbolManager &RSManager;
173 std::map<ReOptMaterializationUnitID, ReOptMaterializationUnitState> MUStates;
174 DenseMap<ResourceKey, DenseSet<ReOptMaterializationUnitID>> MUResources;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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.
Interface for layers that accept LLVM IR.
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.
ReOptimizeLayer(ExecutionSession &ES, DataLayout &DL, IRLayer &BaseLayer, RedirectableSymbolManager &RM)
void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM) override
Emits the given module.
void setReoptimizeFunc(ReOptimizeFunc ReOptFunc)
Error reigsterRuntimeFunctions(JITDylib &PlatformJD)
Registers reoptimize runtime dispatch handlers to given PlatformJD.
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...
static void createReoptimizeCall(Module &M, Instruction &IP, GlobalVariable *ArgBuffer)
void setAddProfilerFunc(AddProfilerFunc ProfilerFunc)
uint64_t ReOptMaterializationUnitID
void handleTransferResources(JITDylib &JD, ResourceKey DstK, ResourceKey SrcK) override
This function will be called inside the session lock.
static Error reoptimizeIfCallFrequent(ReOptimizeLayer &Parent, ReOptMaterializationUnitID MUID, unsigned CurVersion, ThreadSafeModule &TSM)
Basic AddProfilerFunc that reoptimizes the function when the call count exceeds CallCountThreshold.
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...
Error handleRemoveResources(JITDylib &JD, ResourceKey K) override
This function will be called outside the session lock.
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.
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.