LLVM 23.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_16 = 16, ///< Reserved for downstream use.
51
52 /// Internal address spaces. Can be freely renumbered.
53 STREAMOUT_REGISTER = 128, ///< Address space for GS NGG Streamout registers.
54 /// end Internal address spaces.
55
56 /// Address space for direct addressable parameter memory (CONST0).
58 /// Address space for indirect addressable parameter memory (VTX1).
60
61 // Do not re-order the CONSTANT_BUFFER_* enums. Several places depend on
62 // this order to be able to dynamically index a constant buffer, for
63 // example:
64 //
65 // ConstantBufferAS = CONSTANT_BUFFER_0 + CBIdx
66
83
84 // Some places use this if the address space can't be determined.
86};
87} // end namespace AMDGPUAS
88
89namespace AMDGPU {
94
100
101inline bool isConstantAddressSpace(unsigned AS) {
102 switch (AS) {
103 using namespace AMDGPUAS;
104 case CONSTANT_ADDRESS:
105 case CONSTANT_ADDRESS_32BIT:
106 case CONSTANT_BUFFER_0:
107 case CONSTANT_BUFFER_1:
108 case CONSTANT_BUFFER_2:
109 case CONSTANT_BUFFER_3:
110 case CONSTANT_BUFFER_4:
111 case CONSTANT_BUFFER_5:
112 case CONSTANT_BUFFER_6:
113 case CONSTANT_BUFFER_7:
114 case CONSTANT_BUFFER_8:
115 case CONSTANT_BUFFER_9:
116 case CONSTANT_BUFFER_10:
117 case CONSTANT_BUFFER_11:
118 case CONSTANT_BUFFER_12:
119 case CONSTANT_BUFFER_13:
120 case CONSTANT_BUFFER_14:
121 case CONSTANT_BUFFER_15:
122 return true;
123 default:
124 return false;
125 }
126}
127
128namespace DWARFAS {
129enum : unsigned {
133 LOCAL = 3,
137};
138} // namespace DWARFAS
139
140namespace impl {
141// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
142// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
143static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
144 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
145 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
146 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
147 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
148 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
149 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
150};
151} // end namespace impl
152
153/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
154/// return it; otherwise return the sentinel value -1 to indicate
155/// no such mapping exists.
156///
157/// This maps private/scratch to the focused lane view.
158///
159/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.rst
160/// table "AMDGPU DWARF Address Space Mapping".
161///
162/// Note: This could return std::optional<int> but that would require
163/// an extra #include.
164constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
165 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
168 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
169 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
170 return -1;
171}
172
173/// Get the null pointer value for the given address space.
174constexpr int64_t getNullPointerValue(unsigned AS) {
175 switch (AS) {
176 using namespace AMDGPUAS;
177 case PRIVATE_ADDRESS:
178 case LOCAL_ADDRESS:
179 case REGION_ADDRESS:
180 return -1;
181 default:
182 return 0;
183 }
184}
185} // end namespace AMDGPU
186
187} // end namespace llvm
188
189#endif // LLVM_SUPPORT_AMDGPUADDRSPACE_H
OpenCL uses address spaces to differentiate between various memory regions on the hardware.
@ 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_16
Reserved for downstream use.
@ PARAM_D_ADDRESS
end Internal address spaces.
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ 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).
@ 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.