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 {
29 // The maximum value for flat, generic, local, private, constant and region.
31
32 FLAT_ADDRESS = 0, ///< Address space for flat memory.
33 GLOBAL_ADDRESS = 1, ///< Address space for global memory (RAT0, VTX0).
34 REGION_ADDRESS = 2, ///< Address space for region memory. (GDS)
35
36 LOCAL_ADDRESS = 3, ///< Address space for local memory.
37 CONSTANT_ADDRESS = 4, ///< Address space for constant memory (VTX2).
38 PRIVATE_ADDRESS = 5, ///< Address space for private memory.
39
40 CONSTANT_ADDRESS_32BIT = 6, ///< Address space for 32-bit constant memory.
41
42 BUFFER_FAT_POINTER = 7, ///< Address space for 160-bit buffer fat pointers.
43 ///< Not used in backend.
44
45 BUFFER_RESOURCE = 8, ///< Address space for 128-bit buffer resources.
46
47 BUFFER_STRIDED_POINTER = 9, ///< Address space for 192-bit fat buffer
48 ///< pointers with an additional index.
49
50 RESERVED_ADDRESS_SPACE_10 = 10, ///< Reserved for downstream use.
51
52 RESERVED_ADDRESS_SPACE_11 = 11, ///< Reserved for downstream use.
53
54 RESERVED_ADDRESS_SPACE_13 = 13, ///< Reserved for downstream use.
55
56 RESERVED_ADDRESS_SPACE_14 = 14, ///< Reserved for downstream use.
57
58 RESERVED_ADDRESS_SPACE_16 = 16, ///< Reserved for downstream use.
59
60 RESERVED_ADDRESS_SPACE_17 = 17, ///< Reserved for downstream use.
61
62 RESERVED_ADDRESS_SPACE_18 = 18, ///< Reserved for downstream use.
63
64 /// Internal address spaces. Can be freely renumbered.
65 STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
66 /// end Internal address spaces.
67
68 /// Address space for direct addressable parameter memory (CONST0).
70 /// Address space for indirect addressable parameter memory (VTX1).
72
73 // Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
74 // this order to be able to dynamically index a constant buffer, for
75 // example:
76 //
77 // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
78
95
96 // Some places use this if the address space can't be determined.
98};
99} // end namespace AMDGPUAS
100
101namespace AMDGPU {
102// Identifies which FLAT address-space segment an instruction operates on.
103// Passed to helpers like isLegalFLATOffset / splitFlatOffset.
104enum class FlatAddrSpace : unsigned { FLAT, FlatGlobal, FlatScratch };
105
106inline bool isFlatGlobalAddrSpace(unsigned AS) {
107 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS ||
109}
110
116
117inline bool isConstantAddressSpace(unsigned AS) {
118 switch (AS) {
119 using namespace AMDGPUAS;
120 case CONSTANT_ADDRESS:
121 case CONSTANT_ADDRESS_32BIT:
122 case CONSTANT_BUFFER_0:
123 case CONSTANT_BUFFER_1:
124 case CONSTANT_BUFFER_2:
125 case CONSTANT_BUFFER_3:
126 case CONSTANT_BUFFER_4:
127 case CONSTANT_BUFFER_5:
128 case CONSTANT_BUFFER_6:
129 case CONSTANT_BUFFER_7:
130 case CONSTANT_BUFFER_8:
131 case CONSTANT_BUFFER_9:
132 case CONSTANT_BUFFER_10:
133 case CONSTANT_BUFFER_11:
134 case CONSTANT_BUFFER_12:
135 case CONSTANT_BUFFER_13:
136 case CONSTANT_BUFFER_14:
137 case CONSTANT_BUFFER_15:
138 return true;
139 default:
140 return false;
141 }
142}
143
144namespace DWARFAS {
145enum : unsigned {
149 LOCAL = 3,
153};
154} // namespace DWARFAS
155
156namespace impl {
157// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
158// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
159static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
160 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
161 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
162 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
163 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
164 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
165 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
166};
167} // end namespace impl
168
169/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
170/// return it; otherwise return the sentinel value -1 to indicate
171/// no such mapping exists.
172///
173/// This maps private/scratch to the focused lane view.
174///
175/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.rst
176/// table "AMDGPU DWARF Address Space Mapping".
177///
178/// Note: This could return std::optional<int> but that would require
179/// an extra #include.
180constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
181 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
184 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
185 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
186 return -1;
187}
188
189/// Get the null pointer value for the given address space.
190constexpr int64_t getNullPointerValue(unsigned AS) {
191 switch (AS) {
192 using namespace AMDGPUAS;
193 case PRIVATE_ADDRESS:
194 case LOCAL_ADDRESS:
195 case REGION_ADDRESS:
196 return -1;
197 default:
198 return 0;
199 }
200}
201} // end namespace AMDGPU
202
203} // end namespace llvm
204
205#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_11
Reserved for downstream use.
@ CONSTANT_ADDRESS_32BIT
Address space for 32-bit constant memory.
@ RESERVED_ADDRESS_SPACE_13
Reserved for downstream use.
@ BUFFER_STRIDED_POINTER
Address space for 192-bit fat buffer pointers with an additional index.
@ RESERVED_ADDRESS_SPACE_10
Reserved for downstream use.
@ 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.
@ 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.
@ 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.