/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Basic/AddressSpaces.h
Line | Count | Source |
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. |
34 | | opencl_global, |
35 | | opencl_local, |
36 | | opencl_constant, |
37 | | opencl_private, |
38 | | opencl_generic, |
39 | | opencl_global_device, |
40 | | opencl_global_host, |
41 | | |
42 | | // CUDA specific address spaces. |
43 | | cuda_device, |
44 | | cuda_constant, |
45 | | cuda_shared, |
46 | | |
47 | | // SYCL specific address spaces. |
48 | | sycl_global, |
49 | | sycl_global_device, |
50 | | sycl_global_host, |
51 | | sycl_local, |
52 | | sycl_private, |
53 | | |
54 | | // Pointer size and extension address spaces. |
55 | | ptr32_sptr, |
56 | | ptr32_uptr, |
57 | | ptr64, |
58 | | |
59 | | // HLSL specific address spaces. |
60 | | hlsl_groupshared, |
61 | | |
62 | | // Wasm specific address spaces. |
63 | | wasm_funcref, |
64 | | |
65 | | // This denotes the count of language-specific address spaces and also |
66 | | // the offset added to the target-specific address spaces, which are usually |
67 | | // specified by address space attributes __attribute__(address_space(n))). |
68 | | FirstTargetAddressSpace |
69 | | }; |
70 | | |
71 | | /// The type of a lookup table which maps from language-specific address spaces |
72 | | /// to target-specific ones. |
73 | | using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace]; |
74 | | |
75 | | /// \return whether \p AS is a target-specific address space rather than a |
76 | | /// clang AST address space |
77 | 1.47M | inline bool isTargetAddressSpace(LangAS AS) { |
78 | 1.47M | return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace; |
79 | 1.47M | } |
80 | | |
81 | 2.18k | inline unsigned toTargetAddressSpace(LangAS AS) { |
82 | 2.18k | assert(isTargetAddressSpace(AS)); |
83 | 2.18k | return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace; |
84 | 2.18k | } |
85 | | |
86 | 2.73k | inline LangAS getLangASFromTargetAS(unsigned TargetAS) { |
87 | 2.73k | return static_cast<LangAS>((TargetAS) + |
88 | 2.73k | (unsigned)LangAS::FirstTargetAddressSpace); |
89 | 2.73k | } |
90 | | |
91 | 22.2M | inline bool isPtrSizeAddressSpace(LangAS AS) { |
92 | 22.2M | return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr22.2M || |
93 | 22.2M | AS == LangAS::ptr6422.2M ); |
94 | 22.2M | } |
95 | | |
96 | | } // namespace clang |
97 | | |
98 | | #endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H |