LLVM 24.0.0git
AMDGPUAsyncStages.h
Go to the documentation of this file.
1//===- AMDGPUAsyncStages.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/// \file
10/// Shared AMDGPU asyncmark stage definitions.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_SUPPORT_AMDGPUASYNCSTAGES_H
15#define LLVM_SUPPORT_AMDGPUASYNCSTAGES_H
16
18#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/Sequence.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/bit.h"
24#include <cassert>
25#include <cstdint>
26
27namespace llvm::AMDGPU {
28
30
31/// Bit mask of the async stages tracked by the asyncmark / wait_asyncmark
32/// intrinsics. Each stage has its own independent sequence of marks. A single
33/// stage is a mask with exactly one bit set.
34///
35/// The bit of each stage is part of the IR, so do not renumber them. Some
36/// values are RESERVED for later use.
37enum class AsyncStages : uint32_t {
38 NONE = 0,
39 // Tensor loads to LDS and tensor stores from LDS.
40 TENSOR = 1u << 0,
41 // Asynchronous global loads to LDS.
43 // Asynchronous multicast (cluster) global loads to LDS.
45 // Asynchronous global stores from LDS.
47 // Held for downstream use.
48 RESERVED_4 = 1u << 4,
49 // Buffer loads to LDS and pre-gfx1250 global loads to LDS.
51 RESERVED_6 = 1u << 6,
52 RESERVED_7 = 1u << 7,
53 RESERVED_8 = 1u << 8,
54 RESERVED_9 = 1u << 9,
55 RESERVED_10 = 1u << 10,
56
59
60 // Bits that a mask may legally set. Reserved stages are included: naming a
61 // stage whose operations do not exist yet is harmless, and accepting the bit
62 // keeps masks portable as stages are filled in.
63 ALL = (1u << 11) - 1,
64
66};
67
68/// The number of stages, which is also the number of bits in a stage mask.
69inline constexpr unsigned NumAsyncStages = BitWidth<AsyncStages>;
70
71/// The name of each stage, indexed by the position of its bit.
73 "TENSOR",
74 "GLOBAL_LOAD_ASYNC_TO_LDS",
75 "GLOBAL_LOAD_ASYNC_TO_LDS_MCAST",
76 "GLOBAL_STORE_ASYNC_FROM_LDS",
77 "RESERVED_4",
78 "BUFFER_GLOBAL_LOAD",
79 "RESERVED_6",
80 "RESERVED_7",
81 "RESERVED_8",
82 "RESERVED_9",
83 "RESERVED_10",
84};
85
86/// \returns true if \p Mask is a legal stage mask operand of the asyncmark /
87/// wait_asyncmark intrinsics and pseudos.
88constexpr bool isValidAsyncStageMask(int64_t Mask) {
89 return Mask >= 0 && (Mask & ~int64_t(to_underlying(AsyncStages::ALL))) == 0;
90}
91
92/// \returns the stages named by the stage mask operand \p Mask of the
93/// asyncmark / wait_asyncmark intrinsics and pseudos. The zero mask is the one
94/// exception to a set bit naming a stage: it names every stage rather than
95/// none.
96constexpr AsyncStages asyncStagesFromMaskOperand(int64_t Mask) {
97 assert(isValidAsyncStageMask(Mask) && "Invalid async stage mask");
98 return Mask ? static_cast<AsyncStages>(Mask) : AsyncStages::ALL;
99}
100
101/// \returns the single stages named by \p Mask, from the least significant bit
102/// up.
103inline auto asyncStages(AsyncStages Mask) {
104 return make_filter_range(
106 [](unsigned I) { return static_cast<AsyncStages>(1u << I); }),
107 [Mask](AsyncStages Stage) { return any(Mask & Stage); });
108}
109
110/// \returns the position of the bit of the single stage \p Stage, for indexing
111/// per-stage data.
112inline unsigned getAsyncStageIndex(AsyncStages Stage) {
113 assert(has_single_bit(to_underlying(Stage)) && "Expected a single stage");
114 return countr_zero(to_underlying(Stage));
115}
116
117/// \returns the name of the single stage \p Stage.
121
122/// Print the stages named by \p Mask as a '|'-separated list, or "all" if it
123/// names every stage.
125 if (Mask == AsyncStages::ALL)
126 return OS << "all";
127 if (Mask == AsyncStages::NONE)
128 return OS << "none";
130 asyncStages(Mask), OS,
131 [&OS](AsyncStages Stage) { OS << getAsyncStageName(Stage); }, "|");
132 return OS;
133}
134
135} // namespace llvm::AMDGPU
136
137#endif // LLVM_SUPPORT_AMDGPUASYNCSTAGES_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains some templates that are useful if you are working with the STL at all.
This file contains library features backported from future STL versions.
Provides some synthesis utilities to produce sequences of values.
This file implements the C++20 <bit> header.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:888
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
StringRef getAsyncStageName(AsyncStages Stage)
constexpr AsyncStages asyncStagesFromMaskOperand(int64_t Mask)
constexpr bool isValidAsyncStageMask(int64_t Mask)
AsyncStages
Bit mask of the async stages tracked by the asyncmark / wait_asyncmark intrinsics.
raw_ostream & operator<<(raw_ostream &OS, AsyncStages Mask)
Print the stages named by Mask as a '|'-separated list, or "all" if it names every stage.
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE()
constexpr StringLiteral AsyncStageNames[NumAsyncStages]
The name of each stage, indexed by the position of its bit.
auto asyncStages(AsyncStages Mask)
unsigned getAsyncStageIndex(AsyncStages Stage)
constexpr unsigned NumAsyncStages
The number of stages, which is also the number of bits in a stage mask.
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
Definition STLExtras.h:2291
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
Definition STLExtras.h:366
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition bit.h:204
constexpr bool has_single_bit(T Value) noexcept
Definition bit.h:149
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
constexpr unsigned BitWidth
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:341