File indexing completed on 2026-05-10 08:44:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_MCA_HWEVENTLISTENER_H
0015 #define LLVM_MCA_HWEVENTLISTENER_H
0016
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/MCA/Instruction.h"
0019 #include "llvm/MCA/Support.h"
0020
0021 namespace llvm {
0022 namespace mca {
0023
0024
0025
0026
0027 class HWInstructionEvent {
0028 public:
0029
0030
0031
0032
0033
0034
0035
0036
0037 enum GenericEventType {
0038 Invalid = 0,
0039
0040 Retired,
0041
0042 Pending,
0043 Ready,
0044 Issued,
0045 Executed,
0046
0047 Dispatched,
0048
0049 LastGenericEventType,
0050 };
0051
0052 HWInstructionEvent(unsigned type, const InstRef &Inst)
0053 : Type(type), IR(Inst) {}
0054
0055
0056 const unsigned Type;
0057
0058
0059 const InstRef &IR;
0060 };
0061
0062
0063
0064 using ResourceRef = std::pair<uint64_t, uint64_t>;
0065
0066 using ResourceUse = std::pair<ResourceRef, ReleaseAtCycles>;
0067
0068 class HWInstructionIssuedEvent : public HWInstructionEvent {
0069 public:
0070 HWInstructionIssuedEvent(const InstRef &IR, ArrayRef<ResourceUse> UR)
0071 : HWInstructionEvent(HWInstructionEvent::Issued, IR), UsedResources(UR) {}
0072
0073 ArrayRef<ResourceUse> UsedResources;
0074 };
0075
0076 class HWInstructionDispatchedEvent : public HWInstructionEvent {
0077 public:
0078 HWInstructionDispatchedEvent(const InstRef &IR, ArrayRef<unsigned> Regs,
0079 unsigned UOps)
0080 : HWInstructionEvent(HWInstructionEvent::Dispatched, IR),
0081 UsedPhysRegs(Regs), MicroOpcodes(UOps) {}
0082
0083
0084 ArrayRef<unsigned> UsedPhysRegs;
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 unsigned MicroOpcodes;
0095 };
0096
0097 class HWInstructionRetiredEvent : public HWInstructionEvent {
0098 public:
0099 HWInstructionRetiredEvent(const InstRef &IR, ArrayRef<unsigned> Regs)
0100 : HWInstructionEvent(HWInstructionEvent::Retired, IR),
0101 FreedPhysRegs(Regs) {}
0102
0103
0104 ArrayRef<unsigned> FreedPhysRegs;
0105 };
0106
0107
0108
0109 class HWStallEvent {
0110 public:
0111 enum GenericEventType {
0112 Invalid = 0,
0113
0114 RegisterFileStall,
0115 RetireControlUnitStall,
0116
0117 DispatchGroupStall,
0118 SchedulerQueueFull,
0119 LoadQueueFull,
0120 StoreQueueFull,
0121 CustomBehaviourStall,
0122 LastGenericEvent
0123 };
0124
0125 HWStallEvent(unsigned type, const InstRef &Inst) : Type(type), IR(Inst) {}
0126
0127
0128 const unsigned Type;
0129
0130
0131 const InstRef &IR;
0132 };
0133
0134
0135
0136 class HWPressureEvent {
0137 public:
0138 enum GenericReason {
0139 INVALID = 0,
0140
0141
0142 RESOURCES,
0143
0144 REGISTER_DEPS,
0145
0146 MEMORY_DEPS
0147 };
0148
0149 HWPressureEvent(GenericReason reason, ArrayRef<InstRef> Insts,
0150 uint64_t Mask = 0)
0151 : Reason(reason), AffectedInstructions(Insts), ResourceMask(Mask) {}
0152
0153
0154 GenericReason Reason;
0155
0156
0157 ArrayRef<InstRef> AffectedInstructions;
0158
0159
0160 const uint64_t ResourceMask;
0161 };
0162
0163 class HWEventListener {
0164 public:
0165
0166 virtual void onCycleBegin() {}
0167 virtual void onCycleEnd() {}
0168
0169 virtual void onEvent(const HWInstructionEvent &Event) {}
0170 virtual void onEvent(const HWStallEvent &Event) {}
0171 virtual void onEvent(const HWPressureEvent &Event) {}
0172
0173 virtual void onResourceAvailable(const ResourceRef &RRef) {}
0174
0175
0176
0177 virtual void onReservedBuffers(const InstRef &Inst,
0178 ArrayRef<unsigned> Buffers) {}
0179 virtual void onReleasedBuffers(const InstRef &Inst,
0180 ArrayRef<unsigned> Buffers) {}
0181
0182 virtual ~HWEventListener() = default;
0183
0184 private:
0185 virtual void anchor();
0186 };
0187 }
0188 }
0189
0190 #endif