LLVM API Documentation

llvm::Type Class Reference

Root of type hierarchy. More...

#include <Type.h>

Inheritance diagram for llvm::Type:

Inheritance graph
[legend]
Collaboration diagram for llvm::Type:

Collaboration graph
[legend]

List of all members.

Public Types

enum  TypeID {
  VoidTyID = 0, FloatTyID, DoubleTyID, X86_FP80TyID,
  FP128TyID, PPC_FP128TyID, LabelTyID, IntegerTyID,
  FunctionTyID, StructTyID, ArrayTyID, PointerTyID,
  OpaqueTyID, VectorTyID, NumTypeIDs, LastPrimitiveTyID = LabelTyID,
  FirstDerivedTyID = IntegerTyID
}
typedef PATypeHandlesubtype_iterator

Public Member Functions

void print (raw_ostream &O) const
void print (std::ostream &O) const
void dump () const
 Debugging support: print to stderr.
void dump (const Module *Context) const
 Debugging support: print to stderr (use type names from context module).
TypeID getTypeID () const
const std::string & getDescription () const
 getDescription - Return the string representation of the type...
bool isInteger () const
bool isIntOrIntVector () const
bool isFloatingPoint () const
bool isFPOrFPVector () const
bool isAbstract () const
bool canLosslesslyBitCastTo (const Type *Ty) const
 Determine if this type could be losslessly bitcast to Ty.
bool isPrimitiveType () const
bool isDerivedType () const
bool isFirstClassType () const
bool isSingleValueType () const
bool isAggregateType () const
bool isSized () const
unsigned getPrimitiveSizeInBits () const
int getFPMantissaWidth () const
const TypegetForwardedType () const
const TypegetVAArgsPromotedType () const
subtype_iterator subtype_begin () const
subtype_iterator subtype_end () const
const TypegetContainedType (unsigned i) const
unsigned getNumContainedTypes () const
void addRef () const
void dropRef () const
void addAbstractTypeUser (AbstractTypeUser *U) const
void removeAbstractTypeUser (AbstractTypeUser *U) const

Static Public Member Functions

static const TypegetPrimitiveType (TypeID IDNumber)
 getPrimitiveType - Return a type based on an identifier.
static bool classof (const Type *)
 Methods for support type inquiry through isa, cast, and dyn_cast:.

Static Public Attributes

static const TypeVoidTy = new Type(Type::VoidTyID)
static const TypeLabelTy = new Type(Type::LabelTyID)
static const TypeFloatTy = new Type(Type::FloatTyID)
static const TypeDoubleTy = new Type(Type::DoubleTyID)
static const TypeX86_FP80Ty = new Type(Type::X86_FP80TyID)
static const TypeFP128Ty = new Type(Type::FP128TyID)
static const TypePPC_FP128Ty = new Type(Type::PPC_FP128TyID)
static const IntegerTypeInt1Ty = new BuiltinIntegerType(1)
static const IntegerTypeInt8Ty = new BuiltinIntegerType(8)
static const IntegerTypeInt16Ty = new BuiltinIntegerType(16)
static const IntegerTypeInt32Ty = new BuiltinIntegerType(32)
static const IntegerTypeInt64Ty = new BuiltinIntegerType(64)

Protected Member Functions

 Type (TypeID id)
virtual ~Type ()
void setAbstract (bool Val)
unsigned getRefCount () const
unsigned getSubclassData () const
void setSubclassData (unsigned val)
void PromoteAbstractToConcrete ()

Protected Attributes

const TypeForwardType
std::vector< AbstractTypeUser * > AbstractTypeUsers
unsigned NumContainedTys
PATypeHandleContainedTys

Friends

class TypeMapBase


Detailed Description

Root of type hierarchy.

This file contains the declaration of the Type class. For more "Type" type stuff, look in DerivedTypes.h.

The instances of the Type class are immutable: once they are created, 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 in class Type and in derived classes.

Once allocated, Types are never free'd, unless they are an abstract type that is resolved to a more concrete type.

