[llvm-mca] Refactor how execution is orchestrated by the Pipeline.
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 16 Aug 2018 19:00:48 +0000 (19:00 +0000)
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>
Thu, 16 Aug 2018 19:00:48 +0000 (19:00 +0000)
commitdb63088ea7cc8890972e875c87550609e6bfaf4a
tree61a51d9fb868a510c6cf465feb3b38002b7a9f37
parent73e8a784e62f945a51363c8b5ec4eaedcf9f87e8
[llvm-mca] Refactor how execution is orchestrated by the Pipeline.

This patch changes how instruction execution is orchestrated by the Pipeline.
In particular, this patch makes it more explicit how instructions transition
through the various pipeline stages during execution.

The main goal is to simplify both the stage API and the Pipeline execution.  At
the same time, this patch fixes some design issues which are currently latent,
but that are likely to cause problems in future if people start defining custom
pipelines.

The new design assumes that each pipeline stage knows the "next-in-sequence".
The Stage API has gained three new methods:
 -   isAvailable(IR)
 -   checkNextStage(IR)
 -   moveToTheNextStage(IR).

An instruction IR can be executed by a Stage if method `Stage::isAvailable(IR)`
returns true.
Instructions can move to next stages using method moveToTheNextStage(IR).
An instruction cannot be moved to the next stage if method checkNextStage(IR)
(called on the current stage) returns false.
Stages are now responsible for moving instructions to the next stage in sequence
if necessary.

Instructions are allowed to transition through multiple stages during a single
cycle (as long as stages are available, and as long as all the calls to
`checkNextStage(IR)` returns true).

Methods `Stage::preExecute()` and `Stage::postExecute()` have now become
redundant, and those are removed by this patch.

Method Pipeline::runCycle() is now simpler, and it correctly visits stages
on every begin/end of cycle.

Other changes:
 - DispatchStage no longer requires a reference to the Scheduler.
 - ExecuteStage no longer needs to directly interact with the
   RetireControlUnit. Instead, executed instructions are now directly moved to the
   next stage (i.e. the retire stage).
 - RetireStage gained an execute method. This allowed us to remove the
   dependency with the RCU in ExecuteStage.
 - FecthStage now updates the "program counter" during cycleBegin() (i.e.
   before we start executing new instructions).
 - We no longer need Stage::Status to be returned by method execute(). It has
   been dropped in favor of a more lightweight llvm::Error.

Overally, I measured a ~11% performance gain w.r.t. the previous design.  I also
think that the Stage interface is probably easier to read now.  That being said,
code comments have to be improved, and I plan to do it in a follow-up patch.

Differential revision: https://reviews.llvm.org/D50849

llvm-svn: 339923
14 files changed:
llvm/tools/llvm-mca/Context.cpp
llvm/tools/llvm-mca/DispatchStage.cpp
llvm/tools/llvm-mca/DispatchStage.h
llvm/tools/llvm-mca/ExecuteStage.cpp
llvm/tools/llvm-mca/ExecuteStage.h
llvm/tools/llvm-mca/FetchStage.cpp
llvm/tools/llvm-mca/FetchStage.h
llvm/tools/llvm-mca/InstructionTables.cpp
llvm/tools/llvm-mca/InstructionTables.h
llvm/tools/llvm-mca/Pipeline.cpp
llvm/tools/llvm-mca/Pipeline.h
llvm/tools/llvm-mca/RetireStage.cpp
llvm/tools/llvm-mca/RetireStage.h
llvm/tools/llvm-mca/Stage.h