X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FIR%2FType.h;h=4378709c0c6684cfa5e2ec28f79f6dffd6fea8c0;hb=2b762697564ca1e12e0e974e93ceeb4c3420505c;hp=730c4fe30ad9e9be1d7aaa0124ca603ee1d086af;hpb=954b6b844be9483e3a81f8d0313e65f6208f90c6;p=oota-llvm.git diff --git a/include/llvm/IR/Type.h b/include/llvm/IR/Type.h index 730c4fe30ad..4378709c0c6 100644 --- a/include/llvm/IR/Type.h +++ b/include/llvm/IR/Type.h @@ -15,13 +15,13 @@ #ifndef LLVM_IR_TYPE_H #define LLVM_IR_TYPE_H +#include "llvm-c/Core.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallPtrSet.h" -#include "llvm/Support/Casting.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm-c/Core.h" namespace llvm { @@ -38,10 +38,10 @@ template struct GraphTraits; /// they are never changed. Also note that only one instance of a particular /// type is ever created. Thus seeing if two types are equal is a matter of /// doing a trivial pointer comparison. To enforce that no two equal instances -/// are created, Type instances can only be created via static factory methods +/// are created, Type instances can only be created via static factory methods /// in class Type and in derived classes. Once allocated, Types are never /// free'd. -/// +/// class Type { public: //===--------------------------------------------------------------------===// @@ -63,48 +63,36 @@ public: LabelTyID, ///< 7: Labels MetadataTyID, ///< 8: Metadata X86_MMXTyID, ///< 9: MMX vectors (64 bits, X86 specific) + TokenTyID, ///< 10: Tokens // Derived types... see DerivedTypes.h file. // Make sure FirstDerivedTyID stays up to date! - IntegerTyID, ///< 10: Arbitrary bit width integers - FunctionTyID, ///< 11: Functions - StructTyID, ///< 12: Structures - ArrayTyID, ///< 13: Arrays - PointerTyID, ///< 14: Pointers - VectorTyID, ///< 15: SIMD 'packed' format, or other vector type - - LastPrimitiveTyID = X86_MMXTyID, - FirstDerivedTyID = IntegerTyID + IntegerTyID, ///< 11: Arbitrary bit width integers + FunctionTyID, ///< 12: Functions + StructTyID, ///< 13: Structures + ArrayTyID, ///< 14: Arrays + PointerTyID, ///< 15: Pointers + VectorTyID ///< 16: SIMD 'packed' format, or other vector type }; private: /// Context - This refers to the LLVMContext in which this type was uniqued. LLVMContext &Context; - // Due to Ubuntu GCC bug 910363: - // https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/910363 - // Bitpack ID and SubclassData manually. - // Note: TypeID : low 8 bit; SubclassData : high 24 bit. - uint32_t IDAndSubclassData; + TypeID ID : 8; // The current base type of this type. + unsigned SubclassData : 24; // Space for subclasses to store data. protected: friend class LLVMContextImpl; explicit Type(LLVMContext &C, TypeID tid) - : Context(C), IDAndSubclassData(0), - NumContainedTys(0), ContainedTys(0) { - setTypeID(tid); - } - ~Type() {} - - void setTypeID(TypeID ID) { - IDAndSubclassData = (ID & 0xFF) | (IDAndSubclassData & 0xFFFFFF00); - assert(getTypeID() == ID && "TypeID data too large for field"); - } - - unsigned getSubclassData() const { return IDAndSubclassData >> 8; } - + : Context(C), ID(tid), SubclassData(0), + NumContainedTys(0), ContainedTys(nullptr) {} + ~Type() = default; + + unsigned getSubclassData() const { return SubclassData; } + void setSubclassData(unsigned val) { - IDAndSubclassData = (IDAndSubclassData & 0xFF) | (val << 8); + SubclassData = val; // Ensure we don't have any accidental truncation. assert(getSubclassData() == val && "Subclass data too large for field"); } @@ -121,7 +109,7 @@ protected: Type * const *ContainedTys; public: - void print(raw_ostream &O) const; + void print(raw_ostream &O, bool IsForDebug = false) const; void dump() const; /// getContext - Return the LLVMContext in which this type was uniqued. @@ -134,7 +122,7 @@ public: /// getTypeID - Return the type id for the type. This will return one /// of the TypeID enum elements defined above. /// - TypeID getTypeID() const { return (TypeID)(IDAndSubclassData & 0xFF); } + TypeID getTypeID() const { return ID; } /// isVoidTy - Return true if this is 'void'. bool isVoidTy() const { return getTypeID() == VoidTyID; } @@ -144,7 +132,7 @@ public: /// isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type. bool isFloatTy() const { return getTypeID() == FloatTyID; } - + /// isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type. bool isDoubleTy() const { return getTypeID() == DoubleTyID; } @@ -184,16 +172,19 @@ public: /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP. /// bool isFPOrFPVectorTy() const { return getScalarType()->isFloatingPointTy(); } - + /// isLabelTy - Return true if this is 'label'. bool isLabelTy() const { return getTypeID() == LabelTyID; } /// isMetadataTy - Return true if this is 'metadata'. bool isMetadataTy() const { return getTypeID() == MetadataTyID; } + /// isTokenTy - Return true if this is 'token'. + bool isTokenTy() const { return getTypeID() == TokenTyID; } + /// isIntegerTy - True if this is an instance of IntegerType. /// - bool isIntegerTy() const { return getTypeID() == IntegerTyID; } + bool isIntegerTy() const { return getTypeID() == IntegerTyID; } /// isIntegerTy - Return true if this is an IntegerType of the given width. bool isIntegerTy(unsigned Bitwidth) const; @@ -202,7 +193,7 @@ public: /// integer types. /// bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); } - + /// isFunctionTy - True if this is an instance of FunctionType. /// bool isFunctionTy() const { return getTypeID() == FunctionTyID; } @@ -223,14 +214,14 @@ public: /// pointer types. /// bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); } - + /// isVectorTy - True if this is an instance of VectorType. /// bool isVectorTy() const { return getTypeID() == VectorTyID; } - /// canLosslesslyBitCastTo - Return true if this type could be converted - /// with a lossless BitCast to type 'Ty'. For example, i8* to i32*. BitCasts - /// are valid for types of the same size only where no re-interpretation of + /// canLosslesslyBitCastTo - Return true if this type could be converted + /// with a lossless BitCast to type 'Ty'. For example, i8* to i32*. BitCasts + /// are valid for types of the same size only where no re-interpretation of /// the bits is done. /// @brief Determine if this type could be losslessly bitcast to Ty bool canLosslesslyBitCastTo(Type *Ty) const; @@ -239,12 +230,6 @@ public: /// elements or all its elements are empty. bool isEmptyTy() const; - /// Here are some useful little methods to query what type derived types are - /// Note that all other types can just compare to see if this == Type::xxxTy; - /// - bool isPrimitiveType() const { return getTypeID() <= LastPrimitiveTyID; } - bool isDerivedType() const { return getTypeID() >= FirstDerivedTyID; } - /// isFirstClassType - Return true if the type is "first class", meaning it /// is a valid type for a Value. /// @@ -257,9 +242,8 @@ public: /// and array types. /// bool isSingleValueType() const { - return (getTypeID() != VoidTyID && isPrimitiveType()) || - getTypeID() == IntegerTyID || getTypeID() == PointerTyID || - getTypeID() == VectorTyID; + return isFloatingPointTy() || isX86_MMXTy() || isIntegerTy() || + isPointerTy() || isVectorTy(); } /// isAggregateType - Return true if the type is an aggregate type. This @@ -275,7 +259,7 @@ public: /// get the actual size for a particular target, it is reasonable to use the /// DataLayout subsystem to do this. /// - bool isSized(SmallPtrSet *Visited = 0) const { + bool isSized(SmallPtrSetImpl *Visited = nullptr) const { // If it's a primitive, it is always sized. if (getTypeID() == IntegerTyID || isFloatingPointTy() || getTypeID() == PointerTyID || @@ -300,12 +284,12 @@ public: /// instance of the type is stored to memory. The DataLayout class provides /// additional query functions to provide this information. /// - unsigned getPrimitiveSizeInBits() const; + unsigned getPrimitiveSizeInBits() const LLVM_READONLY; /// getScalarSizeInBits - If this is a vector type, return the /// getPrimitiveSizeInBits value for the element type. Otherwise return the /// getPrimitiveSizeInBits value for this type. - unsigned getScalarSizeInBits(); + unsigned getScalarSizeInBits() const LLVM_READONLY; /// getFPMantissaWidth - Return the width of the mantissa of this type. This /// is only valid on floating point types. If the FP type does not @@ -314,8 +298,7 @@ public: /// getScalarType - If this is a vector type, return the element type, /// otherwise return 'this'. - const Type *getScalarType() const; - Type *getScalarType(); + Type *getScalarType() const LLVM_READONLY; //===--------------------------------------------------------------------===// // Type Iteration support. @@ -323,6 +306,9 @@ public: typedef Type * const *subtype_iterator; subtype_iterator subtype_begin() const { return ContainedTys; } subtype_iterator subtype_end() const { return &ContainedTys[NumContainedTys];} + ArrayRef subtypes() const { + return makeArrayRef(subtype_begin(), subtype_end()); + } typedef std::reverse_iterator subtype_reverse_iterator; subtype_reverse_iterator subtype_rbegin() const { @@ -333,7 +319,7 @@ public: } /// getContainedType - This method is used to implement the type iterator - /// (defined a the end of the file). For derived types, this returns the + /// (defined at the end of the file). For derived types, this returns the /// types 'contained' in the derived type. /// Type *getContainedType(unsigned i) const { @@ -351,19 +337,19 @@ public: // example) is shorthand for cast(Ty)->getNumElements(). This is // only intended to cover the core methods that are frequently used, helper // methods should not be added here. - + unsigned getIntegerBitWidth() const; Type *getFunctionParamType(unsigned i) const; unsigned getFunctionNumParams() const; bool isFunctionVarArg() const; - + StringRef getStructName() const; unsigned getStructNumElements() const; Type *getStructElementType(unsigned N) const; - + Type *getSequentialElementType() const; - + uint64_t getArrayNumElements() const; Type *getArrayElementType() const { return getSequentialElementType(); } @@ -374,7 +360,7 @@ public: /// \brief Get the address space of this pointer or pointer vector type. unsigned getPointerAddressSpace() const; - + //===--------------------------------------------------------------------===// // Static members exported by the Type class itself. Useful for getting // instances of Type. @@ -396,12 +382,14 @@ public: static Type *getFP128Ty(LLVMContext &C); static Type *getPPC_FP128Ty(LLVMContext &C); static Type *getX86_MMXTy(LLVMContext &C); + static Type *getTokenTy(LLVMContext &C); static IntegerType *getIntNTy(LLVMContext &C, unsigned N); static IntegerType *getInt1Ty(LLVMContext &C); static IntegerType *getInt8Ty(LLVMContext &C); static IntegerType *getInt16Ty(LLVMContext &C); static IntegerType *getInt32Ty(LLVMContext &C); static IntegerType *getInt64Ty(LLVMContext &C); + static IntegerType *getInt128Ty(LLVMContext &C); //===--------------------------------------------------------------------===// // Convenience methods for getting pointer types with one of the above builtin @@ -423,13 +411,13 @@ public: /// getPointerTo - Return a pointer to the current type. This is equivalent /// to PointerType::get(Foo, AddrSpace). - PointerType *getPointerTo(unsigned AddrSpace = 0); + PointerType *getPointerTo(unsigned AddrSpace = 0) const; private: /// isSizedDerivedType - Derived types like structures and arrays are sized /// iff all of the members of the type are sized as well. Since asking for /// their size is relatively uncommon, move this operation out of line. - bool isSizedDerivedType(SmallPtrSet *Visited = 0) const; + bool isSizedDerivedType(SmallPtrSetImpl *Visited = nullptr) const; }; // Printing of types. @@ -445,13 +433,11 @@ template <> struct isa_impl { } }; - //===----------------------------------------------------------------------===// // Provide specializations of GraphTraits to be able to treat a type as a // graph of sub types. - -template <> struct GraphTraits { +template <> struct GraphTraits { typedef Type NodeType; typedef Type::subtype_iterator ChildIteratorType; @@ -489,7 +475,7 @@ inline Type **unwrap(LLVMTypeRef* Tys) { inline LLVMTypeRef *wrap(Type **Tys) { return reinterpret_cast(const_cast(Tys)); } - + } // End llvm namespace #endif