[llvm] [RFC][AMDGPU][InsertWaitCnt] Move WaitEventType into separate HWEvent header (PR #202886)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 10 09:35:52 PDT 2026
================
@@ -0,0 +1,120 @@
+//===- AMDGPUHWEvents.h -----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUHWEVENTS_H
+#define LLVM_LIB_TARGET_AMDGPU_UTILS_AMDGPUHWEVENTS_H
+
+#include "llvm/ADT/Sequence.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace llvm {
+class raw_ostream;
+
+namespace AMDGPU {
+
+enum class HWEvent : unsigned char {
+#define AMDGPU_HW_EVENT(X) X,
+#define AMDGPU_FIRST_HW_EVENT(X) FIRST_WAIT_EVENT = X,
+#define AMDGPU_LAST_HW_EVENT(X) NUM_WAIT_EVENTS = X,
+#include "AMDGPUHWEvents.def"
+};
+
+} // namespace AMDGPU
+
+template <> struct enum_iteration_traits<AMDGPU::HWEvent> {
+ static constexpr bool is_iterable = true; // NOLINT
+};
+
+namespace AMDGPU {
+
+static constexpr StringLiteral toString(HWEvent Event) {
+ switch (Event) {
+#define AMDGPU_HW_EVENT(EVENT) \
+ case HWEvent::EVENT: \
+ return #EVENT;
+#include "AMDGPUHWEvents.def"
+ }
+
+ return "";
+}
+
+/// Return an iterator over all events between FIRST_WAIT_EVENT
+/// and \c MaxEvent (exclusive, default value yields an enumeration over
+/// all counters).
+// NOLINTNEXTLINE
+inline iota_range<HWEvent>
+hw_events(HWEvent MaxEvent = HWEvent::NUM_WAIT_EVENTS) {
+ return enum_seq(HWEvent::FIRST_WAIT_EVENT, MaxEvent);
+}
+
+class HWEventSet {
----------------
ssahasra wrote:
I don't fully understand the C++ implications here. Why would that macro be bad? It only pulls into the _current_ namespace. So maybe we can use it inside an `enum class`, or just this outer container class that we already have? It should be okay to inject things into a header like this. They are things that we _want_ to expose to uses of the type that we just declared.
https://github.com/llvm/llvm-project/pull/202886
More information about the llvm-commits
mailing list