Types themself don't have a name, and can be named either by:

Opaque types are simple derived types with no state. There may be many different Opaque type objects floating around, but two are only considered identical if they are pointer equals of each other. This allows us to have two opaque types that end up resolving to different concrete types later.

Opaque types are also kinda weird and scary and different because they have to keep a list of uses of the type. When, through linking, parsing, or bitcode reading, they become resolved, they need to find and update all users of the unknown type, causing them to reference a new, more concrete type. Opaque types are deleted when their use list dwindles to zero users.

Definition at line 61 of file Type.h.


Member Typedef Documentation

Definition at line 301 of file Type.h.


Member Enumeration Documentation

Definitions of all of the base types for the Type system. Based on this value, you can cast to a "DerivedType" subclass (see DerivedTypes.h) Note: If you add an element to this, you need to add an element to the Type::getPrimitiveType function, or else things will break!

Enumerator:
VoidTyID  0: type with no size
FloatTyID  1: 32 bit floating point type
DoubleTyID  2: 64 bit floating point type
X86_FP80TyID  3: 80 bit floating point type (X87)
FP128TyID  4: 128 bit floating point type (112-bit mantissa)
PPC_FP128TyID  5: 128 bit floating point type (two 64-bits)
LabelTyID  6: Labels
IntegerTyID  7: Arbitrary bit width integers
FunctionTyID  8: Functions
StructTyID  9: Structures
ArrayTyID  10: Arrays
PointerTyID  11: Pointers
OpaqueTyID  12: Opaque: type with unknown structure
VectorTyID  13: SIMD 'packed' format, or other vector type
NumTypeIDs 
LastPrimitiveTyID 
FirstDerivedTyID 

Definition at line 69 of file Type.h.


Constructor & Destructor Documentation

llvm::Type::Type ( TypeID  id  )  [inline, explicit, protected]

Definition at line 113 of file Type.h.

virtual llvm::Type::~Type (  )  [inline, protected, virtual]

Definition at line 116 of file Type.h.

References AbstractTypeUsers.


Member Function Documentation

void llvm::Type::setAbstract ( bool  Val  )  [inline, protected]

Types can become nonabstract later, if they are refined.

Definition at line 122 of file Type.h.

unsigned llvm::Type::getRefCount (  )  const [inline, protected]

Definition at line 124 of file Type.h.

Referenced by removeAbstractTypeUser().

unsigned llvm::Type::getSubclassData (  )  const [inline, protected]

void llvm::Type::setSubclassData ( unsigned  val  )  [inline, protected]

Definition at line 127 of file Type.h.

Referenced by llvm::IntegerType::IntegerType().

void Type::print ( raw_ostream O  )  const

void Type::print ( std::ostream &  O  )  const

Definition at line 1719 of file AsmWriter.cpp.

References OS, and print().

void Type::dump (  )  const [virtual]

Debugging support: print to stderr.

Implements llvm::AbstractTypeUser.

Reimplemented in llvm::DerivedType.

Definition at line 1774 of file AsmWriter.cpp.

References llvm::errs(), llvm::raw_ostream::flush(), and print().

void Type::dump ( const Module Context  )  const

Debugging support: print to stderr (use type names from context module).

Definition at line 1778 of file AsmWriter.cpp.

References llvm::errs(), llvm::raw_ostream::flush(), and llvm::WriteTypeSymbolic().

TypeID llvm::Type::getTypeID (  )  const [inline]

getTypeID - Return the type id for the type. This will return one of the TypeID enum elements defined above.

Definition at line 178 of file Type.h.

