[llvm] r336959 - [llvm-mca] Add cycleBegin/cycleEnd callbacks to mca::Stage.

Matt Davis via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 12 15:59:53 PDT 2018


Author: mattd
Date: Thu Jul 12 15:59:53 2018
New Revision: 336959

URL: http://llvm.org/viewvc/llvm-project?rev=336959&view=rev
Log:
[llvm-mca] Add cycleBegin/cycleEnd callbacks to mca::Stage.

Summary:
This patch  clears up some of the semantics within the Stage class.  Now, preExecute
can be called multiple times per simulated cycle.  Previously preExecute was
only called once per cycle, and postExecute could have been called multiple
times.

Now, cycleStart/cycleEnd are called only once per simulated cycle.
preExecute/postExecute can be called multiple times per cycle.  This
occurs because multiple execution events can occur during a single cycle.

When stages are executed (Pipeline::runCycle), the postExecute hook will
be called only if all Stages return a success from their 'execute' callback.

Reviewers: andreadb, courbet, RKSimon

Reviewed By: andreadb

Subscribers: tschuett, gbedwell, llvm-commits

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

Modified:
    llvm/trunk/tools/llvm-mca/DispatchStage.cpp
    llvm/trunk/tools/llvm-mca/DispatchStage.h
    llvm/trunk/tools/llvm-mca/ExecuteStage.cpp
    llvm/trunk/tools/llvm-mca/ExecuteStage.h
    llvm/trunk/tools/llvm-mca/FetchStage.cpp
    llvm/trunk/tools/llvm-mca/FetchStage.h
    llvm/trunk/tools/llvm-mca/Pipeline.cpp
    llvm/trunk/tools/llvm-mca/Pipeline.h
    llvm/trunk/tools/llvm-mca/RetireStage.cpp
    llvm/trunk/tools/llvm-mca/RetireStage.h
    llvm/trunk/tools/llvm-mca/Stage.h

Modified: llvm/trunk/tools/llvm-mca/DispatchStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/DispatchStage.cpp?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/DispatchStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/DispatchStage.cpp Thu Jul 12 15:59:53 2018
@@ -129,7 +129,7 @@ void DispatchStage::dispatch(InstRef IR)
   notifyInstructionDispatched(IR, RegisterFiles);
 }
 
-void DispatchStage::preExecute(const InstRef &IR) {
+void DispatchStage::cycleStart() {
   AvailableEntries = CarryOver >= DispatchWidth ? 0 : DispatchWidth - CarryOver;
   CarryOver = CarryOver >= DispatchWidth ? CarryOver - DispatchWidth : 0U;
 }

Modified: llvm/trunk/tools/llvm-mca/DispatchStage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/DispatchStage.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/DispatchStage.h (original)
+++ llvm/trunk/tools/llvm-mca/DispatchStage.h Thu Jul 12 15:59:53 2018
@@ -93,7 +93,7 @@ public:
   // The retire stage, which controls the RCU, might have items to complete but
   // RetireStage::hasWorkToComplete will check for that case.
   virtual bool hasWorkToComplete() const override final { return false; }
-  virtual void preExecute(const InstRef &IR) override final;
+  virtual void cycleStart() override final;
   virtual bool execute(InstRef &IR) override final;
   void notifyDispatchStall(const InstRef &IR, unsigned EventType);
 

Modified: llvm/trunk/tools/llvm-mca/ExecuteStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ExecuteStage.cpp?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/ExecuteStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/ExecuteStage.cpp Thu Jul 12 15:59:53 2018
@@ -89,7 +89,7 @@ void ExecuteStage::issueReadyInstruction
 // Notifications are issued to this stage's listeners when instructions are
 // moved between the HWS's queues.  In particular, when an instruction becomes
 // ready or executed.
-void ExecuteStage::preExecute(const InstRef &Unused) {
+void ExecuteStage::cycleStart() {
   reclaimSchedulerResources();
   updateSchedulerQueues();
   issueReadyInstructions();

Modified: llvm/trunk/tools/llvm-mca/ExecuteStage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ExecuteStage.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/ExecuteStage.h (original)
+++ llvm/trunk/tools/llvm-mca/ExecuteStage.h Thu Jul 12 15:59:53 2018
@@ -45,7 +45,7 @@ public:
   // execute(), so it is never left in a 'to-be-processed' state.
   virtual bool hasWorkToComplete() const override final { return false; }
 
-  virtual void preExecute(const InstRef &IR) override final;
+  virtual void cycleStart() override final;
   virtual bool execute(InstRef &IR) override final;
 
   void

Modified: llvm/trunk/tools/llvm-mca/FetchStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/FetchStage.cpp?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/FetchStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/FetchStage.cpp Thu Jul 12 15:59:53 2018
@@ -29,15 +29,18 @@ bool FetchStage::execute(InstRef &IR) {
   return true;
 }
 
-void FetchStage::postExecute(const InstRef &IR) {
+void FetchStage::postExecute(const InstRef &IR) { SM.updateNext(); }
+
+void FetchStage::cycleEnd() {
   // Find the first instruction which hasn't been retired.
   const InstMap::iterator It =
       llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) {
         return !KeyValuePair.second->isRetired();
       });
+
+  // Erase instructions up to the first that hasn't been retired.
   if (It != Instructions.begin())
     Instructions.erase(Instructions.begin(), It);
-  SM.updateNext();
 }
 
 } // namespace mca

Modified: llvm/trunk/tools/llvm-mca/FetchStage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/FetchStage.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/FetchStage.h (original)
+++ llvm/trunk/tools/llvm-mca/FetchStage.h Thu Jul 12 15:59:53 2018
@@ -37,6 +37,7 @@ public:
   bool hasWorkToComplete() const override final;
   bool execute(InstRef &IR) override final;
   void postExecute(const InstRef &IR) override final;
+  void cycleEnd() override final;
 };
 
 } // namespace mca

