File indexing completed on 2026-05-10 08:44:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_MCA_STAGES_STAGE_H
0016 #define LLVM_MCA_STAGES_STAGE_H
0017
0018 #include "llvm/MCA/HWEventListener.h"
0019 #include "llvm/Support/Error.h"
0020 #include <set>
0021
0022 namespace llvm {
0023 namespace mca {
0024
0025 class InstRef;
0026
0027 class Stage {
0028 Stage *NextInSequence = nullptr;
0029 std::set<HWEventListener *> Listeners;
0030
0031 Stage(const Stage &Other) = delete;
0032 Stage &operator=(const Stage &Other) = delete;
0033
0034 protected:
0035 const std::set<HWEventListener *> &getListeners() const { return Listeners; }
0036
0037 public:
0038 Stage() = default;
0039 virtual ~Stage();
0040
0041
0042 virtual bool isAvailable(const InstRef &IR) const { return true; }
0043
0044
0045 virtual bool hasWorkToComplete() const = 0;
0046
0047
0048
0049 virtual Error cycleStart() { return ErrorSuccess(); }
0050
0051
0052 virtual Error cycleResume() { return ErrorSuccess(); }
0053
0054
0055 virtual Error cycleEnd() { return ErrorSuccess(); }
0056
0057
0058 virtual Error execute(InstRef &IR) = 0;
0059
0060 void setNextInSequence(Stage *NextStage) {
0061 assert(!NextInSequence && "This stage already has a NextInSequence!");
0062 NextInSequence = NextStage;
0063 }
0064
0065 bool checkNextStage(const InstRef &IR) const {
0066 return NextInSequence && NextInSequence->isAvailable(IR);
0067 }
0068
0069
0070
0071
0072
0073 Error moveToTheNextStage(InstRef &IR) {
0074 assert(checkNextStage(IR) && "Next stage is not ready!");
0075 return NextInSequence->execute(IR);
0076 }
0077
0078
0079 void addListener(HWEventListener *Listener);
0080
0081
0082 template <typename EventT> void notifyEvent(const EventT &Event) const {
0083 for (HWEventListener *Listener : Listeners)
0084 Listener->onEvent(Event);
0085 }
0086 };
0087
0088
0089
0090 struct InstStreamPause : public ErrorInfo<InstStreamPause> {
0091 static char ID;
0092
0093 std::error_code convertToErrorCode() const override {
0094 return llvm::inconvertibleErrorCode();
0095 }
0096 void log(raw_ostream &OS) const override { OS << "Stream is paused"; }
0097 };
0098 }
0099 }
0100 #endif