1 //===--- AddressSpaces.h - Language-specific address spaces -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Provides definitions for the various language-specific address
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
17 #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
23 /// \brief Defines the address space values used by the address space qualifier
26 enum class LangAS : unsigned {
27 // The default value 0 is the value used in QualType for the the situation
28 // where there is no address space qualifier.
31 // OpenCL specific address spaces.
32 // In OpenCL each l-value must have certain non-default address space, each
33 // r-value must have no address space (i.e. the default address space). The
34 // pointee of a pointer must have non-default address space.
41 // CUDA specific address spaces.
46 // This denotes the count of language-specific address spaces and also
47 // the offset added to the target-specific address spaces, which are usually
48 // specified by address space attributes __attribute__(address_space(n))).
49 FirstTargetAddressSpace
52 /// The type of a lookup table which maps from language-specific address spaces
53 /// to target-specific ones.
54 typedef unsigned LangASMap[(unsigned)LangAS::FirstTargetAddressSpace];
56 /// \return whether \p AS is a target-specific address space rather than a
57 /// clang AST address space
58 inline bool isTargetAddressSpace(LangAS AS) {
59 return (unsigned)AS >= (unsigned)LangAS::FirstTargetAddressSpace;
62 inline unsigned toTargetAddressSpace(LangAS AS) {
63 assert(isTargetAddressSpace(AS));
64 return (unsigned)AS - (unsigned)LangAS::FirstTargetAddressSpace;
67 inline LangAS getLangASFromTargetAS(unsigned TargetAS) {
68 return static_cast<LangAS>((TargetAS) +
69 (unsigned)LangAS::FirstTargetAddressSpace);