[llvm-mca] Refactor event listeners to make the backend agnostic to event types.

Summary: This is a first step towards making the pipeline configurable.

Subscribers: llvm-commits, andreadb

Differential Revision: https://reviews.llvm.org/D44309

llvm-svn: 327389
diff --git a/llvm/tools/llvm-mca/TimelineView.cpp b/llvm/tools/llvm-mca/TimelineView.cpp
index dd44bcc..cb51e9e 100644
--- a/llvm/tools/llvm-mca/TimelineView.cpp
+++ b/llvm/tools/llvm-mca/TimelineView.cpp
@@ -34,55 +34,44 @@
   std::fill(WaitTime.begin(), WaitTime.end(), NullWTEntry);
 }
 
-void TimelineView::onInstructionDispatched(unsigned Index) {
-  if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
+void TimelineView::onInstructionEvent(const HWInstructionEvent &Event) {
+  if (CurrentCycle >= MaxCycle || Event.Index >= Timeline.size())
     return;
-  Timeline[Index].CycleDispatched = CurrentCycle;
-  LastCycle = std::max(LastCycle, CurrentCycle);
-}
+  switch (Event.Type) {
+  case HWInstructionEvent::Retired: {
+    TimelineViewEntry &TVEntry = Timeline[Event.Index];
+    TVEntry.CycleRetired = CurrentCycle;
 
-void TimelineView::onInstructionReady(unsigned Index) {
-  if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
+    // Update the WaitTime entry which corresponds to this Index.
+    WaitTimeEntry &WTEntry = WaitTime[Event.Index % AsmSequence.size()];
+    WTEntry.Executions++;
+    WTEntry.CyclesSpentInSchedulerQueue +=
+        TVEntry.CycleIssued - TVEntry.CycleDispatched;
+    assert(TVEntry.CycleDispatched <= TVEntry.CycleReady);
+    WTEntry.CyclesSpentInSQWhileReady +=
+        TVEntry.CycleIssued - TVEntry.CycleReady;
+    WTEntry.CyclesSpentAfterWBAndBeforeRetire +=
+        (TVEntry.CycleRetired - 1) - TVEntry.CycleExecuted;
+    break;
+  }
+  case HWInstructionEvent::Ready:
+    Timeline[Event.Index].CycleReady = CurrentCycle;
+    break;
+  case HWInstructionEvent::Issued:
+    Timeline[Event.Index].CycleIssued = CurrentCycle;
+    break;
+  case HWInstructionEvent::Executed:
+    Timeline[Event.Index].CycleExecuted = CurrentCycle;
+    break;
+  case HWInstructionEvent::Dispatched:
+    Timeline[Event.Index].CycleDispatched = CurrentCycle;
+    break;
+  default:
     return;
-  Timeline[Index].CycleReady = CurrentCycle;
+  }
   LastCycle = std::max(LastCycle, CurrentCycle);
 }
 
-void TimelineView::onInstructionIssued(
-    unsigned Index,
-    const ArrayRef<std::pair<ResourceRef, unsigned>> & /* Unused */) {
-  if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
-    return;
-  Timeline[Index].CycleIssued = CurrentCycle;
-  LastCycle = std::max(LastCycle, CurrentCycle);
-}
-
-void TimelineView::onInstructionExecuted(unsigned Index) {
-  if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
-    return;
-  Timeline[Index].CycleExecuted = CurrentCycle;
-  LastCycle = std::max(LastCycle, CurrentCycle);
-}
-
-void TimelineView::onInstructionRetired(unsigned Index) {
-  if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
-    return;
-  TimelineViewEntry &TVEntry = Timeline[Index];
-  TVEntry.CycleRetired = CurrentCycle;
-  LastCycle = std::max(LastCycle, CurrentCycle);
-
-  // Update the WaitTime entry which corresponds to this Index.
-
-  WaitTimeEntry &WTEntry = WaitTime[Index % AsmSequence.size()];
-  WTEntry.Executions++;
-  WTEntry.CyclesSpentInSchedulerQueue +=
-      TVEntry.CycleIssued - TVEntry.CycleDispatched;
-  assert(TVEntry.CycleDispatched <= TVEntry.CycleReady);
-  WTEntry.CyclesSpentInSQWhileReady += TVEntry.CycleIssued - TVEntry.CycleReady;
-  WTEntry.CyclesSpentAfterWBAndBeforeRetire +=
-      (TVEntry.CycleRetired - 1) - TVEntry.CycleExecuted;
-}
-
 void TimelineView::printWaitTimeEntry(raw_string_ostream &OS,
                                       const WaitTimeEntry &Entry,
                                       unsigned SourceIndex) const {