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 // This denotes the count of language-specific address spaces and also
75 // the offset added to the target-specific address spaces, which are usually
76 // specified by address space attributes __attribute__(address_space(n))).
78};
79
80/// The type of a lookup table which maps from language-specific address spaces
81/// to target-specific ones.
82class LangASMap {
84
85public:
86 constexpr LangASMap() = default;
87
88 constexpr LangASMap(
89 std::initializer_list<std::pair<LangAS, unsigned>> Mappings) {
90 for (auto [LanguageAS, TargetAS] : Mappings)
91 Map[(unsigned)LanguageAS] = TargetAS;
92 }
93
94 constexpr unsigned operator[](LangAS AS) const { return Map[(unsigned)AS]; }
95};
96
97/// \return whether \p AS is a target-specific address space rather than a
98/// clang AST address space
100 return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
101}
102
103inline unsigned toTargetAddressSpace(LangAS AS) {
104 assert(isTargetAddressSpace(AS));
105 return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
106}
107
108inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
109 return static_cast<LangAS>((TargetAS) +
111}
112
114 return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
115 AS == LangAS::ptr64);
116}
117
118} // namespace clang
119
120#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
The JSON file list parser is used to communicate input to InstallAPI.
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)