Referenced by calcTypeName(), llvm::OpaqueType::classof(), llvm::PointerType::classof(), llvm::VectorType::classof(), llvm::ArrayType::classof(), llvm::SequentialType::classof(), llvm::StructType::classof(), llvm::CompositeType::classof(), llvm::FunctionType::classof(), llvm::IntegerType::classof(), llvm::ConstantArray::ConstantArray(), llvm::ConstantStruct::ConstantStruct(), llvm::ConstantVector::ConstantVector(), executeAddInst(), executeFCMP_OEQ(), executeFCMP_OGE(), executeFCMP_OGT(), executeFCMP_OLE(), executeFCMP_OLT(), executeFCMP_ONE(), executeFDivInst(), executeFRemInst(), executeICMP_EQ(), executeICMP_NE(), executeICMP_SGE(), executeICMP_SGT(), executeICMP_SLE(), executeICMP_SLT(), executeICMP_UGE(), executeICMP_UGT(), executeICMP_ULE(), executeICMP_ULT(), executeMulInst(), executeSubInst(), llvm::ConstantExpr::getCompareTy(), llvm::ExecutionEngine::getConstantValue(), getFloatBitCastField(), llvm::ConstantExpr::getFPToSI(), llvm::ConstantExpr::getFPToUI(), llvm::MVT::getMVT(), llvm::Constant::getNullValue(), getPrimitiveSizeInBits(), llvm::ConstantExpr::getSIToFP(), getSubElementHash(), getTypeDescription(), getTypeID(), getTypePrefix(), llvm::TargetData::getTypeSizeInBits(), llvm::ConstantExpr::getUIToFP(), llvm::MachOWriter::InitMem(), llvm::ConstantFP::isValueValidForType(), llvm::ExecutionEngine::LoadValueFromMemory(), MergeInType(), llvm::AsmPrinter::printDataDirective(), RecursiveResolveTypesI(), ReplaceFPIntrinsicWithCall(), llvm::JIT::runFunction(), llvm::ExecutionEngine::StoreValueToMemory(), TypesEqual(), llvm::Interpreter::visitVAArgInst(), and WriteTypeTable().

const std::string & Type::getDescription (  )  const

getDescription - Return the string representation of the type...

Definition at line 372 of file Type.cpp.

References AbstractTypeDescriptions, ConcreteTypeDescriptions, getOrCreateDesc(), and isAbstract().

Referenced by calcTypeName(), llvm::Interpreter::callExternalFunction(), llvm::TypeSymbolTable::insert(), print(), printTypeInt(), and llvm::WriteTypeSymbolic().

bool llvm::Type::isInteger (  )  const [inline]

bool Type::isIntOrIntVector (  )  const

isIntOrIntVector - Return true if this is an integer type or a vector of integer types.

isIntOrIntVector - Return true if this is an integer type or a vector of integer types.

Definition at line 117 of file Type.cpp.

References isInteger(), and VectorTyID.

Referenced by llvm::CastInst::castIsValid(), llvm::ConstantExpr::getFPToSI(), llvm::ConstantExpr::getFPToUI(), llvm::ConstantExpr::getSIToFP(), and llvm::ConstantExpr::getUIToFP().

bool llvm::Type::isFloatingPoint (  )  const [inline]

bool Type::isFPOrFPVector (  )  const

bool llvm::Type::isAbstract (  )  const [inline]

bool Type::canLosslesslyBitCastTo ( const Type Ty  )  const

Determine if this type could be losslessly bitcast to Ty.

canLosslesslyBitCastTo - Return true if this type could be converted with a lossless BitCast to type 'Ty'. For example, uint to int. BitCasts are valid for types of the same size only where no re-interpretation of the bits is done.

Definition at line 140 of file Type.cpp.

References isFirstClassType().

bool llvm::Type::isPrimitiveType (  )  const [inline]

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;

Definition at line 217 of file Type.h.

References LastPrimitiveTyID.

Referenced by calcTypeName(), getTypeDescription(), printTypeInt(), and ShouldNukeSymtabEntry().

bool llvm::Type::isDerivedType (  )  const [inline]

Definition at line 218 of file Type.h.

References FirstDerivedTyID.

Referenced by llvm::DerivedType::classof().

bool llvm::Type::isFirstClassType (  )  const [inline]

bool llvm::Type::isSingleValueType (  )  const [inline]

