1 //===--------------------- Pipeline.h ---------------------------*- C++ -*-===// 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 /// 11 /// This file implements an ordered container of stages that simulate the 12 /// pipeline of a hardware backend. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_TOOLS_LLVM_MCA_PIPELINE_H 17 #define LLVM_TOOLS_LLVM_MCA_PIPELINE_H 18 19 #include "Scheduler.h" 20 #include "Stage.h" 21 #include "llvm/ADT/SmallVector.h" 22 23 namespace mca { 24 25 class HWEventListener; 26 class HWInstructionEvent; 27 class HWStallEvent; 28 29 /// A pipeline for a specific subtarget. 30 /// 31 /// It emulates an out-of-order execution of instructions. Instructions are 32 /// fetched from a MCInst sequence managed by an initial 'Fetch' stage. 33 /// Instructions are firstly fetched, then dispatched to the schedulers, and 34 /// then executed. 35 /// 36 /// This class tracks the lifetime of an instruction from the moment where 37 /// it gets dispatched to the schedulers, to the moment where it finishes 38 /// executing and register writes are architecturally committed. 39 /// In particular, it monitors changes in the state of every instruction 40 /// in flight. 41 /// 42 /// Instructions are executed in a loop of iterations. The number of iterations 43 /// is defined by the SourceMgr object, which is managed by the initial stage 44 /// of the instruction pipeline. 45 /// 46 /// The Pipeline entry point is method 'run()' which executes cycles in a loop 47 /// until there are new instructions to dispatch, and not every instruction 48 /// has been retired. 49 /// 50 /// Internally, the Pipeline collects statistical information in the form of 51 /// histograms. For example, it tracks how the dispatch group size changes 52 /// over time. 53 class Pipeline { 54 Pipeline(const Pipeline &P) = delete; 55 Pipeline &operator=(const Pipeline &P) = delete; 56 57 /// An ordered list of stages that define this instruction pipeline. 58 llvm::SmallVector<std::unique_ptr<Stage>, 8> Stages; 59 std::set<HWEventListener *> Listeners; 60 unsigned Cycles; 61 62 void preExecuteStages(); 63 bool executeStages(InstRef &IR); 64 void postExecuteStages(); 65 void runCycle(); 66 67 bool hasWorkToProcess(); 68 void notifyCycleBegin(); 69 void notifyCycleEnd(); 70 71 public: Pipeline()72 Pipeline() : Cycles(0) {} appendStage(std::unique_ptr<Stage> S)73 void appendStage(std::unique_ptr<Stage> S) { Stages.push_back(std::move(S)); } 74 void run(); 75 void addEventListener(HWEventListener *Listener); 76 }; 77 } // namespace mca 78 79 #endif // LLVM_TOOLS_LLVM_MCA_PIPELINE_H 80