AddressSpaces.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- AddressSpaces.h - Language-specific address spaces -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. /// \file
  15. /// Provides definitions for the various language-specific address
  16. /// spaces.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
  20. #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
  21. #include <cassert>
  22. namespace clang {
  23. /// Defines the address space values used by the address space qualifier
  24. /// of QualType.
  25. ///
  26. enum class LangAS : unsigned {
  27. // The default value 0 is the value used in QualType for the situation
  28. // where there is no address space qualifier.
  29. Default = 0,
  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. // CUDA specific address spaces.
  42. cuda_device,
  43. cuda_constant,
  44. cuda_shared,
  45. // SYCL specific address spaces.
  46. sycl_global,
  47. sycl_global_device,
  48. sycl_global_host,
  49. sycl_local,
  50. sycl_private,
  51. // Pointer size and extension address spaces.
  52. ptr32_sptr,
  53. ptr32_uptr,
  54. ptr64,
  55. // This denotes the count of language-specific address spaces and also
  56. // the offset added to the target-specific address spaces, which are usually
  57. // specified by address space attributes __attribute__(address_space(n))).
  58. FirstTargetAddressSpace
  59. };
  60. /// The type of a lookup table which maps from language-specific address spaces
  61. /// to target-specific ones.
  62. using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace];
  63. /// \return whether \p AS is a target-specific address space rather than a
  64. /// clang AST address space
  65. inline bool isTargetAddressSpace(LangAS AS) {
  66. return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
  67. }
  68. inline unsigned toTargetAddressSpace(LangAS AS) {
  69. assert(isTargetAddressSpace(AS));
  70. return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
  71. }
  72. inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
  73. return static_cast<LangAS>((TargetAS) +
  74. (unsigned)LangAS::FirstTargetAddressSpace);
  75. }
  76. inline bool isPtrSizeAddressSpace(LangAS AS) {
  77. return (AS == LangAS::ptr32_sptr || AS == LangAS::ptr32_uptr ||
  78. AS == LangAS::ptr64);
  79. }
  80. } // namespace clang
  81. #endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H
  82. #ifdef __GNUC__
  83. #pragma GCC diagnostic pop
  84. #endif