isSingleValueType - Return true if the type is a valid type for a virtual register in codegen. This includes all first-class types except struct and array types.

Definition at line 233 of file Type.h.

References IntegerTyID, LastPrimitiveTyID, PointerTyID, VectorTyID, and VoidTyID.

Referenced by llvm::SDISelAsmOperandInfo::getCallOperandValMVT(), and llvm::MachOWriter::InitMem().

bool llvm::Type::isAggregateType (  )  const [inline]

isAggregateType - Return true if the type is an aggregate type. This means it is valid as the first operand of an insertvalue or extractvalue instruction. This includes struct and array types, but does not include vector types.

Definition at line 243 of file Type.h.

References ArrayTyID, and StructTyID.

Referenced by llvm::SelectionDAGLowering::getValue().

bool llvm::Type::isSized (  )  const [inline]

isSized - Return true if it makes sense to take the size of this type. To get the actual size for a particular target, it is reasonable to use the TargetData subsystem to do this.

Definition at line 251 of file Type.h.

References ArrayTyID, IntegerTyID, isAbstract(), isFloatingPoint(), PointerTyID, StructTyID, and VectorTyID.

Referenced by llvm::ComputeMaskedBits(), llvm::SDISelAsmOperandInfo::getCallOperandValMVT(), llvm::TargetData::getTypeSizeInBits(), isObjectSmallerThan(), isSafeToEliminateVarargsCast(), and TryToOptimizeStoreOfMallocToGlobal().

unsigned Type::getPrimitiveSizeInBits (  )  const

getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type. These are fixed by LLVM and are not target dependent. This will return zero if the type does not have a size or is not a primitive type.

Definition at line 163 of file Type.cpp.

References DoubleTyID, FloatTyID, FP128TyID, getTypeID(), IntegerTyID, PPC_FP128TyID, VectorTyID, and X86_FP80TyID.

Referenced by llvm::CastInst::castIsValid(), CollectBSwapParts(), llvm::ComputeMaskedBits(), llvm::ConstantFoldCastInstruction(), llvm::ConstantFoldCompareInstruction(), llvm::ConstantFoldGetElementPtr(), llvm::ConstantFoldInstOperands(), llvm::CastInst::CreateFPCast(), llvm::CastInst::CreateIntegerCast(), llvm::CastInst::CreateSExtOrBitCast(), llvm::CastInst::CreateTruncOrBitCast(), llvm::CastInst::CreateZExtOrBitCast(), EvaluateGEPOffsetExpression(), FoldBitCast(), llvm::ConstantExpr::getBitCast(), llvm::CastInst::getCastOpcode(), llvm::VectorType::getExtendedElementVectorType(), llvm::ConstantExpr::getFPCast(), llvm::ConstantExpr::getFPExtend(), llvm::ConstantExpr::getFPTrunc(), llvm::VectorType::getInteger(), llvm::ConstantExpr::getIntegerCast(), llvm::ConstantExpr::getSExt(), llvm::ConstantExpr::getSExtOrBitCast(), llvm::ConstantExpr::getTrunc(), llvm::VectorType::getTruncatedElementVectorType(), llvm::ScalarEvolution::getTruncateOrZeroExtend(), llvm::ConstantExpr::getTruncOrBitCast(), llvm::ConstantExpr::getVFCmp(), llvm::ConstantExpr::getZExt(), llvm::ConstantExpr::getZExtOrBitCast(), InsertCastToIntPtrTy(), InstCombineLoadCast(), llvm::CastInst::isCastable(), llvm::CastInst::isEliminableCastPair(), llvm::CastInst::isNoopCast(), isSignBitCheck(), llvm::X86TargetLowering::isTruncateFree(), LowerBSWAP(), LowerCTLZ(), LowerCTPOP(), and llvm::IntrinsicLowering::LowerIntrinsicCall().

int llvm::Type::getFPMantissaWidth (  )  const [inline]

getFPMantissaWidth - Return the width of the mantissa of this type. This is only valid on scalar floating point types. If the FP type does not have a stable mantissa (e.g. ppc long double), this method returns -1.

