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