clang  14.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 <cassert>
19 
20 namespace clang {
21 
22 /// Defines the address space values used by the address space qualifier
23 /// of QualType.
24 ///
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.
28  Default = 0,
29 
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.
41 
42  // CUDA specific address spaces.
46 
47  // SYCL specific address spaces.
51  sycl_local,
53 
54  // Pointer size and extension address spaces.
55  ptr32_sptr,
56  ptr32_uptr,
57  ptr64,
58 
59  // This denotes the count of language-specific address spaces and also
60  // the offset added to the target-specific address spaces, which are usually
61  // specified by address space attributes __attribute__(address_space(n))).
63 };
64 
65 /// The type of a lookup table which maps from language-specific address spaces
66 /// to target-specific ones.
68 
69 /// \return whether \p AS is a target-specific address space rather than a
70 /// clang AST address space
71 inline bool isTargetAddressSpace(LangAS AS) {
72  return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
73 }
74 
75 inline unsigned toTargetAddressSpace(LangAS AS) {
76  assert(isTargetAddressSpace(AS));
77  return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
78 }
79 
80 inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
81  return static_cast<LangAS>((TargetAS) +
83 }
84 
85 inline bool isPtrSizeAddressSpace(LangAS AS) {
86  return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
87  AS == LangAS::ptr64);
88 }
89 
90 } // namespace clang
91 
92 #endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H
clang::LangAS::cuda_shared
@ cuda_shared
clang::isTargetAddressSpace
bool isTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:71
clang::LangAS::opencl_private
@ opencl_private
clang::LangAS::sycl_global
@ sycl_global
clang::LangAS::cuda_device
@ cuda_device
clang::LangAS::sycl_local
@ sycl_local
clang::LangAS::opencl_global_host
@ opencl_global_host
clang::LangAS::sycl_global_device
@ sycl_global_device
clang::LangAS::opencl_local
@ opencl_local
clang::LangAS::FirstTargetAddressSpace
@ FirstTargetAddressSpace
clang::LangASMap
unsigned[(unsigned) LangAS::FirstTargetAddressSpace] LangASMap
The type of a lookup table which maps from language-specific address spaces to target-specific ones.
Definition: AddressSpaces.h:67
clang::toTargetAddressSpace
unsigned toTargetAddressSpace(LangAS AS)
Definition: AddressSpaces.h:75
clang::getLangASFromTargetAS
LangAS getLangASFromTargetAS(unsigned TargetAS)
Definition: AddressSpaces.h:80
clang::LangAS::opencl_constant
@ opencl_constant
clang::LangAS
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
clang::LangAS::opencl_global
@ opencl_global
clang::isPtrSizeAddressSpace
bool isPtrSizeAddressSpace(LangAS AS)
Definition: AddressSpaces.h:85
clang::LangAS::cuda_constant
@ cuda_constant
clang::LangAS::Default
@ Default
clang::LangAS::sycl_private
@ sycl_private
clang
Definition: CalledOnceCheck.h:17
clang::LangAS::ptr64
@ ptr64
clang::LangAS::ptr32_uptr
@ ptr32_uptr
unsigned
clang::LangAS::opencl_global_device
@ opencl_global_device
clang::LangAS::sycl_global_host
@ sycl_global_host
clang::LangAS::opencl_generic
@ opencl_generic
clang::LangAS::ptr32_sptr
@ ptr32_sptr