Definition at line 274 of file Type.h.

References DoubleTyID, FloatTyID, FP128TyID, isFloatingPoint(), PPC_FP128TyID, and X86_FP80TyID.

const Type* llvm::Type::getForwardedType (  )  const [inline]

getForwardedType - Return the type that this type has been resolved to if it has been resolved to anything. This is used to implement the union-find algorithm for type resolution, and shouldn't be used by general purpose clients.

Definition at line 288 of file Type.h.

References ForwardType.

Referenced by llvm::PATypeHolder::get(), and getIndexedTypeInternal().

const Type * Type::getVAArgsPromotedType (  )  const

getVAArgsPromotedType - Return the type an argument of this type will be promoted to if passed through a variable argument function.

Definition at line 105 of file Type.cpp.

References DoubleTy, FloatTyID, getSubclassData(), Int32Ty, and IntegerTyID.

subtype_iterator llvm::Type::subtype_begin (  )  const [inline]

subtype_iterator llvm::Type::subtype_end (  )  const [inline]

const Type* llvm::Type::getContainedType ( unsigned  i  )  const [inline]

getContainedType - This method is used to implement the type iterator (defined a the end of the file). For derived types, this returns the types 'contained' in the derived type.

Definition at line 309 of file Type.h.

References ContainedTys, llvm::PATypeHandle::get(), and NumContainedTys.

Referenced by lookupFunction().

unsigned llvm::Type::getNumContainedTypes (  )  const [inline]

getNumContainedTypes - Return the number of types in the derived type.

Definition at line 316 of file Type.h.

References NumContainedTys.

Referenced by lookupFunction(), and RecursiveResolveTypesI().

const Type * Type::getPrimitiveType ( TypeID  IDNumber  )  [static]

getPrimitiveType - Return a type based on an identifier.

Definition at line 91 of file Type.cpp.

References DoubleTy, DoubleTyID, FloatTy, FloatTyID, FP128Ty, FP128TyID, LabelTy, LabelTyID, PPC_FP128Ty, PPC_FP128TyID, VoidTy, VoidTyID, X86_FP80Ty, and X86_FP80TyID.

static bool llvm::Type::classof ( const Type  )  [inline, static]

Methods for support type inquiry through isa, cast, and dyn_cast:.

Reimplemented in llvm::DerivedType, llvm::IntegerType, llvm::FunctionType, llvm::CompositeType, llvm::StructType, llvm::SequentialType, llvm::ArrayType, llvm::VectorType, llvm::PointerType, and llvm::OpaqueType.

Definition at line 334 of file Type.h.

void llvm::Type::addRef (  )  const [inline]

Definition at line 336 of file Type.h.

References isAbstract().

Referenced by llvm::DerivedType::refineAbstractTypeTo().

void llvm::Type::dropRef (  )  const [inline]

Definition at line 341 of file Type.h.

References AbstractTypeUsers, and isAbstract().

void llvm::Type::addAbstractTypeUser ( AbstractTypeUser U  )  const [inline]

addAbstractTypeUser - Notify an abstract type that there is a new user of it. This function is called primarily by the PATypeHandle class.

Definition at line 354 of file Type.h.

References AbstractTypeUsers, and isAbstract().

void Type::removeAbstractTypeUser ( AbstractTypeUser U  )  const

removeAbstractTypeUser - Notify an abstract type that a user of the class no longer has a handle to the type. This function is called primarily by the PATypeHandle class. When there are no users of the abstract type, it is annihilated, because there is no way to get a reference to it ever again.

Definition at line 1336 of file Type.cpp.

References AbstractTypeUsers, DOUT, getRefCount(), and isAbstract().

Referenced by llvm::TypeMapBase::TypeBecameConcrete(), and llvm::ValueMap< ValType, TypeClass, ConstantClass, HasLargeKey >::typeBecameConcrete().

void Type::PromoteAbstractToConcrete (  )  [protected]


