1 //===-- llvm/Type.h - Classes for handling data types ------------*- C++ -*--=//
3 // This file contains the declaration of the Type class. For more "Type" type
4 // stuff, look in DerivedTypes.h and Opt/ConstantHandling.h
6 // Note that instances of the Type class are immutable: once they are created,
7 // they are never changed. Also note that only one instance of a particular
8 // type is ever created. Thus seeing if two types are equal is a matter of
9 // doing a trivial pointer comparison.
11 // Types, once allocated, are never free'd.
13 //===----------------------------------------------------------------------===//
18 #include "llvm/Value.h"
29 class Type : public Value {
31 //===--------------------------------------------------------------------===//
32 // Definitions of all of the base types for the Type system. Based on this
33 // value, you can cast to a "DerivedType" subclass (see DerivedTypes.h)
34 // Note: If you add an element to this, you need to add an element to the
35 // Type::getPrimitiveType function, or else things will break!
38 VoidTyID = 0 , BoolTyID, // 0, 1: Basics...
39 UByteTyID , SByteTyID, // 2, 3: 8 bit types...
40 UShortTyID , ShortTyID, // 4, 5: 16 bit types...
41 UIntTyID , IntTyID, // 6, 7: 32 bit types...
42 ULongTyID , LongTyID, // 8, 9: 64 bit types...
44 FloatTyID , DoubleTyID, // 10,11: Floating point types...
46 TypeTyID, // 12 : Type definitions
47 LabelTyID , LockTyID, // 13,14: Labels... mutexes...
49 // TODO: Kill FillerTyID. It just makes FirstDerivedTyID = 0x10
50 FillerTyID , // 15 : filler
52 // Derived types... see DerivedTypes.h file...
53 // Make sure FirstDerivedTyID stays up to date!!!
54 MethodTyID , ModuleTyID, // Methods... Modules...
55 ArrayTyID , PointerTyID, // Array... pointer...
56 StructTyID , PackedTyID, // Structure... SIMD 'packed' format...
59 NumPrimitiveIDs, // Must remain as last defined ID
60 FirstDerivedTyID = MethodTyID,
64 PrimitiveID ID; // The current base type of this type...
65 unsigned UID; // The unique ID number for this class
67 // ConstRulesImpl - See Opt/ConstantHandling.h for more info
68 mutable const opt::ConstRules *ConstRulesImpl;
71 // ctor is protected, so only subclasses can create Type objects...
72 Type(const string &Name, PrimitiveID id);
76 // isSigned - Return whether a numeric type is signed.
77 virtual bool isSigned() const { return 0; }
79 // isUnsigned - Return whether a numeric type is unsigned. This is not
80 // quite the complement of isSigned... nonnumeric types return false as they
83 virtual bool isUnsigned() const { return 0; }
85 // isIntegral - Equilivent to isSigned() || isUnsigned, but with only a single
86 // virtual function invocation.
88 virtual bool isIntegral() const { return 0; }
90 inline unsigned getUniqueID() const { return UID; }
91 inline PrimitiveID getPrimitiveID() const { return ID; }
93 // getPrimitiveType/getUniqueIDType - Return a type based on an identifier.
94 static const Type *getPrimitiveType(PrimitiveID IDNumber);
95 static const Type *getUniqueIDType(unsigned UID);
97 // Methods for dealing with constants uniformly. See Opt/ConstantHandling.h
98 // for more info on this...
100 inline const opt::ConstRules *getConstRules() const { return ConstRulesImpl; }
101 inline void setConstRules(const opt::ConstRules *R) const { ConstRulesImpl = R; }
103 public: // These are the builtin types that are always available...
104 static const Type *VoidTy , *BoolTy;
105 static const Type *SByteTy, *UByteTy,
109 static const Type *FloatTy, *DoubleTy;
111 static const Type *TypeTy , *LabelTy, *LockTy;
113 // Here are some useful little methods to query what type derived types are
114 // Note that all other types can just compare to see if this == Type::xxxTy;
116 inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
117 inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
119 inline bool isLabelType() const { return this == LabelTy; }
120 inline const MethodType *isMethodType() const {
121 return ID == MethodTyID ? (const MethodType*)this : 0;
123 inline bool isModuleType() const { return ID == ModuleTyID; }
124 inline const ArrayType *isArrayType() const {
125 return ID == ArrayTyID ? (const ArrayType*)this : 0;
127 inline const PointerType *isPointerType() const {
128 return ID == PointerTyID ? (const PointerType*)this : 0;
130 inline const StructType *isStructType() const {
131 return ID == StructTyID ? (const StructType*)this : 0;