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 /// Internal address spaces. Can be freely renumbered.
69 STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
70 /// end Internal address spaces.
71
72 /// Address space for direct addressable parameter memory (CONST0).
74 /// Address space for indirect addressable parameter memory (VTX1).
76
77 // Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
78 // this order to be able to dynamically index a constant buffer, for
79 // example:
80 //
81 // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
82
99
100 // Some places use this if the address space can't be determined.
102};
103} // end namespace AMDGPUAS
104
105namespace AMDGPU {
106// Identifies which FLAT address-space segment an instruction operates on.
107// Passed to helpers like isLegalFLATOffset / splitFlatOffset.
108enum class FlatAddrSpace : unsigned { FLAT, FlatGlobal, FlatScratch };
109
110inline bool isFlatGlobalAddrSpace(unsigned AS) {
111 return AS == AMDGPUAS::GLOBAL_ADDRESS || AS == AMDGPUAS::FLAT_ADDRESS ||
113}
114
120
121inline bool isConstantAddressSpace(unsigned AS) {
122 switch (AS) {
123 using namespace AMDGPUAS;
124 case CONSTANT_ADDRESS:
125 case CONSTANT_ADDRESS_32BIT:
126 case CONSTANT_BUFFER_0:
127 case CONSTANT_BUFFER_1:
128 case CONSTANT_BUFFER_2:
129 case CONSTANT_BUFFER_3:
130 case CONSTANT_BUFFER_4:
131 case CONSTANT_BUFFER_5:
132 case CONSTANT_BUFFER_6:
133 case CONSTANT_BUFFER_7:
134 case CONSTANT_BUFFER_8:
135 case CONSTANT_BUFFER_9:
136 case CONSTANT_BUFFER_10:
137 case CONSTANT_BUFFER_11:
138 case CONSTANT_BUFFER_12:
139 case CONSTANT_BUFFER_13:
140 case CONSTANT_BUFFER_14:
141 case CONSTANT_BUFFER_15:
142 return true;
143 default:
144 return false;
145 }
146}
147
148namespace DWARFAS {
149enum : unsigned {
153 LOCAL = 3,
157};
158} // namespace DWARFAS
159
160namespace impl {
161// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
162// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
163static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
164 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
165 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
166 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
167 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
168 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
169 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
170};
171} // end namespace impl
172
173/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
174/// return it; otherwise return the sentinel value -1 to indicate
175/// no such mapping exists.
176///
177/// This maps private/scratch to the focused lane view.
178///
179/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.rst
180/// table "AMDGPU DWARF Address Space Mapping".
181///
182/// Note: This could return std::optional<int> but that would require
183/// an extra #include.
184constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
185 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
188 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
189 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
190 return -1;
191}
192
193/// Get the null pointer value for the given address space.
194constexpr int64_t getNullPointerValue(unsigned AS) {
195 switch (AS) {
196 using namespace AMDGPUAS;
197 case PRIVATE_ADDRESS:
198 case LOCAL_ADDRESS:
199 case REGION_ADDRESS:
200 case VGPR:
201 return -1;
202 default:
203 return 0;
204 }
205}
206} // end namespace AMDGPU
207
208} // end namespace llvm
209
210#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.
@ 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.
@ 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.