1 //===---------------------- Stage.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 defines a stage. 12 /// A chain of stages compose an instruction pipeline. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #ifndef LLVM_TOOLS_LLVM_MCA_STAGE_H 17 #define LLVM_TOOLS_LLVM_MCA_STAGE_H 18 19 #include "HWEventListener.h" 20 #include <set> 21 22 namespace mca { 23 24 class InstRef; 25 26 class Stage { 27 Stage(const Stage &Other) = delete; 28 Stage &operator=(const Stage &Other) = delete; 29 std::set<HWEventListener *> Listeners; 30 31 protected: getListeners()32 const std::set<HWEventListener *> &getListeners() const { return Listeners; } 33 34 public: 35 Stage(); 36 virtual ~Stage() = default; 37 38 /// Called prior to preExecute to ensure that the stage has items that it 39 /// is to process. For example, a FetchStage might have more instructions 40 /// that need to be processed, or a RCU might have items that have yet to 41 /// retire. 42 virtual bool hasWorkToComplete() const = 0; 43 44 /// Called once at the start of each cycle. This can be used as a setup 45 /// phase to prepare for the executions during the cycle. cycleStart()46 virtual void cycleStart() {} 47 48 /// Called once at the end of each cycle. cycleEnd()49 virtual void cycleEnd() {} 50 51 /// Called prior to executing the list of stages. 52 /// This can be called multiple times per cycle. preExecute()53 virtual void preExecute() {} 54 55 /// Called as a cleanup and finalization phase after each execution. 56 /// This will only be called if all stages return a success from their 57 /// execute callback. This can be called multiple times per cycle. postExecute()58 virtual void postExecute() {} 59 60 /// The primary action that this stage performs. 61 /// Returning false prevents successor stages from having their 'execute' 62 /// routine called. This can be called multiple times during a single cycle. 63 virtual bool execute(InstRef &IR) = 0; 64 65 /// Add a listener to receive callbacks during the execution of this stage. 66 void addListener(HWEventListener *Listener); 67 68 /// Notify listeners of a particular hardware event. notifyEvent(const EventT & Event)69 template <typename EventT> void notifyEvent(const EventT &Event) { 70 for (HWEventListener *Listener : Listeners) 71 Listener->onEvent(Event); 72 } 73 }; 74 75 } // namespace mca 76 #endif // LLVM_TOOLS_LLVM_MCA_STAGE_H 77