[llvm-mca] Add pipeline stall events.
This patch introduces a new class named HWStallEvent (see HWEventListener.h),
and updates the event listener interface. A HWStallEvent represents a pipeline
stall caused by the lack of hardware resources. Similarly to HWInstructionEvent,
the event type is an unsigned, and the exact meaning depends on the subtarget.
At the moment, HWStallEvent supports a few generic dispatch events.
The main goals of this patch is to remove the logic that counts dispatch stalls
from the DispatchUnit to the BackendStatistics view.
Previously, DispatchUnit was responsible for counting and classifying dispatch
stall events. With this patch, we delegate the task of counting and classifying
stall events to the listeners (i.e. in our case, it is view
"BackendStatistics"). So, the DispatchUnit doesn't have to do extra
(unnecessary) bookkeeping.
This patch also helps futher simplifying the Backend interface. Now class
BackendStatistics no longer has to query the Backend interface to obtain the
number of dispatch stalls. As a consequence, we can get rid of all the
'getNumXXX()' methods from class Backend.
The long term goal is to remove all the remaining dependencies between the
Backend and the BackendStatistics interface.
Differential Revision: https://reviews.llvm.org/D44621
llvm-svn: 327837
diff --git a/llvm/tools/llvm-mca/Dispatch.h b/llvm/tools/llvm-mca/Dispatch.h
index 5a17b4d..e7c63c6 100644
--- a/llvm/tools/llvm-mca/Dispatch.h
+++ b/llvm/tools/llvm-mca/Dispatch.h
@@ -255,41 +255,9 @@
std::unique_ptr<RetireControlUnit> RCU;
Backend *Owner;
- /// Dispatch stall event identifiers.
- ///
- /// The naming convention is:
- /// * Event names starts with the "DS_" prefix
- /// * For dynamic dispatch stalls, the "DS_" prefix is followed by the
- /// the unavailable resource/functional unit acronym (example: RAT)
- /// * The last substring is the event reason (example: REG_UNAVAILABLE means
- /// that register renaming couldn't find enough spare registers in the
- /// register file).
- ///
- /// List of acronyms used for processor resoures:
- /// RAT - Register Alias Table (used by the register renaming logic)
- /// RCU - Retire Control Unit
- /// SQ - Scheduler's Queue
- /// LDQ - Load Queue
- /// STQ - Store Queue
- enum {
- DS_RAT_REG_UNAVAILABLE,
- DS_RCU_TOKEN_UNAVAILABLE,
- DS_SQ_TOKEN_UNAVAILABLE,
- DS_LDQ_TOKEN_UNAVAILABLE,
- DS_STQ_TOKEN_UNAVAILABLE,
- DS_DISPATCH_GROUP_RESTRICTION,
- DS_LAST
- };
-
- // The DispatchUnit track dispatch stall events caused by unavailable
- // of hardware resources. Events are classified based on the stall kind;
- // so we have a counter for every source of dispatch stall. Counters are
- // stored into a vector `DispatchStall` which is always of size DS_LAST.
- std::vector<unsigned> DispatchStalls;
-
- bool checkRAT(const Instruction &Desc);
- bool checkRCU(const InstrDesc &Desc);
- bool checkScheduler(const InstrDesc &Desc);
+ bool checkRAT(unsigned Index, const Instruction &Desc);
+ bool checkRCU(unsigned Index, const InstrDesc &Desc);
+ bool checkScheduler(unsigned Index, const InstrDesc &Desc);
void updateRAWDependencies(ReadState &RS, const llvm::MCSubtargetInfo &STI);
void notifyInstructionDispatched(unsigned IID);
@@ -304,7 +272,7 @@
RAT(llvm::make_unique<RegisterFile>(MRI, RegisterFileSize)),
RCU(llvm::make_unique<RetireControlUnit>(MicroOpBufferSize,
MaxRetirePerCycle, this)),
- Owner(B), DispatchStalls(DS_LAST, 0) {}
+ Owner(B) {}
unsigned getDispatchWidth() const { return DispatchWidth; }
@@ -314,10 +282,11 @@
bool isRCUEmpty() const { return RCU->isEmpty(); }
- bool canDispatch(const Instruction &Inst) {
+ bool canDispatch(unsigned Index, const Instruction &Inst) {
const InstrDesc &Desc = Inst.getDesc();
assert(isAvailable(Desc.NumMicroOps));
- return checkRCU(Desc) && checkRAT(Inst) && checkScheduler(Desc);
+ return checkRCU(Index, Desc) && checkRAT(Index, Inst) &&
+ checkScheduler(Index, Desc);
}
unsigned dispatch(unsigned IID, Instruction *NewInst,
@@ -327,24 +296,6 @@
unsigned RegID) const {
return RAT->collectWrites(Vec, RegID);
}
- unsigned getNumRATStalls() const {
- return DispatchStalls[DS_RAT_REG_UNAVAILABLE];
- }
- unsigned getNumRCUStalls() const {
- return DispatchStalls[DS_RCU_TOKEN_UNAVAILABLE];
- }
- unsigned getNumSQStalls() const {
- return DispatchStalls[DS_SQ_TOKEN_UNAVAILABLE];
- }
- unsigned getNumLDQStalls() const {
- return DispatchStalls[DS_LDQ_TOKEN_UNAVAILABLE];
- }
- unsigned getNumSTQStalls() const {
- return DispatchStalls[DS_STQ_TOKEN_UNAVAILABLE];
- }
- unsigned getNumDispatchGroupStalls() const {
- return DispatchStalls[DS_DISPATCH_GROUP_RESTRICTION];
- }
unsigned getMaxUsedRegisterMappings(unsigned RegFileIndex = 0) const {
return RAT->getMaxUsedRegisterMappings(RegFileIndex);
}
@@ -362,6 +313,8 @@
void notifyInstructionRetired(unsigned Index);
+ void notifyDispatchStall(unsigned Index, unsigned EventType);
+
void onInstructionExecuted(unsigned TokenID) {
RCU->onInstructionExecuted(TokenID);
}