1 //===- llvm/IR/TypedPointerType.h - Typed Pointer Type --------------------===//
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 // This file contains typed pointer type information. It is separated out into
10 // a separate file to make it less likely to accidentally use this type.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_TYPEDPOINTERTYPE_H
15 #define LLVM_IR_TYPEDPOINTERTYPE_H
16 
17 #include "llvm/IR/Type.h"
18 
19 namespace llvm {
20 
21 /// A few GPU targets, such as DXIL and SPIR-V, have typed pointers. This
22 /// pointer type abstraction is used for tracking the types of these pointers.
23 /// It is not legal to use this type, or derived types containing this type, in
24 /// LLVM IR.
25 class TypedPointerType : public Type {
26   explicit TypedPointerType(Type *ElType, unsigned AddrSpace);
27 
28   Type *PointeeTy;
29 
30 public:
31   TypedPointerType(const TypedPointerType &) = delete;
32   TypedPointerType &operator=(const TypedPointerType &) = delete;
33 
34   /// This constructs a pointer to an object of the specified type in a numbered
35   /// address space.
36   static TypedPointerType *get(Type *ElementType, unsigned AddressSpace);
37 
38   /// Return true if the specified type is valid as a element type.
39   static bool isValidElementType(Type *ElemTy);
40 
41   /// Return the address space of the Pointer type.
42   unsigned getAddressSpace() const { return getSubclassData(); }
43 
44   Type *getElementType() const { return PointeeTy; }
45 
46   /// Implement support type inquiry through isa, cast, and dyn_cast.
47   static bool classof(const Type *T) {
48     return T->getTypeID() == TypedPointerTyID;
49   }
50 };
51 
52 } // namespace llvm
53 
54 #endif // LLVM_IR_TYPEDPOINTERTYPE_H
55