1321369Sdim//===- llvm/Type.h - Classes for handling data types ------------*- C++ -*-===// 2249259Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6249259Sdim// 7249259Sdim//===----------------------------------------------------------------------===// 8249259Sdim// 9249259Sdim// This file contains the declaration of the Type class. For more "Type" 10249259Sdim// stuff, look in DerivedTypes.h. 11249259Sdim// 12249259Sdim//===----------------------------------------------------------------------===// 13249259Sdim 14249259Sdim#ifndef LLVM_IR_TYPE_H 15249259Sdim#define LLVM_IR_TYPE_H 16249259Sdim 17249259Sdim#include "llvm/ADT/APFloat.h" 18309124Sdim#include "llvm/ADT/ArrayRef.h" 19276479Sdim#include "llvm/ADT/SmallPtrSet.h" 20276479Sdim#include "llvm/Support/CBindingWrapping.h" 21249259Sdim#include "llvm/Support/Casting.h" 22321369Sdim#include "llvm/Support/Compiler.h" 23249259Sdim#include "llvm/Support/ErrorHandling.h" 24360784Sdim#include "llvm/Support/TypeSize.h" 25321369Sdim#include <cassert> 26321369Sdim#include <cstdint> 27321369Sdim#include <iterator> 28249259Sdim 29249259Sdimnamespace llvm { 30249259Sdim 31321369Sdimtemplate<class GraphType> struct GraphTraits; 32321369Sdimclass IntegerType; 33321369Sdimclass LLVMContext; 34249259Sdimclass PointerType; 35249259Sdimclass raw_ostream; 36249259Sdimclass StringRef; 37249259Sdim 38249259Sdim/// The instances of the Type class are immutable: once they are created, 39249259Sdim/// they are never changed. Also note that only one instance of a particular 40249259Sdim/// type is ever created. Thus seeing if two types are equal is a matter of 41249259Sdim/// doing a trivial pointer comparison. To enforce that no two equal instances 42296417Sdim/// are created, Type instances can only be created via static factory methods 43249259Sdim/// in class Type and in derived classes. Once allocated, Types are never 44249259Sdim/// free'd. 45296417Sdim/// 46249259Sdimclass Type { 47249259Sdimpublic: 48249259Sdim //===--------------------------------------------------------------------===// 49249259Sdim /// Definitions of all of the base types for the Type system. Based on this 50249259Sdim /// value, you can cast to a class defined in DerivedTypes.h. 51249259Sdim /// Note: If you add an element to this, you need to add an element to the 52249259Sdim /// Type::getPrimitiveType function, or else things will break! 53249259Sdim /// Also update LLVMTypeKind and LLVMGetTypeKind () in the C binding. 54249259Sdim /// 55249259Sdim enum TypeID { 56249259Sdim // PrimitiveTypes - make sure LastPrimitiveTyID stays up to date. 57249259Sdim VoidTyID = 0, ///< 0: type with no size 58249259Sdim HalfTyID, ///< 1: 16-bit floating point type 59249259Sdim FloatTyID, ///< 2: 32-bit floating point type 60249259Sdim DoubleTyID, ///< 3: 64-bit floating point type 61249259Sdim X86_FP80TyID, ///< 4: 80-bit floating point type (X87) 62249259Sdim FP128TyID, ///< 5: 128-bit floating point type (112-bit mantissa) 63249259Sdim PPC_FP128TyID, ///< 6: 128-bit floating point type (two 64-bits, PowerPC) 64249259Sdim LabelTyID, ///< 7: Labels 65249259Sdim MetadataTyID, ///< 8: Metadata 66249259Sdim X86_MMXTyID, ///< 9: MMX vectors (64 bits, X86 specific) 67296417Sdim TokenTyID, ///< 10: Tokens 68249259Sdim 69249259Sdim // Derived types... see DerivedTypes.h file. 70249259Sdim // Make sure FirstDerivedTyID stays up to date! 71296417Sdim IntegerTyID, ///< 11: Arbitrary bit width integers 72296417Sdim FunctionTyID, ///< 12: Functions 73296417Sdim StructTyID, ///< 13: Structures 74296417Sdim ArrayTyID, ///< 14: Arrays 75296417Sdim PointerTyID, ///< 15: Pointers 76296417Sdim VectorTyID ///< 16: SIMD 'packed' format, or other vector type 77249259Sdim }; 78249259Sdim 79249259Sdimprivate: 80309124Sdim /// This refers to the LLVMContext in which this type was uniqued. 81249259Sdim LLVMContext &Context; 82249259Sdim 83296417Sdim TypeID ID : 8; // The current base type of this type. 84296417Sdim unsigned SubclassData : 24; // Space for subclasses to store data. 85314564Sdim // Note that this should be synchronized with 86314564Sdim // MAX_INT_BITS value in IntegerType class. 87249259Sdim 88249259Sdimprotected: 89249259Sdim friend class LLVMContextImpl; 90321369Sdim 91249259Sdim explicit Type(LLVMContext &C, TypeID tid) 92321369Sdim : Context(C), ID(tid), SubclassData(0) {} 93288943Sdim ~Type() = default; 94288943Sdim 95296417Sdim unsigned getSubclassData() const { return SubclassData; } 96296417Sdim 97249259Sdim void setSubclassData(unsigned val) { 98296417Sdim SubclassData = val; 99249259Sdim // Ensure we don't have any accidental truncation. 100249259Sdim assert(getSubclassData() == val && "Subclass data too large for field"); 101249259Sdim } 102249259Sdim 103309124Sdim /// Keeps track of how many Type*'s there are in the ContainedTys list. 104321369Sdim unsigned NumContainedTys = 0; 105249259Sdim 106309124Sdim /// A pointer to the array of Types contained by this Type. For example, this 107309124Sdim /// includes the arguments of a function type, the elements of a structure, 108309124Sdim /// the pointee of a pointer, the element type of an array, etc. This pointer 109309124Sdim /// may be 0 for types that don't contain other types (Integer, Double, 110309124Sdim /// Float). 111321369Sdim Type * const *ContainedTys = nullptr; 112249259Sdim 113309124Sdim static bool isSequentialType(TypeID TyID) { 114314564Sdim return TyID == ArrayTyID || TyID == VectorTyID; 115309124Sdim } 116309124Sdim 117249259Sdimpublic: 118309124Sdim /// Print the current type. 119309124Sdim /// Omit the type details if \p NoDetails == true. 120309124Sdim /// E.g., let %st = type { i32, i16 } 121309124Sdim /// When \p NoDetails is true, we only print %st. 122309124Sdim /// Put differently, \p NoDetails prints the type as if 123309124Sdim /// inlined with the operands when printing an instruction. 124309124Sdim void print(raw_ostream &O, bool IsForDebug = false, 125309124Sdim bool NoDetails = false) const; 126321369Sdim 127249259Sdim void dump() const; 128249259Sdim 129309124Sdim /// Return the LLVMContext in which this type was uniqued. 130249259Sdim LLVMContext &getContext() const { return Context; } 131249259Sdim 132249259Sdim //===--------------------------------------------------------------------===// 133249259Sdim // Accessors for working with types. 134249259Sdim // 135249259Sdim 136309124Sdim /// Return the type id for the type. This will return one of the TypeID enum 137309124Sdim /// elements defined above. 138296417Sdim TypeID getTypeID() const { return ID; } 139249259Sdim 140309124Sdim /// Return true if this is 'void'. 141249259Sdim bool isVoidTy() const { return getTypeID() == VoidTyID; } 142249259Sdim 143309124Sdim /// Return true if this is 'half', a 16-bit IEEE fp type. 144249259Sdim bool isHalfTy() const { return getTypeID() == HalfTyID; } 145249259Sdim 146309124Sdim /// Return true if this is 'float', a 32-bit IEEE fp type. 147249259Sdim bool isFloatTy() const { return getTypeID() == FloatTyID; } 148296417Sdim 149309124Sdim /// Return true if this is 'double', a 64-bit IEEE fp type. 150249259Sdim bool isDoubleTy() const { return getTypeID() == DoubleTyID; } 151249259Sdim 152309124Sdim /// Return true if this is x86 long double. 153249259Sdim bool isX86_FP80Ty() const { return getTypeID() == X86_FP80TyID; } 154249259Sdim 155309124Sdim /// Return true if this is 'fp128'. 156249259Sdim bool isFP128Ty() const { return getTypeID() == FP128TyID; } 157249259Sdim 158309124Sdim /// Return true if this is powerpc long double. 159249259Sdim bool isPPC_FP128Ty() const { return getTypeID() == PPC_FP128TyID; } 160249259Sdim 161309124Sdim /// Return true if this is one of the six floating-point types 162249259Sdim bool isFloatingPointTy() const { 163249259Sdim return getTypeID() == HalfTyID || getTypeID() == FloatTyID || 164249259Sdim getTypeID() == DoubleTyID || 165249259Sdim getTypeID() == X86_FP80TyID || getTypeID() == FP128TyID || 166249259Sdim getTypeID() == PPC_FP128TyID; 167249259Sdim } 168249259Sdim 169249259Sdim const fltSemantics &getFltSemantics() const { 170249259Sdim switch (getTypeID()) { 171314564Sdim case HalfTyID: return APFloat::IEEEhalf(); 172314564Sdim case FloatTyID: return APFloat::IEEEsingle(); 173314564Sdim case DoubleTyID: return APFloat::IEEEdouble(); 174314564Sdim case X86_FP80TyID: return APFloat::x87DoubleExtended(); 175314564Sdim case FP128TyID: return APFloat::IEEEquad(); 176314564Sdim case PPC_FP128TyID: return APFloat::PPCDoubleDouble(); 177249259Sdim default: llvm_unreachable("Invalid floating type"); 178249259Sdim } 179249259Sdim } 180249259Sdim 181309124Sdim /// Return true if this is X86 MMX. 182249259Sdim bool isX86_MMXTy() const { return getTypeID() == X86_MMXTyID; } 183249259Sdim 184309124Sdim /// Return true if this is a FP type or a vector of FP. 185249259Sdim bool isFPOrFPVectorTy() const { return getScalarType()->isFloatingPointTy(); } 186296417Sdim 187309124Sdim /// Return true if this is 'label'. 188249259Sdim bool isLabelTy() const { return getTypeID() == LabelTyID; } 189249259Sdim 190309124Sdim /// Return true if this is 'metadata'. 191249259Sdim bool isMetadataTy() const { return getTypeID() == MetadataTyID; } 192249259Sdim 193309124Sdim /// Return true if this is 'token'. 194296417Sdim bool isTokenTy() const { return getTypeID() == TokenTyID; } 195296417Sdim 196309124Sdim /// True if this is an instance of IntegerType. 197296417Sdim bool isIntegerTy() const { return getTypeID() == IntegerTyID; } 198249259Sdim 199309124Sdim /// Return true if this is an IntegerType of the given width. 200249259Sdim bool isIntegerTy(unsigned Bitwidth) const; 201249259Sdim 202309124Sdim /// Return true if this is an integer type or a vector of integer types. 203249259Sdim bool isIntOrIntVectorTy() const { return getScalarType()->isIntegerTy(); } 204296417Sdim 205321369Sdim /// Return true if this is an integer type or a vector of integer types of 206321369Sdim /// the given width. 207321369Sdim bool isIntOrIntVectorTy(unsigned BitWidth) const { 208321369Sdim return getScalarType()->isIntegerTy(BitWidth); 209321369Sdim } 210321369Sdim 211341825Sdim /// Return true if this is an integer type or a pointer type. 212341825Sdim bool isIntOrPtrTy() const { return isIntegerTy() || isPointerTy(); } 213341825Sdim 214309124Sdim /// True if this is an instance of FunctionType. 215249259Sdim bool isFunctionTy() const { return getTypeID() == FunctionTyID; } 216249259Sdim 217309124Sdim /// True if this is an instance of StructType. 218249259Sdim bool isStructTy() const { return getTypeID() == StructTyID; } 219249259Sdim 220309124Sdim /// True if this is an instance of ArrayType. 221249259Sdim bool isArrayTy() const { return getTypeID() == ArrayTyID; } 222249259Sdim 223309124Sdim /// True if this is an instance of PointerType. 224249259Sdim bool isPointerTy() const { return getTypeID() == PointerTyID; } 225249259Sdim 226309124Sdim /// Return true if this is a pointer type or a vector of pointer types. 227249259Sdim bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); } 228296417Sdim 229309124Sdim /// True if this is an instance of VectorType. 230249259Sdim bool isVectorTy() const { return getTypeID() == VectorTyID; } 231249259Sdim 232309124Sdim /// Return true if this type could be converted with a lossless BitCast to 233309124Sdim /// type 'Ty'. For example, i8* to i32*. BitCasts are valid for types of the 234309124Sdim /// same size only where no re-interpretation of the bits is done. 235341825Sdim /// Determine if this type could be losslessly bitcast to Ty 236249259Sdim bool canLosslesslyBitCastTo(Type *Ty) const; 237249259Sdim 238309124Sdim /// Return true if this type is empty, that is, it has no elements or all of 239309124Sdim /// its elements are empty. 240249259Sdim bool isEmptyTy() const; 241249259Sdim 242309124Sdim /// Return true if the type is "first class", meaning it is a valid type for a 243309124Sdim /// Value. 244249259Sdim bool isFirstClassType() const { 245249259Sdim return getTypeID() != FunctionTyID && getTypeID() != VoidTyID; 246249259Sdim } 247249259Sdim 248309124Sdim /// Return true if the type is a valid type for a register in codegen. This 249309124Sdim /// includes all first-class types except struct and array types. 250249259Sdim bool isSingleValueType() const { 251276479Sdim return isFloatingPointTy() || isX86_MMXTy() || isIntegerTy() || 252276479Sdim isPointerTy() || isVectorTy(); 253249259Sdim } 254249259Sdim 255309124Sdim /// Return true if the type is an aggregate type. This means it is valid as 256309124Sdim /// the first operand of an insertvalue or extractvalue instruction. This 257309124Sdim /// includes struct and array types, but does not include vector types. 258249259Sdim bool isAggregateType() const { 259249259Sdim return getTypeID() == StructTyID || getTypeID() == ArrayTyID; 260249259Sdim } 261249259Sdim 262309124Sdim /// Return true if it makes sense to take the size of this type. To get the 263309124Sdim /// actual size for a particular target, it is reasonable to use the 264249259Sdim /// DataLayout subsystem to do this. 265296417Sdim bool isSized(SmallPtrSetImpl<Type*> *Visited = nullptr) const { 266249259Sdim // If it's a primitive, it is always sized. 267249259Sdim if (getTypeID() == IntegerTyID || isFloatingPointTy() || 268249259Sdim getTypeID() == PointerTyID || 269249259Sdim getTypeID() == X86_MMXTyID) 270249259Sdim return true; 271249259Sdim // If it is not something that can have a size (e.g. a function or label), 272249259Sdim // it doesn't have a size. 273249259Sdim if (getTypeID() != StructTyID && getTypeID() != ArrayTyID && 274249259Sdim getTypeID() != VectorTyID) 275249259Sdim return false; 276249259Sdim // Otherwise we have to try harder to decide. 277276479Sdim return isSizedDerivedType(Visited); 278249259Sdim } 279249259Sdim 280309124Sdim /// Return the basic size of this type if it is a primitive type. These are 281309124Sdim /// fixed by LLVM and are not target-dependent. 282249259Sdim /// This will return zero if the type does not have a size or is not a 283249259Sdim /// primitive type. 284249259Sdim /// 285360784Sdim /// If this is a scalable vector type, the scalable property will be set and 286360784Sdim /// the runtime size will be a positive integer multiple of the base size. 287360784Sdim /// 288249259Sdim /// Note that this may not reflect the size of memory allocated for an 289249259Sdim /// instance of the type or the number of bytes that are written when an 290249259Sdim /// instance of the type is stored to memory. The DataLayout class provides 291249259Sdim /// additional query functions to provide this information. 292249259Sdim /// 293360784Sdim TypeSize getPrimitiveSizeInBits() const LLVM_READONLY; 294249259Sdim 295309124Sdim /// If this is a vector type, return the getPrimitiveSizeInBits value for the 296309124Sdim /// element type. Otherwise return the getPrimitiveSizeInBits value for this 297309124Sdim /// type. 298276479Sdim unsigned getScalarSizeInBits() const LLVM_READONLY; 299249259Sdim 300309124Sdim /// Return the width of the mantissa of this type. This is only valid on 301309124Sdim /// floating-point types. If the FP type does not have a stable mantissa (e.g. 302309124Sdim /// ppc long double), this method returns -1. 303249259Sdim int getFPMantissaWidth() const; 304249259Sdim 305309124Sdim /// If this is a vector type, return the element type, otherwise return 306309124Sdim /// 'this'. 307321369Sdim Type *getScalarType() const { 308321369Sdim if (isVectorTy()) 309321369Sdim return getVectorElementType(); 310321369Sdim return const_cast<Type*>(this); 311321369Sdim } 312249259Sdim 313249259Sdim //===--------------------------------------------------------------------===// 314249259Sdim // Type Iteration support. 315249259Sdim // 316321369Sdim using subtype_iterator = Type * const *; 317321369Sdim 318249259Sdim subtype_iterator subtype_begin() const { return ContainedTys; } 319249259Sdim subtype_iterator subtype_end() const { return &ContainedTys[NumContainedTys];} 320280031Sdim ArrayRef<Type*> subtypes() const { 321280031Sdim return makeArrayRef(subtype_begin(), subtype_end()); 322280031Sdim } 323249259Sdim 324321369Sdim using subtype_reverse_iterator = std::reverse_iterator<subtype_iterator>; 325321369Sdim 326261991Sdim subtype_reverse_iterator subtype_rbegin() const { 327261991Sdim return subtype_reverse_iterator(subtype_end()); 328261991Sdim } 329261991Sdim subtype_reverse_iterator subtype_rend() const { 330261991Sdim return subtype_reverse_iterator(subtype_begin()); 331261991Sdim } 332261991Sdim 333309124Sdim /// This method is used to implement the type iterator (defined at the end of 334309124Sdim /// the file). For derived types, this returns the types 'contained' in the 335309124Sdim /// derived type. 336249259Sdim Type *getContainedType(unsigned i) const { 337249259Sdim assert(i < NumContainedTys && "Index out of range!"); 338249259Sdim return ContainedTys[i]; 339249259Sdim } 340249259Sdim 341309124Sdim /// Return the number of types in the derived type. 342249259Sdim unsigned getNumContainedTypes() const { return NumContainedTys; } 343249259Sdim 344249259Sdim //===--------------------------------------------------------------------===// 345249259Sdim // Helper methods corresponding to subclass methods. This forces a cast to 346249259Sdim // the specified subclass and calls its accessor. "getVectorNumElements" (for 347249259Sdim // example) is shorthand for cast<VectorType>(Ty)->getNumElements(). This is 348249259Sdim // only intended to cover the core methods that are frequently used, helper 349249259Sdim // methods should not be added here. 350249259Sdim 351296417Sdim inline unsigned getIntegerBitWidth() const; 352296417Sdim 353296417Sdim inline Type *getFunctionParamType(unsigned i) const; 354296417Sdim inline unsigned getFunctionNumParams() const; 355296417Sdim inline bool isFunctionVarArg() const; 356296417Sdim 357296417Sdim inline StringRef getStructName() const; 358296417Sdim inline unsigned getStructNumElements() const; 359296417Sdim inline Type *getStructElementType(unsigned N) const; 360296417Sdim 361309124Sdim inline Type *getSequentialElementType() const { 362309124Sdim assert(isSequentialType(getTypeID()) && "Not a sequential type!"); 363309124Sdim return ContainedTys[0]; 364309124Sdim } 365296417Sdim 366296417Sdim inline uint64_t getArrayNumElements() const; 367321369Sdim 368314564Sdim Type *getArrayElementType() const { 369314564Sdim assert(getTypeID() == ArrayTyID); 370314564Sdim return ContainedTys[0]; 371314564Sdim } 372249259Sdim 373353358Sdim inline bool getVectorIsScalable() const; 374296417Sdim inline unsigned getVectorNumElements() const; 375360784Sdim inline ElementCount getVectorElementCount() const; 376314564Sdim Type *getVectorElementType() const { 377314564Sdim assert(getTypeID() == VectorTyID); 378314564Sdim return ContainedTys[0]; 379314564Sdim } 380249259Sdim 381314564Sdim Type *getPointerElementType() const { 382314564Sdim assert(getTypeID() == PointerTyID); 383314564Sdim return ContainedTys[0]; 384314564Sdim } 385249259Sdim 386360784Sdim /// Given an integer or vector type, change the lane bitwidth to NewBitwidth, 387360784Sdim /// whilst keeping the old number of lanes. 388360784Sdim inline Type *getWithNewBitWidth(unsigned NewBitWidth) const; 389360784Sdim 390360784Sdim /// Given scalar/vector integer type, returns a type with elements twice as 391360784Sdim /// wide as in the original type. For vectors, preserves element count. 392360784Sdim inline Type *getExtendedType() const; 393360784Sdim 394309124Sdim /// Get the address space of this pointer or pointer vector type. 395296417Sdim inline unsigned getPointerAddressSpace() const; 396296417Sdim 397249259Sdim //===--------------------------------------------------------------------===// 398249259Sdim // Static members exported by the Type class itself. Useful for getting 399249259Sdim // instances of Type. 400249259Sdim // 401249259Sdim 402309124Sdim /// Return a type based on an identifier. 403249259Sdim static Type *getPrimitiveType(LLVMContext &C, TypeID IDNumber); 404249259Sdim 405249259Sdim //===--------------------------------------------------------------------===// 406249259Sdim // These are the builtin types that are always available. 407249259Sdim // 408249259Sdim static Type *getVoidTy(LLVMContext &C); 409249259Sdim static Type *getLabelTy(LLVMContext &C); 410249259Sdim static Type *getHalfTy(LLVMContext &C); 411249259Sdim static Type *getFloatTy(LLVMContext &C); 412249259Sdim static Type *getDoubleTy(LLVMContext &C); 413249259Sdim static Type *getMetadataTy(LLVMContext &C); 414249259Sdim static Type *getX86_FP80Ty(LLVMContext &C); 415249259Sdim static Type *getFP128Ty(LLVMContext &C); 416249259Sdim static Type *getPPC_FP128Ty(LLVMContext &C); 417249259Sdim static Type *getX86_MMXTy(LLVMContext &C); 418296417Sdim static Type *getTokenTy(LLVMContext &C); 419249259Sdim static IntegerType *getIntNTy(LLVMContext &C, unsigned N); 420249259Sdim static IntegerType *getInt1Ty(LLVMContext &C); 421249259Sdim static IntegerType *getInt8Ty(LLVMContext &C); 422249259Sdim static IntegerType *getInt16Ty(LLVMContext &C); 423249259Sdim static IntegerType *getInt32Ty(LLVMContext &C); 424249259Sdim static IntegerType *getInt64Ty(LLVMContext &C); 425288943Sdim static IntegerType *getInt128Ty(LLVMContext &C); 426341825Sdim template <typename ScalarTy> static Type *getScalarTy(LLVMContext &C) { 427341825Sdim int noOfBits = sizeof(ScalarTy) * CHAR_BIT; 428341825Sdim if (std::is_integral<ScalarTy>::value) { 429341825Sdim return (Type*) Type::getIntNTy(C, noOfBits); 430341825Sdim } else if (std::is_floating_point<ScalarTy>::value) { 431341825Sdim switch (noOfBits) { 432341825Sdim case 32: 433341825Sdim return Type::getFloatTy(C); 434341825Sdim case 64: 435341825Sdim return Type::getDoubleTy(C); 436341825Sdim } 437341825Sdim } 438341825Sdim llvm_unreachable("Unsupported type in Type::getScalarTy"); 439341825Sdim } 440296417Sdim 441249259Sdim //===--------------------------------------------------------------------===// 442249259Sdim // Convenience methods for getting pointer types with one of the above builtin 443249259Sdim // types as pointee. 444249259Sdim // 445249259Sdim static PointerType *getHalfPtrTy(LLVMContext &C, unsigned AS = 0); 446249259Sdim static PointerType *getFloatPtrTy(LLVMContext &C, unsigned AS = 0); 447249259Sdim static PointerType *getDoublePtrTy(LLVMContext &C, unsigned AS = 0); 448249259Sdim static PointerType *getX86_FP80PtrTy(LLVMContext &C, unsigned AS = 0); 449249259Sdim static PointerType *getFP128PtrTy(LLVMContext &C, unsigned AS = 0); 450249259Sdim static PointerType *getPPC_FP128PtrTy(LLVMContext &C, unsigned AS = 0); 451249259Sdim static PointerType *getX86_MMXPtrTy(LLVMContext &C, unsigned AS = 0); 452249259Sdim static PointerType *getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS = 0); 453249259Sdim static PointerType *getInt1PtrTy(LLVMContext &C, unsigned AS = 0); 454249259Sdim static PointerType *getInt8PtrTy(LLVMContext &C, unsigned AS = 0); 455249259Sdim static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0); 456249259Sdim static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0); 457249259Sdim static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0); 458249259Sdim 459309124Sdim /// Return a pointer to the current type. This is equivalent to 460309124Sdim /// PointerType::get(Foo, AddrSpace). 461296417Sdim PointerType *getPointerTo(unsigned AddrSpace = 0) const; 462249259Sdim 463249259Sdimprivate: 464309124Sdim /// Derived types like structures and arrays are sized iff all of the members 465309124Sdim /// of the type are sized as well. Since asking for their size is relatively 466309124Sdim /// uncommon, move this operation out-of-line. 467296417Sdim bool isSizedDerivedType(SmallPtrSetImpl<Type*> *Visited = nullptr) const; 468249259Sdim}; 469249259Sdim 470249259Sdim// Printing of types. 471327952Sdiminline raw_ostream &operator<<(raw_ostream &OS, const Type &T) { 472249259Sdim T.print(OS); 473249259Sdim return OS; 474249259Sdim} 475249259Sdim 476249259Sdim// allow isa<PointerType>(x) to work without DerivedTypes.h included. 477249259Sdimtemplate <> struct isa_impl<PointerType, Type> { 478249259Sdim static inline bool doit(const Type &Ty) { 479249259Sdim return Ty.getTypeID() == Type::PointerTyID; 480249259Sdim } 481249259Sdim}; 482249259Sdim 483251662Sdim// Create wrappers for C Binding types (see CBindingWrapping.h). 484251662SdimDEFINE_ISA_CONVERSION_FUNCTIONS(Type, LLVMTypeRef) 485251662Sdim 486251662Sdim/* Specialized opaque type conversions. 487251662Sdim */ 488251662Sdiminline Type **unwrap(LLVMTypeRef* Tys) { 489251662Sdim return reinterpret_cast<Type**>(Tys); 490251662Sdim} 491251662Sdim 492251662Sdiminline LLVMTypeRef *wrap(Type **Tys) { 493251662Sdim return reinterpret_cast<LLVMTypeRef*>(const_cast<Type**>(Tys)); 494251662Sdim} 495296417Sdim 496321369Sdim} // end namespace llvm 497249259Sdim 498321369Sdim#endif // LLVM_IR_TYPE_H 499