clang 24.0.0git
AddressSpaces.h
Go to the documentation of this file.
1//===- AddressSpaces.h - Language-specific address spaces -------*- 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/// Provides definitions for the various language-specific address
11/// spaces.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
16#define LLVM_CLANG_BASIC_ADDRESSSPACES_H
17
18#include <array>
19#include <cassert>
20#include <initializer_list>
21#include <utility>
22
23namespace clang {
24
25/// Defines the address space values used by the address space qualifier
26/// of QualType.
27///
28enum class LangAS : unsigned {
29 // The default value 0 is the value used in QualType for the situation
30 // where there is no address space qualifier.
32
33 // OpenCL specific address spaces.
34 // In OpenCL each l-value must have certain non-default address space, each
35 // r-value must have no address space (i.e. the default address space). The
36 // pointee of a pointer must have non-default address space.
42 // TODO: Remove opencl_global_device and opencl_global_host after
43 // corresponding attributes are deprecated for the required time.
44 // https://discourse.llvm.org/t/rfc-remove-opencl-global-device-and-opencl-global-host-address-space-attributes/90677
47
48 // CUDA specific address spaces.
52
53 // SYCL specific address spaces.
55 // TODO: Remove sycl_global_device and sycl_global_host after corresponding
56 // attributes are deprecated for the required time.
57 // https://discourse.llvm.org/t/rfc-remove-opencl-global-device-and-opencl-global-host-address-space-attributes/90677
64
65 // Pointer size and extension address spaces.
69
70 // HLSL specific address spaces.
78
79 // Wasm specific address spaces.
81
82 // AMDGPU address spaces
84
85 // This denotes the count of language-specific address spaces and also
86 // the offset added to the target-specific address spaces, which are usually
87 // specified by address space attributes __attribute__(address_space(n))).
89};
90
91/// The type of a lookup table which maps from language-specific address spaces
92/// to target-specific ones.
93class LangASMap {
95
96public:
97 constexpr LangASMap() = default;
98
99 constexpr LangASMap(
100 std::initializer_list<std::pair<LangAS, unsigned>> Mappings) {
101 for (auto [LanguageAS, TargetAS] : Mappings)
102 Map[(unsigned)LanguageAS] = TargetAS;
103 }
104
105 constexpr unsigned operator[](LangAS AS) const { return Map[(unsigned)AS]; }
106};
107
108/// \return whether \p AS is a target-specific address space rather than a
109/// clang AST address space
111 return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
112}
113
114inline unsigned toTargetAddressSpace(LangAS AS) {
115 assert(isTargetAddressSpace(AS));
116 return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
117}
118
119inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
120 return static_cast<LangAS>((TargetAS) +
122}
123
125 return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
126 AS == LangAS::ptr64);
127}
128
129} // namespace clang
130
131#endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H
constexpr unsigned operator[](LangAS AS) const
constexpr LangASMap(std::initializer_list< std::pair< LangAS, unsigned > > Mappings)
constexpr LangASMap()=default
Top level wrappers for InstallAPI frontend operations.
bool isTargetAddressSpace(LangAS AS)
unsigned toTargetAddressSpace(LangAS AS)
@ Default
Set to the current date and time.
LangAS
Defines the address space values used by the address space qualifier of QualType.
bool isPtrSizeAddressSpace(LangAS AS)
LangAS getLangASFromTargetAS(unsigned TargetAS)