]> granicus.if.org Git - llvm/commitdiff
[llvm-mca] Simplify eventing by adding an onEvent templated method.
authorMatt Davis <Matthew.Davis@sony.com>
Thu, 12 Jul 2018 16:56:17 +0000 (16:56 +0000)
committerMatt Davis <Matthew.Davis@sony.com>
Thu, 12 Jul 2018 16:56:17 +0000 (16:56 +0000)
Summary:
This patch eliminates some redundancy in iterating across Listeners for the
Instruction and Stall HWEvents, by introducing a template onEvent routine.
This change was suggested by @courbet in https://reviews.llvm.org/D48576.  I
 hope that this patch addresses that suggestion appropriately.  I do like this
change better than what we had previously.

Reviewers: andreadb, courbet, RKSimon

Reviewed By: andreadb, courbet

Subscribers: javed.absar, tschuett, gbedwell, llvm-commits, courbet

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336916 91177308-0d34-0410-b5e6-96231b3b80d8

22 files changed:
tools/llvm-mca/DispatchStage.cpp
tools/llvm-mca/DispatchStage.h
tools/llvm-mca/DispatchStatistics.cpp
tools/llvm-mca/DispatchStatistics.h
tools/llvm-mca/ExecuteStage.cpp
tools/llvm-mca/HWEventListener.h
tools/llvm-mca/InstructionTables.cpp
tools/llvm-mca/RegisterFileStatistics.cpp
tools/llvm-mca/RegisterFileStatistics.h
tools/llvm-mca/ResourcePressureView.cpp
tools/llvm-mca/ResourcePressureView.h
tools/llvm-mca/RetireControlUnitStatistics.cpp
tools/llvm-mca/RetireControlUnitStatistics.h
tools/llvm-mca/RetireStage.cpp
tools/llvm-mca/SchedulerStatistics.cpp
tools/llvm-mca/SchedulerStatistics.h
tools/llvm-mca/Stage.cpp
tools/llvm-mca/Stage.h
tools/llvm-mca/SummaryView.cpp
tools/llvm-mca/SummaryView.h
tools/llvm-mca/TimelineView.cpp
tools/llvm-mca/TimelineView.h

