| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 1 | //===--------------------- Pipeline.h ---------------------------*- C++ -*-===// |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 11 | /// This file implements an ordered container of stages that simulate the |
| 12 | /// pipeline of a hardware backend. |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 13 | /// |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 16 | #ifndef LLVM_TOOLS_LLVM_MCA_PIPELINE_H |
| 17 | #define LLVM_TOOLS_LLVM_MCA_PIPELINE_H |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 18 | |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 19 | #include "Scheduler.h" |
| Matt Davis | 43de6db | 2018-06-22 16:17:26 +0000 | [diff] [blame] | 20 | #include "Stage.h" |
| 21 | #include "llvm/ADT/SmallVector.h" |
| Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Error.h" |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 23 | |
| 24 | namespace mca { |
| 25 | |
| Andrea Di Biagio | 3db1fd9 | 2018-03-08 16:34:19 +0000 | [diff] [blame] | 26 | class HWEventListener; |
| Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 27 | class HWInstructionEvent; |
| Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame] | 28 | class HWStallEvent; |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 29 | |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 30 | /// A pipeline for a specific subtarget. |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 31 | /// |
| 32 | /// It emulates an out-of-order execution of instructions. Instructions are |
| Matt Davis | 5d1cda1 | 2018-05-15 20:21:04 +0000 | [diff] [blame] | 33 | /// fetched from a MCInst sequence managed by an initial 'Fetch' stage. |
| 34 | /// Instructions are firstly fetched, then dispatched to the schedulers, and |
| 35 | /// then executed. |
| 36 | /// |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 37 | /// This class tracks the lifetime of an instruction from the moment where |
| 38 | /// it gets dispatched to the schedulers, to the moment where it finishes |
| 39 | /// executing and register writes are architecturally committed. |
| 40 | /// In particular, it monitors changes in the state of every instruction |
| 41 | /// in flight. |
| Matt Davis | 5d1cda1 | 2018-05-15 20:21:04 +0000 | [diff] [blame] | 42 | /// |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 43 | /// Instructions are executed in a loop of iterations. The number of iterations |
| Matt Davis | 5d1cda1 | 2018-05-15 20:21:04 +0000 | [diff] [blame] | 44 | /// is defined by the SourceMgr object, which is managed by the initial stage |
| 45 | /// of the instruction pipeline. |
| 46 | /// |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 47 | /// The Pipeline entry point is method 'run()' which executes cycles in a loop |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 48 | /// until there are new instructions to dispatch, and not every instruction |
| 49 | /// has been retired. |
| Matt Davis | 5d1cda1 | 2018-05-15 20:21:04 +0000 | [diff] [blame] | 50 | /// |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 51 | /// Internally, the Pipeline collects statistical information in the form of |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 52 | /// histograms. For example, it tracks how the dispatch group size changes |
| 53 | /// over time. |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 54 | class Pipeline { |
| Matt Davis | 8238def | 2018-06-28 17:33:24 +0000 | [diff] [blame] | 55 | Pipeline(const Pipeline &P) = delete; |
| 56 | Pipeline &operator=(const Pipeline &P) = delete; |
| 57 | |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 58 | /// An ordered list of stages that define this instruction pipeline. |
| Matt Davis | 43de6db | 2018-06-22 16:17:26 +0000 | [diff] [blame] | 59 | llvm::SmallVector<std::unique_ptr<Stage>, 8> Stages; |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 60 | std::set<HWEventListener *> Listeners; |
| Matt Davis | 5d1cda1 | 2018-05-15 20:21:04 +0000 | [diff] [blame] | 61 | unsigned Cycles; |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 62 | |
| Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 63 | llvm::Error runCycle(); |
| Matt Davis | 43de6db | 2018-06-22 16:17:26 +0000 | [diff] [blame] | 64 | bool hasWorkToProcess(); |
| Andrea Di Biagio | ef6b8a3 | 2018-07-13 09:27:34 +0000 | [diff] [blame] | 65 | void notifyCycleBegin(); |
| 66 | void notifyCycleEnd(); |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 67 | |
| 68 | public: |
| Andrea Di Biagio | 4335b3e | 2018-07-13 09:31:02 +0000 | [diff] [blame] | 69 | Pipeline() : Cycles(0) {} |
| Andrea Di Biagio | db63088 | 2018-08-16 19:00:48 +0000 | [diff] [blame] | 70 | void appendStage(std::unique_ptr<Stage> S); |
| Matt Davis | 4bcf369 | 2018-08-13 18:11:48 +0000 | [diff] [blame] | 71 | llvm::Error run(); |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 72 | void addEventListener(HWEventListener *Listener); |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 73 | }; |
| Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 74 | } // namespace mca |
| 75 | |
| Matt Davis | dea343d | 2018-06-25 16:53:00 +0000 | [diff] [blame] | 76 | #endif // LLVM_TOOLS_LLVM_MCA_PIPELINE_H |