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"
25 class Type : public Value {
27 //===--------------------------------------------------------------------===//
28 // Definitions of all of the base types for the Type system. Based on this
29 // value, you can cast to a "DerivedType" subclass (see DerivedTypes.h)
30 // Note: If you add an element to this, you need to add an element to the
31 // Type::getPrimitiveType function, or else things will break!
34 VoidTyID = 0 , BoolTyID, // 0, 1: Basics...
35 UByteTyID , SByteTyID, // 2, 3: 8 bit types...
36 UShortTyID , ShortTyID, // 4, 5: 16 bit types...
37 UIntTyID , IntTyID, // 6, 7: 32 bit types...
38 ULongTyID , LongTyID, // 8, 9: 64 bit types...
40 FloatTyID , DoubleTyID, // 10,11: Floating point types...
42 TypeTyID, // 12 : Type definitions
43 LabelTyID , LockTyID, // 13,14: Labels... mutexes...
45 // TODO: Kill FillerTyID. It just makes FirstDerivedTyID = 0x10
46 FillerTyID , // 15 : filler
48 // Derived types... see DerivedTypes.h file...
49 // Make sure FirstDerivedTyID stays up to date!!!
50 MethodTyID , ModuleTyID, // Methods... Modules...
51 ArrayTyID , PointerTyID, // Array... pointer...
52 StructTyID , PackedTyID, // Structure... SIMD 'packed' format...
55 NumPrimitiveIDs, // Must remain as last defined ID
56 FirstDerivedTyID = MethodTyID,
60 PrimitiveID ID; // The current base type of this type...
61 unsigned UID; // The unique ID number for this class
63 // ConstRulesImpl - See Opt/ConstantHandling.h for more info
64 mutable const opt::ConstRules *ConstRulesImpl;
67 // ctor is protected, so only subclasses can create Type objects...
68 Type(const string &Name, PrimitiveID id);
72 // isSigned - Return whether a numeric type is signed.
73 virtual bool isSigned() const { return 0; }
75 // isUnsigned - Return whether a numeric type is unsigned. This is not
76 // quite the complement of isSigned... nonnumeric types return false as they
79 virtual bool isUnsigned() const { return 0; }
81 inline unsigned getUniqueID() const { return UID; }
82 inline PrimitiveID getPrimitiveID() const { return ID; }
84 // getPrimitiveType/getUniqueIDType - Return a type based on an identifier.
85 static const Type *getPrimitiveType(PrimitiveID IDNumber);
86 static const Type *getUniqueIDType(unsigned UID);
88 // Methods for dealing with constants uniformly. See Opt/ConstantHandling.h
89 // for more info on this...
91 inline const opt::ConstRules *getConstRules() const { return ConstRulesImpl; }
92 inline void setConstRules(const opt::ConstRules *R) const { ConstRulesImpl = R; }
94 public: // These are the builtin types that are always available...
95 static const Type *VoidTy , *BoolTy;
96 static const Type *SByteTy, *UByteTy,
100 static const Type *FloatTy, *DoubleTy;
102 static const Type *TypeTy , *LabelTy, *LockTy;
104 // Here are some useful little methods to query what type derived types are
105 // Note that all other types can just compare to see if this == Type::xxxTy;
107 inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
108 inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
110 inline bool isLabelType() const { return this == LabelTy; }
111 inline bool isMethodType() const { return ID == MethodTyID; }
112 inline bool isModuleType() const { return ID == ModuleTyID; }
113 inline bool isArrayType() const { return ID == ArrayTyID; }
114 inline bool isPointerType() const { return ID == PointerTyID; }
115 inline bool isStructType() const { return ID == StructTyID; }