Friends And Related Function Documentation

friend class TypeMapBase [friend]

Definition at line 380 of file Type.h.


Member Data Documentation

const Type* llvm::Type::ForwardType [mutable, protected]

ForwardType - This field is used to implement the union find scheme for abstract types. When types are refined to other types, this field is set to the more refined type. Only abstract types can be forwarded.

Definition at line 132 of file Type.h.

Referenced by getForwardedType(), and llvm::DerivedType::refineAbstractTypeTo().

std::vector<AbstractTypeUser *> llvm::Type::AbstractTypeUsers [mutable, protected]

AbstractTypeUsers - Implement a list of the users that need to be notified if I am a type, and I get resolved into a more concrete type.

Definition at line 138 of file Type.h.

Referenced by addAbstractTypeUser(), dropRef(), llvm::DerivedType::notifyUsesThatTypeBecameConcrete(), llvm::DerivedType::refineAbstractTypeTo(), removeAbstractTypeUser(), and ~Type().

NumContainedTys - Keeps track of how many PATypeHandle instances there are at the end of this type instance for the list of contained types. It is the subclasses responsibility to set this up. Set to 0 if there are no contained types in this type.

Definition at line 144 of file Type.h.

Referenced by llvm::DerivedType::dropAllTypeUses(), llvm::StructType::element_end(), getContainedType(), llvm::StructType::getElementType(), getNumContainedTypes(), llvm::StructType::getNumElements(), llvm::FunctionType::getNumParams(), llvm::StructType::indexValid(), llvm::FunctionType::param_end(), llvm::SequentialType::SequentialType(), and subtype_end().

ContainedTys - A pointer to the array of Types (PATypeHandle) contained by this Type. For example, this includes the arguments of a function type, the elements of a structure, the pointee of a pointer, the element type of an array, etc. This pointer may be 0 for types that don't contain other types (Integer, Double, Float). In general, the subclass should arrange for space for the PATypeHandles to be included in the allocation of the type object and set this pointer to the address of the first element. This allows the Type class to manipulate the ContainedTys without understanding the subclass's placement for this array. keeping it here also allows the subtype_* members to be implemented MUCH more efficiently, and dynamically very few types do not contain any elements.

Definition at line 157 of file Type.h.

Referenced by llvm::DerivedType::dropAllTypeUses(), llvm::StructType::element_begin(), llvm::StructType::element_end(), getContainedType(), llvm::SequentialType::getElementType(), llvm::StructType::getElementType(), llvm::FunctionType::getParamType(), llvm::FunctionType::getReturnType(), llvm::StructType::getTypeAtIndex(), llvm::SequentialType::getTypeAtIndex(), llvm::FunctionType::param_begin(), llvm::FunctionType::param_end(), llvm::SequentialType::SequentialType(), subtype_begin(), and subtype_end().

const Type * Type::VoidTy = new Type(Type::VoidTyID) [static]

const Type * Type::LabelTy = new Type(Type::LabelTyID) [static]

Definition at line 329 of file Type.h.

Referenced by getPrimitiveType().

const Type * Type::FloatTy = new Type(Type::FloatTyID) [static]

const Type * Type::DoubleTy = new Type(Type::DoubleTyID) [static]

const Type * Type::X86_FP80Ty = new Type(Type::X86_FP80TyID) [static]

const Type * Type::FP128Ty = new Type(Type::FP128TyID) [static]

const Type * Type::PPC_FP128Ty = new Type(Type::PPC_FP128TyID) [static]

const IntegerType * Type::Int1Ty = new BuiltinIntegerType(1) [static]

const IntegerType * Type::Int8Ty = new BuiltinIntegerType(8) [static]

const IntegerType * Type::Int16Ty = new BuiltinIntegerType(16) [static]

Definition at line 331 of file Type.h.

Referenced by ByteswapSCANFResults(), and llvm::MVT::getTypeForMVT().

const IntegerType * Type::Int32Ty = new BuiltinIntegerType(32) [static]