index 21eef3d93d664b7e9c6a830f5af5c7bddb997b93..99cf8e077d10127b55353bdf944f4d671adba236 100644 (file)
@@ -30,12 +30,7 @@ namespace mca {
 void DispatchStage::notifyInstructionDispatched(const InstRef &IR,
                                                 ArrayRef<unsigned> UsedRegs) {
   LLVM_DEBUG(dbgs() << "[E] Instruction Dispatched: " << IR << '\n');
-  notifyInstructionEvent(HWInstructionDispatchedEvent(IR, UsedRegs));
-}
-
-void DispatchStage::notifyStallEvent(const HWStallEvent &Event) {
-  for (HWEventListener *Listener : getListeners())
-    Listener->onStallEvent(Event);
+  notifyEvent<HWInstructionEvent>(HWInstructionDispatchedEvent(IR, UsedRegs));
 }
 
 bool DispatchStage::checkPRF(const InstRef &IR) {
@@ -47,7 +42,8 @@ bool DispatchStage::checkPRF(const InstRef &IR) {
   const unsigned RegisterMask = PRF.isAvailable(RegDefs);
   // A mask with all zeroes means: register files are available.
   if (RegisterMask) {
-    notifyStallEvent(HWStallEvent(HWStallEvent::RegisterFileStall, IR));
+    notifyEvent<HWStallEvent>(
+        HWStallEvent(HWStallEvent::RegisterFileStall, IR));
     return false;
   }
 
@@ -58,7 +54,8 @@ bool DispatchStage::checkRCU(const InstRef &IR) {
   const unsigned NumMicroOps = IR.getInstruction()->getDesc().NumMicroOps;
   if (RCU.isAvailable(NumMicroOps))
     return true;
-  notifyStallEvent(HWStallEvent(HWStallEvent::RetireControlUnitStall, IR));
+  notifyEvent<HWStallEvent>(
+      HWStallEvent(HWStallEvent::RetireControlUnitStall, IR));
   return false;
 }
 
@@ -66,7 +63,7 @@ bool DispatchStage::checkScheduler(const InstRef &IR) {
   HWStallEvent::GenericEventType Event;
   const bool Ready = SC.canBeDispatched(IR, Event);
   if (!Ready)
-    notifyStallEvent(HWStallEvent(Event, IR));
+    notifyEvent<HWStallEvent>(HWStallEvent(Event, IR));
   return Ready;
 }
 
index fff9a2bb114e13a2c4ae46ddeb39d5fed6ecceef..65ac2bc73147e53c4d8c2670d5bfc90a868a69bf 100644 (file)
@@ -64,7 +64,6 @@ class DispatchStage : public Stage {
   void dispatch(InstRef IR);
   void updateRAWDependencies(ReadState &RS, const llvm::MCSubtargetInfo &STI);
 
-  void notifyStallEvent(const HWStallEvent &Event);
   void notifyInstructionDispatched(const InstRef &IR,
                                    llvm::ArrayRef<unsigned> UsedPhysRegs);
 
index da852454e8f07e1b297e71bf3972c68e6b17e8f9..4bddbef9a0c8191b9e042263ff8359b0e1e33dbb 100644 (file)
@@ -20,12 +20,12 @@ using namespace llvm;
 
 namespace mca {
 
-void DispatchStatistics::onStallEvent(const HWStallEvent &Event) {
+void DispatchStatistics::onEvent(const HWStallEvent &Event) {
   if (Event.Type < HWStallEvent::LastGenericEvent)
     HWStalls[Event.Type]++;
 }
 
-void DispatchStatistics::onInstructionEvent(const HWInstructionEvent &Event) {
+void DispatchStatistics::onEvent(const HWInstructionEvent &Event) {
   if (Event.Type == HWInstructionEvent::Dispatched)
     ++NumDispatched;
 }
index 7b98a848df6435825e99b7c703c24de42786fdf6..1e389d54766bdbe1c3ddc027d190cab66b8ed299 100644 (file)
@@ -66,14 +66,14 @@ public:
       : NumDispatched(0), NumCycles(0),
         HWStalls(HWStallEvent::LastGenericEvent) {}
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWStallEvent &Event) override;
+
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void onCycleBegin() override { NumCycles++; }
 
   void onCycleEnd() override { updateHistograms(); }
 
-  void onStallEvent(const HWStallEvent &Event) override;
-
   void printView(llvm::raw_ostream &OS) const override {
     printDispatchStalls(OS);
     printDispatchHistogram(OS);
index c446ad67725dc60acb5181e97d2f40930322283a..f2e458dcabd5cbedb04febe16398988f5c58d965 100644 (file)
@@ -154,13 +154,15 @@ bool ExecuteStage::execute(InstRef &IR) {
 void ExecuteStage::notifyInstructionExecuted(const InstRef &IR) {
   HWS.onInstructionExecuted(IR);
   LLVM_DEBUG(dbgs() << "[E] Instruction Executed: " << IR << '\n');
-  notifyInstructionEvent(HWInstructionEvent(HWInstructionEvent::Executed, IR));
+  notifyEvent<HWInstructionEvent>(
+      HWInstructionEvent(HWInstructionEvent::Executed, IR));
   RCU.onInstructionExecuted(IR.getInstruction()->getRCUTokenID());
 }
 
 void ExecuteStage::notifyInstructionReady(const InstRef &IR) {
   LLVM_DEBUG(dbgs() << "[E] Instruction Ready: " << IR << '\n');
-  notifyInstructionEvent(HWInstructionEvent(HWInstructionEvent::Ready, IR));
+  notifyEvent<HWInstructionEvent>(
+      HWInstructionEvent(HWInstructionEvent::Ready, IR));
 }
 
 void ExecuteStage::notifyResourceAvailable(const ResourceRef &RR) {
@@ -180,7 +182,7 @@ void ExecuteStage::notifyInstructionIssued(
       dbgs() << "           cycles: " << Resource.second << '\n';
     }
   });
-  notifyInstructionEvent(HWInstructionIssuedEvent(IR, Used));
+  notifyEvent<HWInstructionEvent>(HWInstructionIssuedEvent(IR, Used));
 }
 
 void ExecuteStage::notifyReservedBuffers(ArrayRef<uint64_t> Buffers) {
index c7384d51b13090e96acc8d3bdd7aa48058c58147..aa3e6dcf19a0288609d099114455e7e857dd7d1a 100644 (file)
@@ -120,8 +120,8 @@ public:
   virtual void onCycleBegin() {}
   virtual void onCycleEnd() {}
 
-  virtual void onInstructionEvent(const HWInstructionEvent &Event) {}
-  virtual void onStallEvent(const HWStallEvent &Event) {}
+  virtual void onEvent(const HWInstructionEvent &Event) {}
+  virtual void onEvent(const HWStallEvent &Event) {}
 
   using ResourceRef = std::pair<uint64_t, uint64_t>;
   virtual void onResourceAvailable(const ResourceRef &RRef) {}
index 652ef20138816e219b690fb66484cb07b4a31d80..c7cce7cafa00216f45c9586420f4f4c50eb55b44 100644 (file)
@@ -39,9 +39,8 @@ void InstructionTables::run() {
       if (!Resource.second.size())
         continue;
       double Cycles = static_cast<double>(Resource.second.size());
-      unsigned Index =
-          std::distance(Masks.begin(), std::find(Masks.begin(), Masks.end(),
-                                                 Resource.first));
+      unsigned Index = std::distance(
+          Masks.begin(), std::find(Masks.begin(), Masks.end(), Resource.first));
       const MCProcResourceDesc &ProcResource = *SM.getProcResource(Index);
       unsigned NumUnits = ProcResource.NumUnits;
       if (!ProcResource.SubUnitsIdxBegin) {
@@ -73,7 +72,7 @@ void InstructionTables::run() {
     InstRef IR(SR.first, Inst.get());
     HWInstructionIssuedEvent Event(IR, UsedResources);
     for (std::unique_ptr<View> &Listener : Views)
-      Listener->onInstructionEvent(Event);
+      Listener->onEvent(Event);
     S.updateNext();
   }
 }
index 46302bf41b242cfe5f2b387320ab319007f7d450..1b07bf9a3b33a594a2835f1a257864e89201af63 100644 (file)
@@ -39,8 +39,7 @@ void RegisterFileStatistics::initializeRegisterFileInfo() {
   std::fill(RegisterFiles.begin(), RegisterFiles.end(), Empty);
 }
 
-void RegisterFileStatistics::onInstructionEvent(
-    const HWInstructionEvent &Event) {
+void RegisterFileStatistics::onEvent(const HWInstructionEvent &Event) {
   switch (Event.Type) {
   default:
     break;
index d36b61ecd2b7c398c51bf4f4225ded8f8a0ad30e..cbe816cd33325ae9cb5cb01346ca4baa475684d1 100644 (file)
@@ -58,7 +58,7 @@ public:
     initializeRegisterFileInfo();
   }
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void printView(llvm::raw_ostream &OS) const override;
 };
index 37bb059c907872d04076530858dd2cd9021a54b3..fe9d5b7fabc899fce866e81e22998168424ab21d 100644 (file)
@@ -40,7 +40,7 @@ void ResourcePressureView::initialize() {
   std::fill(ResourceUsage.begin(), ResourceUsage.end(), 0.0);
 }
 
-void ResourcePressureView::onInstructionEvent(const HWInstructionEvent &Event) {
+void ResourcePressureView::onEvent(const HWInstructionEvent &Event) {
   // We're only interested in Issue events.
   if (Event.Type != HWInstructionEvent::Issued)
     return;
index c15cf1832adc1be484700579c095c1cb383b3f8f..fe1c6af5e6f6c5c1a159b94ad08da96654d9cc5c 100644 (file)
@@ -96,7 +96,7 @@ public:
     initialize();
   }
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void printView(llvm::raw_ostream &OS) const override {
     unsigned Executions = Source.getNumIterations();
index 5d3632f14a42e39d32698121db5e0bdd0ebd2199..edb855e11e84ef10d94018fbe91ea3303d86db2b 100644 (file)
@@ -19,8 +19,7 @@ using namespace llvm;
 
 namespace mca {
 
-void RetireControlUnitStatistics::onInstructionEvent(
-    const HWInstructionEvent &Event) {
+void RetireControlUnitStatistics::onEvent(const HWInstructionEvent &Event) {
   if (Event.Type == HWInstructionEvent::Retired)
     ++NumRetired;
 }
index 5c91af532ecb39a3c83975225b2b8f245a5da86f..1f03e7efe889679e6ef9f64a94b5dcba8b0b543b 100644 (file)
@@ -47,7 +47,7 @@ class RetireControlUnitStatistics : public View {
 public:
   RetireControlUnitStatistics() : NumRetired(0), NumCycles(0) {}
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void onCycleBegin() override { NumCycles++; }
 
index 0d1f4e4303585f4503e317ed9718a53e696089d8..b4dcc2860353ff518d84b0bfaed61fee7dd15421 100644 (file)
@@ -49,7 +49,7 @@ void RetireStage::notifyInstructionRetired(const InstRef &IR) {
 
   for (const std::unique_ptr<WriteState> &WS : IR.getInstruction()->getDefs())
     PRF.removeRegisterWrite(*WS.get(), FreedRegs, !Desc.isZeroLatency());
-  notifyInstructionEvent(HWInstructionRetiredEvent(IR, FreedRegs));
+  notifyEvent<HWInstructionEvent>(HWInstructionRetiredEvent(IR, FreedRegs));
 }
 
 } // namespace mca
index dc38f6889c9411a6aa5eb0e18c215a60bd2405ab..5c6d22a718121bdc546fad1e5415e55a78072c52 100644 (file)
@@ -19,7 +19,7 @@ using namespace llvm;
 
 namespace mca {
 
-void SchedulerStatistics::onInstructionEvent(const HWInstructionEvent &Event) {
+void SchedulerStatistics::onEvent(const HWInstructionEvent &Event) {
   if (Event.Type == HWInstructionEvent::Issued)
     ++NumIssued;
 }
index 08d8a3494372fe4704f23a4a24cdab5c364953bc..7383c54a16151d4f106a88120ca85ea926b71981 100644 (file)
@@ -65,9 +65,9 @@ class SchedulerStatistics : public View {
 
 public:
   SchedulerStatistics(const llvm::MCSubtargetInfo &STI)
-      : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0) { }
+      : SM(STI.getSchedModel()), NumIssued(0), NumCycles(0) {}
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void onCycleBegin() override { NumCycles++; }
 
index cfcb3f8bde07161e75cbddba3ba8fe8d9c2e97e1..7ead940e63c1e1d42d573c91390d7ff805b97612 100644 (file)
@@ -24,9 +24,4 @@ void Stage::addListener(HWEventListener *Listener) {
   Listeners.insert(Listener);
 }
 
-void Stage::notifyInstructionEvent(const HWInstructionEvent &Event) {
-  for (HWEventListener *Listener : Listeners)
-    Listener->onInstructionEvent(Event);
-}
-
 } // namespace mca
index 2719376f757126a5fbc1370b54e397a493a37e0c..80d4906ec9b3354666eca76c82ef960efc3c375c 100644 (file)
@@ -55,7 +55,11 @@ public:
   /// Add a listener to receive callbacks during the execution of this stage.
   void addListener(HWEventListener *Listener);
 
-  virtual void notifyInstructionEvent(const HWInstructionEvent &Event);
+  /// Notify listeners of a particular hardware event.
+  template <typename EventT> void notifyEvent(const EventT &Event) {
+    for (HWEventListener *Listener : Listeners)
+      Listener->onEvent(Event);
+  }
 };
 
 } // namespace mca
index 5cb5c23c973921146c4a1665b81a4a86b3cc4276..01399055c4fd5144da70dac056be24a1e093ed82 100644 (file)
@@ -32,7 +32,7 @@ SummaryView::SummaryView(const llvm::MCSchedModel &Model, const SourceMgr &S,
   computeProcResourceMasks(SM, ProcResourceMasks);
 }
 
-void SummaryView::onInstructionEvent(const HWInstructionEvent &Event) {
+void SummaryView::onEvent(const HWInstructionEvent &Event) {
   // We are only interested in the "instruction dispatched" events generated by
   // the dispatch stage for instructions that are part of iteration #0.
   if (Event.Type != HWInstructionEvent::Dispatched)
index 04f4a871247f6455864647ca811e03178979255d..b799ce3aa7473048bbaa1e7ac32413b0827cb576 100644 (file)
@@ -67,7 +67,7 @@ public:
 
   void onCycleEnd() override { ++TotalCycles; }
 
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   void printView(llvm::raw_ostream &OS) const override;
 };
index 8087ea97e3cbccc5039d3d6777402c6c8e0fd208..6e75cac0d4323231da9ace8284293d8a79462322 100644 (file)
@@ -34,7 +34,7 @@ void TimelineView::initialize(unsigned MaxIterations) {
   std::fill(WaitTime.begin(), WaitTime.end(), NullWTEntry);
 }
 
-void TimelineView::onInstructionEvent(const HWInstructionEvent &Event) {
+void TimelineView::onEvent(const HWInstructionEvent &Event) {
   const unsigned Index = Event.IR.getSourceIndex();
   if (CurrentCycle >= MaxCycle || Index >= Timeline.size())
     return;
index 1a85ca1de64213f4da09670397c86b396c411cac..e53c23ec1cc22c753e3d8f80e63b2e2c638b5dd9 100644 (file)
@@ -174,7 +174,7 @@ public:
 
   // Event handlers.
   void onCycleEnd() override { ++CurrentCycle; }
-  void onInstructionEvent(const HWInstructionEvent &Event) override;
+  void onEvent(const HWInstructionEvent &Event) override;
 
   // print functionalities.
   void printTimeline(llvm::raw_ostream &OS) const;