LLVM 24.0.0git
AMDGPUAddrSpace.h
Go to the documentation of this file.
1//===---------------- AMDGPUAddrSpace.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/// AMDGPU address space definition
11///
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_AMDGPUADDRSPACE_H
16#define LLVM_SUPPORT_AMDGPUADDRSPACE_H
17
18#include <cstdint>
19
20namespace llvm {
21/// OpenCL uses address spaces to differentiate between
22/// various memory regions on the hardware. On the CPU
23/// all of the address spaces point to the same memory,
24/// however on the GPU, each address space points to
25/// a separate piece of memory that is unique from other
26/// memory locations.
27namespace AMDGPUAS {
28enum : unsigned {
30
31 FLAT_ADDRESS = 0, ///< Address space for flat memory.
32 GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
33 REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
34
35 LOCAL_ADDRESS = 3, ///< Address space for local memory.
36 CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
37 PRIVATE_ADDRESS = 5, ///< Address space for private memory.
38
39 CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
40
41 BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
42 ///< Not used in backend.
43
44 BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
45
46 BUFFER_STRIDED_POINTER = 9, ///< Address space for 192-bit fat buffer
47 ///< pointers with an additional index.
48
49 RESERVED_ADDRESS_SPACE_10 = 10, ///< Reserved for downstream use.
50
51 RESERVED_ADDRESS_SPACE_11 = 11, ///< Reserved for downstream use.
52
53 RESERVED_ADDRESS_SPACE_12 = 12, ///< Reserved for downstream use.
54
55 VGPR = 13, ///< Address space for VGPRs. The 32-bit address is a byte offset
56 ///< into the wave's view of its vector registers. Note this shares
57 ///< its numeric value with CONSTANT_BUFFER_5, which is only used
58 ///< by the (graphics) R600 path.
59
60 RESERVED_ADDRESS_SPACE_14 = 14, ///< Reserved for downstream use.
61
62 BARRIER = 15, ///< Address space for modeling barrier IDs as addresses.
63
64 RESERVED_ADDRESS_SPACE_16 = 16, ///< Reserved for downstream use.
65
66 RESERVED_ADDRESS_SPACE_17 = 17, ///< Reserved for downstream use.
67
68 RESERVED_ADDRESS_SPACE_18 = 18, ///< Reserved for downstream use.
69
70 RESERVED_ADDRESS_SPACE_19 = 19, ///< Reserved for downstream use.
71
72 RESERVED_ADDRESS_SPACE_20 = 20, ///< Reserved for downstream use.
73
74 /// Internal address spaces. Can be freely renumbered.
75 STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
76 /// end Internal address spaces.
77
78 /// Address space for direct addressable parameter memory (CONST0).
80 /// Address space for indirect addressable parameter memory (VTX1).
82
83 // Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
84 // this order to be able to dynamically index a constant buffer, for
85 // example:
86 //
87 // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
88
105
106 // Some places use this if the address space can't be determined.
108};
109} // end namespace AMDGPUAS
110
111namespace AMDGPU {
112// Identifies which FLAT address-space segment an instruction operates on.
113// Passed to helpers like isLegalFLATOffset / splitFlatOffset.
114enum class FlatAddrSpace : unsigned { FLAT, FlatGlobal, FlatScratch };
115
116inline bool isReservedAddressSpace(unsigned AS) {
117 switch (AS) {
118 using namespace AMDGPUAS;
119 case RESERVED_ADDRESS_SPACE_10:
120 case RESERVED_ADDRESS_SPACE_11:
121 case RESERVED_ADDRESS_SPACE_12:
122 case RESERVED_ADDRESS_SPACE_14:
123 case RESERVED_ADDRESS_SPACE_16:
124 case RESERVED_ADDRESS_SPACE_17:
125 case RESERVED_ADDRESS_SPACE_18:
126 case RESERVED_ADDRESS_SPACE_19:
127 case RESERVED_ADDRESS_SPACE_20:
128 return true;
129 default:
130 return false;
131 }
132}
133
134inline bool isFlatGlobalAddrSpace(unsigned AS) {
135 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS ||
137}
138
144
145inline bool isConstantAddressSpace(unsigned AS) {
146 switch (AS) {
147 using namespace AMDGPUAS;
148 case CONSTANT_ADDRESS:
149 case CONSTANT_ADDRESS_32BIT:
150 case CONSTANT_BUFFER_0:
151 case CONSTANT_BUFFER_1:
152 case CONSTANT_BUFFER_2:
153 case CONSTANT_BUFFER_3:
154 case CONSTANT_BUFFER_4:
155 case CONSTANT_BUFFER_5:
156 case CONSTANT_BUFFER_6:
157 case CONSTANT_BUFFER_7:
158 case CONSTANT_BUFFER_8:
159 case CONSTANT_BUFFER_9:
160 case CONSTANT_BUFFER_10:
161 case CONSTANT_BUFFER_11:
162 case CONSTANT_BUFFER_12:
163 case CONSTANT_BUFFER_13:
164 case CONSTANT_BUFFER_14:
165 case CONSTANT_BUFFER_15:
166 return true;
167 default:
168 return false;
169 }
170}
171
172namespace DWARFAS {
173enum : unsigned {
177 LOCAL = 3,
181};
182} // namespace DWARFAS
183
184namespace impl {
185// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
186// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
187static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
188 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
189 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
190 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
191 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
192 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
193 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
194};
195} // end namespace impl
196
197/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
198/// return it; otherwise return the sentinel value -1 to indicate
199/// no such mapping exists.
200///
201/// This maps private/scratch to the focused lane view.
202///
203/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.md
204/// table "AMDGPU DWARF Address Space Mapping".
205///
206/// Note: This could return std::optional<int> but that would require
207/// an extra #include.
208constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
209 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
212 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
213 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
214 return -1;
215}
216
217/// Get the null pointer value for the given address space.
218constexpr int64_t getNullPointerValue(unsigned AS) {
219 switch (AS) {
220 using namespace AMDGPUAS;
221 case PRIVATE_ADDRESS:
222 case LOCAL_ADDRESS:
223 case REGION_ADDRESS:
224 case VGPR:
225 return -1;
226 default:
227 return 0;
228 }
229}
230} // end namespace AMDGPU
231
232} // end namespace llvm
233
234#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H
OpenCL uses address spaces to differentiate between various memory regions on the hardware.
@ RESERVED_ADDRESS_SPACE_17
Reserved for downstream use.
@ RESERVED_ADDRESS_SPACE_20
Reserved for downstream use.
@ RESERVED_ADDRESS_SPACE_11
Reserved for downstream use.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ BUFFER_STRIDED_POINTER
Address space for 192-bit fat buffer pointers with an additional index.
@ RESERVED_ADDRESS_SPACE_10
Reserved for downstream use.
@ BARRIER
Address space for modeling barrier IDs as addresses.
@ RESERVED_ADDRESS_SPACE_16
Reserved for downstream use.
@ PARAM_D_ADDRESS
end Internal address spaces.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ RESERVED_ADDRESS_SPACE_18
Reserved for downstream use.
@ LOCAL_ADDRESS
Address space for local memory.
@ STREAMOUT_REGISTER
Internal address spaces. Can be freely renumbered.
@ VGPR
Address space for VGPRs.
@ RESERVED_ADDRESS_SPACE_12
Reserved for downstream use.
@ PARAM_I_ADDRESS
Address space for indirect addressable parameter memory (VTX1).
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ RESERVED_ADDRESS_SPACE_14
Reserved for downstream use.
@ RESERVED_ADDRESS_SPACE_19
Reserved for downstream use.
@ BUFFER_FAT_POINTER
Address space for 160-bit buffer fat pointers.
@ PRIVATE_ADDRESS
Address space for private memory.
@ BUFFER_RESOURCE
Address space for 128-bit buffer resources.
static constexpr unsigned LLVMToDWARFAddrSpaceMapping[]
bool isFlatGlobalAddrSpace(unsigned AS)
bool isReservedAddressSpace(unsigned AS)
constexpr int64_t getNullPointerValue(unsigned AS)
Get the null pointer value for the given address space.
constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace)
If LLVMAddressSpace has a corresponding DWARF encoding, return it; otherwise return the sentinel valu...
bool isExtendedGlobalAddrSpace(unsigned AS)
bool isConstantAddressSpace(unsigned AS)
This is an optimization pass for GlobalISel generic memory operations.