20 #define DEBUG_TYPE "llvm-mca" 22 void Scheduler::initializeStrategy(std::unique_ptr<SchedulerStrategy> S) {
24 Strategy = S ? std::move(S) : std::make_unique<DefaultSchedulerStrategy>();
33 dbgs() <<
"[SCHEDULER]: WaitSet size is: " << WaitSet.size() <<
'\n';
34 dbgs() <<
"[SCHEDULER]: ReadySet size is: " << ReadySet.size() <<
'\n';
35 dbgs() <<
"[SCHEDULER]: IssuedSet size is: " << IssuedSet.size() <<
'\n';
70 void Scheduler::issueInstructionImpl(
72 SmallVectorImpl<std::pair<ResourceRef, ResourceCycles>> &UsedResources) {
78 Resources->issueInstruction(D, UsedResources);
93 IssuedSet.emplace_back(IR);
101 SmallVectorImpl<std::pair<ResourceRef, ResourceCycles>> &UsedResources,
109 issueInstructionImpl(IR, UsedResources);
114 if (HasDependentUsers)
115 if (promoteToPendingSet(PendingInstructions))
116 promoteToReadySet(ReadyInstructions);
122 unsigned PromotedElements = 0;
123 for (
auto I = PendingSet.begin(),
E = PendingSet.end();
I !=
E;) {
141 <<
" promoted to the READY set.\n");
144 ReadySet.emplace_back(IR);
148 std::iter_swap(
I,
E - PromotedElements);
151 PendingSet.resize(PendingSet.size() - PromotedElements);
152 return PromotedElements;
158 unsigned RemovedElements = 0;
159 for (
auto I = WaitSet.begin(),
E = WaitSet.end();
I !=
E;) {
178 <<
" promoted to the PENDING set.\n");
181 PendingSet.emplace_back(IR);
185 std::iter_swap(
I,
E - RemovedElements);
188 WaitSet.resize(WaitSet.size() - RemovedElements);
189 return RemovedElements;
193 unsigned QueueIndex = ReadySet.size();
194 for (
unsigned I = 0,
E = ReadySet.size();
I !=
E; ++
I) {
196 if (QueueIndex == ReadySet.size() ||
197 Strategy->compare(IR, ReadySet[QueueIndex])) {
199 uint64_t BusyResourceMask = Resources->checkAvailability(IS.
getDesc());
200 if (BusyResourceMask)
202 BusyResourceUnits |= BusyResourceMask;
203 if (!BusyResourceMask)
208 if (QueueIndex == ReadySet.size())
212 InstRef IR = ReadySet[QueueIndex];
213 std::swap(ReadySet[QueueIndex], ReadySet[ReadySet.size() - 1]);
219 unsigned RemovedElements = 0;
220 for (
auto I = IssuedSet.begin(),
E = IssuedSet.end();
I !=
E;) {
227 <<
" is still executing.\n");
237 std::iter_swap(
I,
E - RemovedElements);
240 IssuedSet.resize(IssuedSet.size() - RemovedElements);
244 Insts.
insert(Insts.
end(), ReadySet.begin(), ReadySet.end());
245 return BusyResourceUnits;
250 const auto EndIt = PendingSet.end() - NumDispatchedToThePendingSet;
253 if (Resources->checkAvailability(IS.
getDesc()))
271 Resources->cycleEvent(Freed);
275 updateIssuedSet(Executed);
283 promoteToPendingSet(Pending);
284 promoteToReadySet(Ready);
286 NumDispatchedToThePendingSet = 0;
287 BusyResourceUnits = 0;
309 LLVM_DEBUG(
dbgs() <<
"[SCHEDULER] Adding #" << IR <<
" to the WaitSet\n");
310 WaitSet.push_back(IR);
316 <<
" to the PendingSet\n");
317 PendingSet.push_back(IR);
318 ++NumDispatchedToThePendingSet;
323 "Unexpected internal state found!");
333 LLVM_DEBUG(
dbgs() <<
"[SCHEDULER] Adding #" << IR <<
" to the ReadySet\n");
334 ReadySet.push_back(IR);
void setCriticalMemDep(const CriticalDependency &MemDep)
Instruction * getInstruction()
reference emplace_back(ArgTypes &&... Args)
void execute(unsigned IID)
An instruction propagated through the simulated instruction pipeline.
bool hasDependentUsers() const
This class represents lattice values for constants.
Status isAvailable(const InstRef &IR)
Check if the instruction in 'IR' can be dispatched during this cycle.
void issueInstruction(InstRef &IR, SmallVectorImpl< std::pair< ResourceRef, ResourceCycles >> &Used, SmallVectorImpl< InstRef > &Pending, SmallVectorImpl< InstRef > &Ready)
Issue an instruction and populates a vector of used pipeline resources, and a vector of instructions ...
bool isDispatched() const
virtual Status isAvailable(const InstRef &IR) const =0
This method checks the availability of the load/store buffers.
InstRef select()
Select the next instruction to issue from the ReadySet.
An InstRef contains both a SourceMgr index and Instruction pair.
A node of a memory dependency graph.
virtual void cycleEvent()
unsigned getSourceIndex() const
virtual void onInstructionExecuted(const InstRef &IR)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void cycleEvent(SmallVectorImpl< ResourceRef > &Freed, SmallVectorImpl< InstRef > &Executed, SmallVectorImpl< InstRef > &Pending, SmallVectorImpl< InstRef > &Ready)
This routine notifies the Scheduler that a new cycle just started.
unsigned getLSUTokenID() const
uint64_t analyzeResourcePressure(SmallVectorImpl< InstRef > &Insts)
Returns a mask of busy resources, and populates vector Insts with instructions that could not be issu...
const InstrDesc & getDesc() const
uint64_t getUsedBuffers() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void invalidate()
Invalidate this reference.
void setLSUTokenID(unsigned LSUTok)
virtual unsigned dispatch(const InstRef &IR)=0
Allocates LS resources for instruction IR.
bool hasDependentUsers(const InstRef &IR) const
const CriticalDependency & computeCriticalRegDep()
ResourceStateEvent
Used to notify the internal state of a processor resource.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setCriticalResourceMask(uint64_t ResourceMask)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
virtual ~SchedulerStrategy()
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const CriticalDependency & getCriticalPredecessor() const
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.
iterator insert(iterator I, T &&Elt)
bool MustIssueImmediately
bool isPending(const InstRef &IR) const
Check if instruction IR only depends on memory instructions that are currently executing.
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.
bool isWaiting(const InstRef &IR) const
Check if instruction IR is still waiting on memory operations, and the wait time is still unknown...
void analyzeDataDependencies(SmallVectorImpl< InstRef > &RegDeps, SmallVectorImpl< InstRef > &MemDeps)
This method is called by the ExecuteStage at the end of each cycle to identify bottlenecks caused by ...
bool isZeroLatency() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual ~DefaultSchedulerStrategy()
A scheduler for Processor Resource Units and Processor Resource Groups.
bool dispatch(InstRef &IR)
Reserves buffer and LSUnit queue resources that are necessary to issue this instruction.
virtual void onInstructionIssued(const InstRef &IR)
Statically lint checks LLVM IR
const MemoryGroup & getGroup(unsigned Index) const
bool isReady(const InstRef &IR) const
Check if a peviously dispatched instruction IR is now ready for execution.