1 //===- AddressSpaces.h - Language-specific address spaces -------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Provides definitions for the various language-specific address
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
16 #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
22 /// Defines the address space values used by the address space qualifier
25 enum class LangAS : unsigned {
26 // The default value 0 is the value used in QualType for the situation
27 // where there is no address space qualifier.
30 // OpenCL specific address spaces.
31 // In OpenCL each l-value must have certain non-default address space, each
32 // r-value must have no address space (i.e. the default address space). The
33 // pointee of a pointer must have non-default address space.
40 // CUDA specific address spaces.
45 // Pointer size and extension address spaces.
50 // This denotes the count of language-specific address spaces and also
51 // the offset added to the target-specific address spaces, which are usually
52 // specified by address space attributes __attribute__(address_space(n))).
53 FirstTargetAddressSpace
56 /// The type of a lookup table which maps from language-specific address spaces
57 /// to target-specific ones.
58 using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace];
60 /// \return whether \p AS is a target-specific address space rather than a
61 /// clang AST address space
62 inline bool isTargetAddressSpace(LangAS AS) {
63 return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
66 inline unsigned toTargetAddressSpace(LangAS AS) {
67 assert(isTargetAddressSpace(AS));
68 return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
71 inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
72 return static_cast<LangAS>((TargetAS) +
73 (unsigned)LangAS::FirstTargetAddressSpace);
76 inline bool isPtrSizeAddressSpace(LangAS AS) {
77 return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
83 #endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H