xref: /openbsd-src/gnu/llvm/clang/include/clang/Basic/AddressSpaces.h (revision 12c855180aad702bbcca06e0398d774beeafb155)
1e5dd7070Spatrick //===- AddressSpaces.h - Language-specific address spaces -------*- C++ -*-===//
2e5dd7070Spatrick //
3e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e5dd7070Spatrick //
7e5dd7070Spatrick //===----------------------------------------------------------------------===//
8e5dd7070Spatrick //
9e5dd7070Spatrick /// \file
10e5dd7070Spatrick /// Provides definitions for the various language-specific address
11e5dd7070Spatrick /// spaces.
12e5dd7070Spatrick //
13e5dd7070Spatrick //===----------------------------------------------------------------------===//
14e5dd7070Spatrick 
15e5dd7070Spatrick #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
16e5dd7070Spatrick #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
17e5dd7070Spatrick 
18e5dd7070Spatrick #include <cassert>
19e5dd7070Spatrick 
20e5dd7070Spatrick namespace clang {
21e5dd7070Spatrick 
22e5dd7070Spatrick /// Defines the address space values used by the address space qualifier
23e5dd7070Spatrick /// of QualType.
24e5dd7070Spatrick ///
25e5dd7070Spatrick enum class LangAS : unsigned {
26e5dd7070Spatrick   // The default value 0 is the value used in QualType for the situation
27e5dd7070Spatrick   // where there is no address space qualifier.
28e5dd7070Spatrick   Default = 0,
29e5dd7070Spatrick 
30e5dd7070Spatrick   // OpenCL specific address spaces.
31e5dd7070Spatrick   // In OpenCL each l-value must have certain non-default address space, each
32e5dd7070Spatrick   // r-value must have no address space (i.e. the default address space). The
33e5dd7070Spatrick   // pointee of a pointer must have non-default address space.
34e5dd7070Spatrick   opencl_global,
35e5dd7070Spatrick   opencl_local,
36e5dd7070Spatrick   opencl_constant,
37e5dd7070Spatrick   opencl_private,
38e5dd7070Spatrick   opencl_generic,
39a9ac8606Spatrick   opencl_global_device,
40a9ac8606Spatrick   opencl_global_host,
41e5dd7070Spatrick 
42e5dd7070Spatrick   // CUDA specific address spaces.
43e5dd7070Spatrick   cuda_device,
44e5dd7070Spatrick   cuda_constant,
45e5dd7070Spatrick   cuda_shared,
46e5dd7070Spatrick 
47a9ac8606Spatrick   // SYCL specific address spaces.
48a9ac8606Spatrick   sycl_global,
49a9ac8606Spatrick   sycl_global_device,
50a9ac8606Spatrick   sycl_global_host,
51a9ac8606Spatrick   sycl_local,
52a9ac8606Spatrick   sycl_private,
53a9ac8606Spatrick 
54e5dd7070Spatrick   // Pointer size and extension address spaces.
55e5dd7070Spatrick   ptr32_sptr,
56e5dd7070Spatrick   ptr32_uptr,
57e5dd7070Spatrick   ptr64,
58e5dd7070Spatrick 
59*12c85518Srobert   // HLSL specific address spaces.
60*12c85518Srobert   hlsl_groupshared,
61*12c85518Srobert 
62e5dd7070Spatrick   // This denotes the count of language-specific address spaces and also
63e5dd7070Spatrick   // the offset added to the target-specific address spaces, which are usually
64e5dd7070Spatrick   // specified by address space attributes __attribute__(address_space(n))).
65e5dd7070Spatrick   FirstTargetAddressSpace
66e5dd7070Spatrick };
67e5dd7070Spatrick 
68e5dd7070Spatrick /// The type of a lookup table which maps from language-specific address spaces
69e5dd7070Spatrick /// to target-specific ones.
70e5dd7070Spatrick using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace];
71e5dd7070Spatrick 
72e5dd7070Spatrick /// \return whether \p AS is a target-specific address space rather than a
73e5dd7070Spatrick /// clang AST address space
isTargetAddressSpace(LangAS AS)74e5dd7070Spatrick inline bool isTargetAddressSpace(LangAS AS) {
75e5dd7070Spatrick   return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
76e5dd7070Spatrick }
77e5dd7070Spatrick 
toTargetAddressSpace(LangAS AS)78e5dd7070Spatrick inline unsigned toTargetAddressSpace(LangAS AS) {
79e5dd7070Spatrick   assert(isTargetAddressSpace(AS));
80e5dd7070Spatrick   return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
81e5dd7070Spatrick }
82e5dd7070Spatrick 
getLangASFromTargetAS(unsigned TargetAS)83e5dd7070Spatrick inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
84e5dd7070Spatrick   return static_cast<LangAS>((TargetAS) +
85e5dd7070Spatrick                              (unsigned)LangAS::FirstTargetAddressSpace);
86e5dd7070Spatrick }
87e5dd7070Spatrick 
isPtrSizeAddressSpace(LangAS AS)88e5dd7070Spatrick inline bool isPtrSizeAddressSpace(LangAS AS) {
89e5dd7070Spatrick   return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
90e5dd7070Spatrick           AS == LangAS::ptr64);
91e5dd7070Spatrick }
92e5dd7070Spatrick 
93e5dd7070Spatrick } // namespace clang
94e5dd7070Spatrick 
95e5dd7070Spatrick #endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H
96