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.
44
45 // CUDA specific address spaces.
49
50 // SYCL specific address spaces.
56
57 // Pointer size and extension address spaces.
61
62 // HLSL specific address spaces.
70
71 // Wasm specific address spaces.
73
74 // AMDGPU address spaces
76
77 // This denotes the count of language-specific address spaces and also
78 // the offset added to the target-specific address spaces, which are usually
79 // specified by address space attributes __attribute__(address_space(n))).
81};
82
83/// The type of a lookup table which maps from language-specific address spaces
84/// to target-specific ones.
85class LangASMap {
87
88public:
89 constexpr LangASMap() = default;
90
91 constexpr LangASMap(
92 std::initializer_list<std::pair<LangAS, unsigned>> Mappings) {
93 for (auto [LanguageAS, TargetAS] : Mappings)
94 Map[(unsigned)LanguageAS] = TargetAS;
95 }
96
97 constexpr unsigned operator[](LangAS AS) const { return Map[(unsigned)AS]; }
98};
99
100/// \return whether \p AS is a target-specific address space rather than a
101/// clang AST address space
103 return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
104}
105
106inline unsigned toTargetAddressSpace(LangAS AS) {
107 assert(isTargetAddressSpace(AS));
108 return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
109}
110
111inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
112 return static_cast<LangAS>((TargetAS) +
114}
115
117 return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
118 AS == LangAS::ptr64);
119}
120
121} // namespace clang
122
123#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)