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 {
90// Identifies which FLAT address-space segment an instruction operates on.
91// Passed to helpers like isLegalFLATOffset / splitFlatOffset.
92enum class FlatAddrSpace : unsigned { FLAT, FlatGlobal, FlatScratch };
93
98
104
105inline bool isConstantAddressSpace(unsigned AS) {
106 switch (AS) {
107 using namespace AMDGPUAS;
108 case CONSTANT_ADDRESS:
109 case CONSTANT_ADDRESS_32BIT:
110 case CONSTANT_BUFFER_0:
111 case CONSTANT_BUFFER_1:
112 case CONSTANT_BUFFER_2:
113 case CONSTANT_BUFFER_3:
114 case CONSTANT_BUFFER_4:
115 case CONSTANT_BUFFER_5:
116 case CONSTANT_BUFFER_6:
117 case CONSTANT_BUFFER_7:
118 case CONSTANT_BUFFER_8:
119 case CONSTANT_BUFFER_9:
120 case CONSTANT_BUFFER_10:
121 case CONSTANT_BUFFER_11:
122 case CONSTANT_BUFFER_12:
123 case CONSTANT_BUFFER_13:
124 case CONSTANT_BUFFER_14:
125 case CONSTANT_BUFFER_15:
126 return true;
127 default:
128 return false;
129 }
130}
131
132namespace DWARFAS {
133enum : unsigned {
137 LOCAL = 3,
141};
142} // namespace DWARFAS
143
144namespace impl {
145// TODO: Move this into mapToDWARFAddrSpace when we switch to C++23
146// (see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2647r1.html)
147static constexpr unsigned LLVMToDWARFAddrSpaceMapping[] = {
148 DWARFAS::GENERIC, //< AMDGPUAS::FLAT_ADDRESS
149 DWARFAS::GLOBAL, //< AMDGPUAS::GLOBAL_ADDRESS
150 DWARFAS::REGION, //< AMDGPUAS::REGION_ADDRESS
151 DWARFAS::LOCAL, //< AMDGPUAS::LOCAL_ADDRESS
152 DWARFAS::GLOBAL, //< AMDGPUAS::CONSTANT_ADDRESS
153 DWARFAS::PRIVATE_LANE //< AMDGPUAS::PRIVATE_ADDRESS
154};
155} // end namespace impl
156
157/// If @p LLVMAddressSpace has a corresponding DWARF encoding,
158/// return it; otherwise return the sentinel value -1 to indicate
159/// no such mapping exists.
160///
161/// This maps private/scratch to the focused lane view.
162///
163/// These mappings must be kept in sync with llvm/docs/AMDGPUUsage.rst
164/// table "AMDGPU DWARF Address Space Mapping".
165///
166/// Note: This could return std::optional<int> but that would require
167/// an extra #include.
168constexpr int mapToDWARFAddrSpace(unsigned LLVMAddrSpace) {
169 constexpr unsigned SizeOfLLVMToDWARFAddrSpaceMapping =
172 if (LLVMAddrSpace < SizeOfLLVMToDWARFAddrSpaceMapping)
173 return impl::LLVMToDWARFAddrSpaceMapping[LLVMAddrSpace];
174 return -1;
175}
176
177/// Get the null pointer value for the given address space.
178constexpr int64_t getNullPointerValue(unsigned AS) {
179 switch (AS) {
180 using namespace AMDGPUAS;
181 case PRIVATE_ADDRESS:
182 case LOCAL_ADDRESS:
183 case REGION_ADDRESS:
184 return -1;
185 default:
186 return 0;
187 }
188}
189} // end namespace AMDGPU
190
191} // end namespace llvm
192
193#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.