21 #define DEBUG_TYPE "llvm-mca" 23 void Scheduler::initializeStrategy(std::unique_ptr<SchedulerStrategy> S) {
25 Strategy = S ? std::move(S) : llvm::make_unique<DefaultSchedulerStrategy>();
34 dbgs() <<
"[SCHEDULER]: WaitSet size is: " << WaitSet.size() <<
'\n';
35 dbgs() <<
"[SCHEDULER]: ReadySet size is: " << ReadySet.size() <<
'\n';
36 dbgs() <<
"[SCHEDULER]: IssuedSet size is: " << IssuedSet.size() <<
'\n';
44 switch (Resources->canBeDispatched(Desc.
Buffers)) {
66 void Scheduler::issueInstructionImpl(
68 SmallVectorImpl<std::pair<ResourceRef, ResourceCycles>> &UsedResources) {
74 Resources->issueInstruction(D, UsedResources);
81 IssuedSet.emplace_back(IR);
95 issueInstructionImpl(IR, UsedResources);
100 if (HasDependentUsers)
101 promoteToReadySet(ReadyInstructions);
107 unsigned RemovedElements = 0;
108 for (
auto I = WaitSet.begin(),
E = WaitSet.end();
I !=
E;) {
126 ReadySet.emplace_back(IR);
130 std::iter_swap(
I,
E - RemovedElements);
133 WaitSet.resize(WaitSet.size() - RemovedElements);
137 unsigned QueueIndex = ReadySet.size();
138 for (
unsigned I = 0,
E = ReadySet.size();
I !=
E; ++
I) {
140 if (QueueIndex == ReadySet.size() ||
141 Strategy->compare(IR, ReadySet[QueueIndex])) {
143 if (Resources->canBeIssued(D))
148 if (QueueIndex == ReadySet.size())
152 InstRef IR = ReadySet[QueueIndex];
153 std::swap(ReadySet[QueueIndex], ReadySet[ReadySet.size() - 1]);
159 unsigned RemovedElements = 0;
160 for (
auto I = IssuedSet.begin(),
E = IssuedSet.end();
I !=
E;) {
167 <<
" is still executing.\n");
177 std::iter_swap(
I,
E - RemovedElements);
180 IssuedSet.resize(IssuedSet.size() - RemovedElements);
187 Resources->cycleEvent(Freed);
193 updateIssuedSet(Executed);
198 promoteToReadySet(Ready);
213 Resources->reserveBuffers(Desc.
Buffers);
221 LLVM_DEBUG(
dbgs() <<
"[SCHEDULER] Adding #" << IR <<
" to the WaitSet\n");
222 WaitSet.push_back(IR);
235 LLVM_DEBUG(
dbgs() <<
"[SCHEDULER] Adding #" << IR <<
" to the ReadySet\n");
236 ReadySet.push_back(IR);
bool isReady(const InstRef &IR) const
Returns true if IR is ready to be executed by the underlying pipelines.
Instruction * getInstruction()
Status isAvailable(const InstRef &IR) const
virtual bool isReady(const InstRef &IR) const
Status isAvailable(const InstRef &IR) const
Check if the instruction in 'IR' can be dispatched and returns an answer in the form of a Status valu...
An instruction propagated through the simulated instruction pipeline.
bool hasDependentUsers() const
void cycleEvent(SmallVectorImpl< ResourceRef > &Freed, SmallVectorImpl< InstRef > &Ready, SmallVectorImpl< InstRef > &Executed)
This routine notifies the Scheduler that a new cycle just started.
This class represents lattice values for constants.
SmallVector< uint64_t, 4 > Buffers
InstRef select()
Select the next instruction to issue from the ReadySet.
void onInstructionExecuted(const InstRef &IR)
An InstRef contains both a SourceMgr index and Instruction pair.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
const InstrDesc & getDesc() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void invalidate()
Invalidate this reference.
void issueInstruction(InstRef &IR, SmallVectorImpl< std::pair< ResourceRef, ResourceCycles >> &Used, SmallVectorImpl< InstRef > &Ready)
Issue an instruction and populates a vector of used pipeline resources, and a vector of instructions ...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
virtual ~SchedulerStrategy()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
bool MustIssueImmediately
An instruction descriptor.
bool mustIssueImmediately(const InstRef &IR) const
Returns true if IR has to be issued immediately, or if IR is a zero latency instruction.
void emplace_back(ArgTypes &&... Args)
bool isZeroLatency() const
void dispatch(const InstRef &IR)
virtual ~DefaultSchedulerStrategy()
A scheduler for Processor Resource Units and Processor Resource Groups.
Statically lint checks LLVM IR
void dispatch(const InstRef &IR)
Reserves buffer and LSUnit queue resources that are necessary to issue this instruction.