1 //===---------------------- Stage.h -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file defines a stage.
12 /// A chain of stages compose an instruction pipeline.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TOOLS_LLVM_MCA_STAGE_H
17 #define LLVM_TOOLS_LLVM_MCA_STAGE_H
19 #include "HWEventListener.h"
27 Stage(const Stage &Other) = delete;
28 Stage &operator=(const Stage &Other) = delete;
29 std::set<HWEventListener *> Listeners;
32 const std::set<HWEventListener *> &getListeners() const { return Listeners; }
36 virtual ~Stage() = default;
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
42 virtual bool hasWorkToComplete() const = 0;
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.
46 virtual void cycleStart() {}
48 /// Called once at the end of each cycle.
49 virtual void cycleEnd() {}
51 /// Called prior to executing the list of stages.
52 /// This can be called multiple times per cycle.
53 virtual void preExecute() {}
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.
58 virtual void postExecute() {}
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;
65 /// Add a listener to receive callbacks during the execution of this stage.
66 void addListener(HWEventListener *Listener);
68 /// Notify listeners of a particular hardware event.
69 template <typename EventT> void notifyEvent(const EventT &Event) {
70 for (HWEventListener *Listener : Listeners)
71 Listener->onEvent(Event);
76 #endif // LLVM_TOOLS_LLVM_MCA_STAGE_H