LLVM 23.0.0git
AMDGPUHWEvents.h
Go to the documentation of this file.
1//===- AMDGPUHWEvents.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
9#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUHWEVENTS_H
10#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUHWEVENTS_H
11
12#include "llvm/ADT/Sequence.h"
13#include "llvm/ADT/StringRef.h"
14
15namespace llvm {
16class GCNSubtarget;
17class MachineInstr;
18class raw_ostream;
19
20namespace AMDGPU {
21
22/// TODO: This should be a bitmask from the start instead of having this enum
23/// + \ref HWEventSet below.
24enum class HWEvent : unsigned char {
25#define AMDGPU_HW_EVENT(X) X,
26#define AMDGPU_FIRST_HW_EVENT(X) FIRST_WAIT_EVENT = X,
27#define AMDGPU_LAST_HW_EVENT(X) NUM_WAIT_EVENTS = X,
28#include "AMDGPUHWEvents.def"
29};
30
31} // namespace AMDGPU
32
33template <> struct enum_iteration_traits<AMDGPU::HWEvent> {
34 static constexpr bool is_iterable = true; // NOLINT
35};
36
37namespace AMDGPU {
38
39static constexpr StringLiteral toString(HWEvent Event) {
40 switch (Event) {
41#define AMDGPU_HW_EVENT(EVENT) \
42 case HWEvent::EVENT: \
43 return #EVENT;
44#include "AMDGPUHWEvents.def"
45 }
46
47 return "";
48}
49
50/// Return an iterator over all events between FIRST_WAIT_EVENT
51/// and \c MaxEvent (exclusive, default value yields an enumeration over
52/// all counters).
53// NOLINTNEXTLINE
55hw_events(HWEvent MaxEvent = HWEvent::NUM_WAIT_EVENTS) {
56 return enum_seq(HWEvent::FIRST_WAIT_EVENT, MaxEvent);
57}
58
60 unsigned Mask = 0;
61
62public:
63 HWEventSet() = default;
64 constexpr HWEventSet(HWEvent Event) {
65 static_assert(static_cast<unsigned>(HWEvent::NUM_WAIT_EVENTS) <=
66 sizeof(Mask) * 8,
67 "Not enough bits in Mask for all the events");
68 Mask |= 1 << static_cast<unsigned>(Event);
69 }
70 constexpr HWEventSet(std::initializer_list<HWEvent> Events) {
71 for (auto &E : Events) {
72 Mask |= 1 << static_cast<unsigned>(E);
73 }
74 }
75 void insert(const HWEvent &Event) {
76 Mask |= 1 << static_cast<unsigned>(Event);
77 }
78 void remove(const HWEvent &Event) {
79 Mask &= ~(1 << static_cast<unsigned>(Event));
80 }
81 void remove(const HWEventSet &Other) { Mask &= ~Other.Mask; }
82 bool contains(const HWEvent &Event) const {
83 return Mask & (1 << static_cast<unsigned>(Event));
84 }
85 /// \returns true if this set contains all elements of \p Other.
86 bool contains(const HWEventSet &Other) const {
87 return (~Mask & Other.Mask) == 0;
88 }
89 /// \returns the intersection of this and \p Other.
91 auto Copy = *this;
92 Copy.Mask &= Other.Mask;
93 return Copy;
94 }
95 /// \returns the union of this and \p Other.
97 auto Copy = *this;
98 Copy.Mask |= Other.Mask;
99 return Copy;
100 }
101 /// This set becomes the union of this and \p Other.
103 Mask |= Other.Mask;
104 return *this;
105 }
106 /// This set becomes the intersection of this and \p Other.
108 Mask &= Other.Mask;
109 return *this;
110 }
111 bool operator==(const HWEventSet &Other) const { return Mask == Other.Mask; }
112 bool operator!=(const HWEventSet &Other) const { return !(*this == Other); }
113 bool empty() const { return Mask == 0; }
114 /// \returns true if the set contains more than one element.
115 bool twoOrMore() const { return Mask & (Mask - 1); }
116 operator bool() const { return !empty(); }
117 void print(raw_ostream &OS) const;
118 LLVM_DUMP_METHOD void dump() const;
119};
120
121/// \returns all HWEvents triggered by \p Inst
122HWEventSet getEventsFor(const MachineInstr &Inst, const GCNSubtarget &ST,
123 bool IsExpertMode);
124
125} // namespace AMDGPU
126} // namespace llvm
127
128#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:661
AMDGPU::HWEventSet HWEventSet
AMDGPU::HWEvent HWEvent
Provides some synthesis utilities to produce sequences of values.
void remove(const HWEvent &Event)
constexpr HWEventSet(std::initializer_list< HWEvent > Events)
bool contains(const HWEventSet &Other) const
HWEventSet operator&(const HWEventSet &Other) const
LLVM_DUMP_METHOD void dump() const
HWEventSet operator|(const HWEventSet &Other) const
void remove(const HWEventSet &Other)
HWEventSet & operator|=(const HWEventSet &Other)
This set becomes the union of this and Other.
bool operator==(const HWEventSet &Other) const
constexpr HWEventSet(HWEvent Event)
void print(raw_ostream &OS) const
bool operator!=(const HWEventSet &Other) const
bool contains(const HWEvent &Event) const
HWEventSet & operator&=(const HWEventSet &Other)
This set becomes the intersection of this and Other.
void insert(const HWEvent &Event)
Representation of each machine instruction.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:882
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
HWEventSet getEventsFor(const MachineInstr &Inst, const GCNSubtarget &ST, bool IsExpertMode)
static constexpr StringLiteral toString(HWEvent Event)
HWEvent
TODO: This should be a bitmask from the start instead of having this enum.
iota_range< HWEvent > hw_events(HWEvent MaxEvent=HWEvent::NUM_WAIT_EVENTS)
Return an iterator over all events between FIRST_WAIT_EVENT and MaxEvent (exclusive,...
This is an optimization pass for GlobalISel generic memory operations.
auto enum_seq(EnumT Begin, EnumT End)
Iterate over an enum type from Begin up to - but not including - End.
Definition Sequence.h:337