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 VGPR = 13, ///< Address space for VGPRs. The 32-bit address is a byte offset
54 ///< into the wave's view of its vector registers. Note this shares
55 ///< its numeric value with CONSTANT_BUFFER_5, which is only used
56 ///< by the (graphics) R600 path.
57
58 RESERVED_ADDRESS_SPACE_14 = 14, ///< Reserved for downstream use.
59
60 BARRIER = 15, ///< Address space for modeling barrier IDs as addresses.
61
62 RESERVED_ADDRESS_SPACE_16 = 16, ///< Reserved for downstream use.
63
64 RESERVED_ADDRESS_SPACE_17 = 17, ///< Reserved for downstream use.
65
66 RESERVED_ADDRESS_SPACE_18 = 18, ///< Reserved for downstream use.
67
68 RESERVED_ADDRESS_SPACE_19 = 19, ///< Reserved for downstream use.
69
70 RESERVED_ADDRESS_SPACE_20 = 20, ///< Reserved for downstream use.
71
72 /// Internal address spaces. Can be freely renumbered.
73 STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
74 /// end Internal address spaces.
75
76 /// Address space for direct addressable parameter memory (CONST0).
78 /// Address space for indirect addressable parameter memory (VTX1).
80
81 // Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
82 // this order to be able to dynamically index a constant buffer, for
83 // example:
84 //
85 // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
86
103
104 // Some places use this if the address space can't be determined.
106};
107} // end namespace AMDGPUAS
108
109namespace AMDGPU {
110// Identifies which FLAT address-space segment an instruction operates on.
111// Passed to helpers like isLegalFLATOffset / splitFlatOffset.
112enum class FlatAddrSpace : unsigned { FLAT, FlatGlobal, FlatScratch };
113
114inline bool isFlatGlobalAddrSpace(unsigned AS) {
115 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS ||
117}
118
124
125inline bool isConstantAddressSpace(unsigned AS) {
126 switch (AS) {
127 using namespace AMDGPUAS;
128 case CONSTANT_ADDRESS:
129 case CONSTANT_ADDRESS_32BIT:
130 case CONSTANT_BUFFER_0:
131 case CONSTANT_BUFFER_1:
132 case CONSTANT_BUFFER_2:
133 case CONSTANT_BUFFER_3:
134 case CONSTANT_BUFFER_4:
135 case CONSTANT_BUFFER_5:
136 case CONSTANT_BUFFER_6:
137 case CONSTANT_BUFFER_7:
138 case CONSTANT_BUFFER_8:
139 case CONSTANT_BUFFER_9:
140 case CONSTANT_BUFFER_10:
141 case CONSTANT_BUFFER_11:
142 case CONSTANT_BUFFER_12:
143 case CONSTANT_BUFFER_13:
144 case CONSTANT_BUFFER_14:
145 case CONSTANT_BUFFER_15:
146 return true;
147 default:
148 return false;
149 }
150}
151
152namespace DWARFAS {
153enum : unsigned {
157 LOCAL = 3,
161};
162} // namespace DWARFAS
163
164namespace impl {
165// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
166// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
167static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
168 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
169 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
170 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
171 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
172 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
173 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
174};
175} // end namespace impl
176
177/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
178/// return it; otherwise return the sentinel value -1 to indicate
179/// no such mapping exists.
180///
181/// This maps private/scratch to the focused lane view.
182///
183/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.rst
184/// table "AMDGPU DWARF Address Space Mapping".
185///
186/// Note: This could return std::optional<int> but that would require
187/// an extra #include.
188constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
189 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
192 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
193 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
194 return -1;
195}
196
197/// Get the null pointer value for the given address space.
198constexpr int64_t getNullPointerValue(unsigned AS) {
199 switch (AS) {
200 using namespace AMDGPUAS;
201 case PRIVATE_ADDRESS:
202 case LOCAL_ADDRESS:
203 case REGION_ADDRESS:
204 case VGPR:
205 return -1;
206 default:
207 return 0;
208 }
209}
210} // end namespace AMDGPU
211
212} // end namespace llvm
213
214#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.
@ 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)
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.