LLVM 22.0.0git
Stage.h
Go to the documentation of this file.
1//===---------------------- Stage.h -----------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file defines a stage.
11/// A chain of stages compose an instruction pipeline.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_MCA_STAGES_STAGE_H
16#define LLVM_MCA_STAGES_STAGE_H
17
20#include "llvm/Support/Error.h"
21#include <set>
22
23namespace llvm {
24namespace mca {
25
26class InstRef;
27
29 Stage *NextInSequence = nullptr;
30 std::set<HWEventListener *> Listeners;
31
32 Stage(const Stage &Other) = delete;
33 Stage &operator=(const Stage &Other) = delete;
34
35protected:
36 const std::set<HWEventListener *> &getListeners() const { return Listeners; }
37
38public:
39 Stage() = default;
40 virtual ~Stage();
41
42 /// Returns true if it can execute IR during this cycle.
43 virtual bool isAvailable(const InstRef &IR) const { return true; }
44
45 /// Returns true if some instructions are still executing this stage.
46 virtual bool hasWorkToComplete() const = 0;
47
48 /// Called once at the start of each cycle. This can be used as a setup
49 /// phase to prepare for the executions during the cycle.
50 virtual Error cycleStart() { return ErrorSuccess(); }
51
52 /// Called after the pipeline is resumed from pausing state.
53 virtual Error cycleResume() { return ErrorSuccess(); }
54
55 /// Called once at the end of each cycle.
56 virtual Error cycleEnd() { return ErrorSuccess(); }
57
58 /// The primary action that this stage performs on instruction IR.
59 virtual Error execute(InstRef &IR) = 0;
60
61 void setNextInSequence(Stage *NextStage) {
62 assert(!NextInSequence && "This stage already has a NextInSequence!");
63 NextInSequence = NextStage;
64 }
65
66 bool checkNextStage(const InstRef &IR) const {
67 return NextInSequence && NextInSequence->isAvailable(IR);
68 }
69
70 /// Called when an instruction is ready to move the next pipeline stage.
71 ///
72 /// Stages are responsible for moving instructions to their immediate
73 /// successor stages.
75 assert(checkNextStage(IR) && "Next stage is not ready!");
76 return NextInSequence->execute(IR);
77 }
78
79 /// Add a listener to receive callbacks during the execution of this stage.
80 void addListener(HWEventListener *Listener);
81
82 /// Notify listeners of a particular hardware event.
83 template <typename EventT> void notifyEvent(const EventT &Event) const {
84 for (HWEventListener *Listener : Listeners)
85 Listener->onEvent(Event);
86 }
87};
88
89/// This is actually not an error but a marker to indicate that
90/// the instruction stream is paused.
91struct InstStreamPause : public ErrorInfo<InstStreamPause> {
92 LLVM_ABI static char ID;
93
94 std::error_code convertToErrorCode() const override {
96 }
97 void log(raw_ostream &OS) const override { OS << "Stream is paused"; }
98};
99} // namespace mca
100} // namespace llvm
101#endif // LLVM_MCA_STAGES_STAGE_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
std::optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1328
This file defines the main interface for hardware event listeners.
Legalize the Machine IR a function s Machine IR
Definition: Legalizer.cpp:80
raw_pwrite_stream & OS
Base class for user error types.
Definition: Error.h:354
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition: Error.h:334
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:725
virtual Error cycleEnd()
Called once at the end of each cycle.
Definition: Stage.h:56
Error moveToTheNextStage(InstRef &IR)
Called when an instruction is ready to move the next pipeline stage.
Definition: Stage.h:74
void notifyEvent(const EventT &Event) const
Notify listeners of a particular hardware event.
Definition: Stage.h:83
bool checkNextStage(const InstRef &IR) const
Definition: Stage.h:66
virtual bool isAvailable(const InstRef &IR) const
Returns true if it can execute IR during this cycle.
Definition: Stage.h:43
virtual ~Stage()
virtual Error cycleStart()
Called once at the start of each cycle.
Definition: Stage.h:50
virtual Error execute(InstRef &IR)=0
The primary action that this stage performs on instruction IR.
const std::set< HWEventListener * > & getListeners() const
Definition: Stage.h:36
virtual bool hasWorkToComplete() const =0
Returns true if some instructions are still executing this stage.
void setNextInSequence(Stage *NextStage)
Definition: Stage.h:61
virtual Error cycleResume()
Called after the pipeline is resumed from pausing state.
Definition: Stage.h:53
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
This is actually not an error but a marker to indicate that the instruction stream is paused.
Definition: Stage.h:91
static LLVM_ABI char ID
Definition: Stage.h:92
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: Stage.h:94
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: Stage.h:97