Modified: llvm/trunk/tools/llvm-mca/Pipeline.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Pipeline.cpp?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Pipeline.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Pipeline.cpp Thu Jul 12 15:59:53 2018
@@ -47,6 +47,11 @@ bool Pipeline::executeStages(InstRef &IR
   return true;
 }
 
+void Pipeline::preExecuteStages(const InstRef &IR) {
+  for (const std::unique_ptr<Stage> &S : Stages)
+    S->preExecute(IR);
+}
+
 void Pipeline::postExecuteStages(const InstRef &IR) {
   for (const std::unique_ptr<Stage> &S : Stages)
     S->postExecute(IR);
@@ -63,12 +68,19 @@ void Pipeline::runCycle(unsigned Cycle)
   // Update the stages before we do any processing for this cycle.
   InstRef IR;
   for (auto &S : Stages)
-    S->preExecute(IR);
+    S->cycleStart();
 
   // Continue executing this cycle until any stage claims it cannot make
   // progress.
-  while (executeStages(IR))
+  while (true) {
+    preExecuteStages(IR);
+    if (!executeStages(IR))
+      break;
     postExecuteStages(IR);
+  }
+
+  for (auto &S : Stages)
+    S->cycleEnd();
 
   notifyCycleEnd(Cycle);
 }

Modified: llvm/trunk/tools/llvm-mca/Pipeline.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Pipeline.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Pipeline.h (original)
+++ llvm/trunk/tools/llvm-mca/Pipeline.h Thu Jul 12 15:59:53 2018
@@ -59,6 +59,7 @@ class Pipeline {
   std::set<HWEventListener *> Listeners;
   unsigned Cycles;
 
+  void preExecuteStages(const InstRef &IR);
   bool executeStages(InstRef &IR);
   void postExecuteStages(const InstRef &IR);
   bool hasWorkToProcess();

Modified: llvm/trunk/tools/llvm-mca/RetireStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/RetireStage.cpp?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/RetireStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/RetireStage.cpp Thu Jul 12 15:59:53 2018
@@ -24,7 +24,7 @@ using namespace llvm;
 
 namespace mca {
 
-void RetireStage::preExecute(const InstRef &IR) {
+void RetireStage::cycleStart() {
   if (RCU.isEmpty())
     return;
 

Modified: llvm/trunk/tools/llvm-mca/RetireStage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/RetireStage.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/RetireStage.h (original)
+++ llvm/trunk/tools/llvm-mca/RetireStage.h Thu Jul 12 15:59:53 2018
@@ -37,7 +37,7 @@ public:
   virtual bool hasWorkToComplete() const override final {
     return !RCU.isEmpty();
   }
-  virtual void preExecute(const InstRef &IR) override final;
+  virtual void cycleStart() override final;
   virtual bool execute(InstRef &IR) override final { return true; }
   void notifyInstructionRetired(const InstRef &IR);
   void onInstructionExecuted(unsigned TokenID);

Modified: llvm/trunk/tools/llvm-mca/Stage.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Stage.h?rev=336959&r1=336958&r2=336959&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Stage.h (original)
+++ llvm/trunk/tools/llvm-mca/Stage.h Thu Jul 12 15:59:53 2018
@@ -41,15 +41,25 @@ public:
   /// retire.
   virtual bool hasWorkToComplete() const = 0;
 
-  /// Called as a setup phase to prepare for the main stage execution.
+  /// Called once at the start of each cycle.  This can be used as a setup
+  /// phase to prepare for the executions during the cycle.
+  virtual void cycleStart() {}
+
+  /// Called once at the end of each cycle.
+  virtual void cycleEnd() {}
+
+  /// Called prior to executing the list of stages.
+  /// This can be called multiple times per cycle.
   virtual void preExecute(const InstRef &IR) {}
 
-  /// Called as a cleanup and finalization phase after main stage execution.
+  /// Called as a cleanup and finalization phase after each execution.
+  /// This will only be called if all stages return a success from their
+  /// execute callback.  This can be called multiple times per cycle.
   virtual void postExecute(const InstRef &IR) {}
 
   /// The primary action that this stage performs.
   /// Returning false prevents successor stages from having their 'execute'
-  /// routine called.
+  /// routine called.  This can be called multiple times during a single cycle.
   virtual bool execute(InstRef &IR) = 0;
 
   /// Add a listener to receive callbacks during the execution of this stage.




More information about the llvm-commits mailing list