2003-09-30 18:37:50 +00:00
|
|
|
//===-- llvm/DerivedTypes.h - Classes for handling data types ---*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2005-04-21 20:19:05 +00:00
|
|
|
// This file contains the declarations of classes that represent "derived
|
2001-06-06 20:29:01 +00:00
|
|
|
// types". These are things like "arrays of x" or "structure of x, y, z" or
|
|
|
|
// "method returning x taking (y,z) as parameters", etc...
|
|
|
|
//
|
|
|
|
// The implementations of these classes live in the Type.cpp file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_DERIVED_TYPES_H
|
|
|
|
#define LLVM_DERIVED_TYPES_H
|
|
|
|
|
|
|
|
#include "llvm/Type.h"
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2004-07-08 15:54:29 +00:00
|
|
|
class Value;
|
2003-09-05 02:30:18 +00:00
|
|
|
template<class ValType, class TypeClass> class TypeMap;
|
|
|
|
class FunctionValType;
|
|
|
|
class ArrayValType;
|
|
|
|
class StructValType;
|
|
|
|
class PointerValType;
|
2007-02-15 02:26:10 +00:00
|
|
|
class VectorValType;
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
class IntegerValType;
|
2007-03-01 04:02:06 +00:00
|
|
|
class APInt;
|
2003-09-05 02:30:18 +00:00
|
|
|
|
2005-11-13 03:26:12 +00:00
|
|
|
class DerivedType : public Type {
|
2004-10-07 19:21:43 +00:00
|
|
|
friend class Type;
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
protected:
|
2007-03-23 18:44:11 +00:00
|
|
|
explicit DerivedType(TypeID id) : Type(id) {}
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
/// notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type
|
|
|
|
/// that the current type has transitioned from being abstract to being
|
|
|
|
/// concrete.
|
|
|
|
///
|
|
|
|
void notifyUsesThatTypeBecameConcrete();
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// dropAllTypeUses - When this (abstract) type is resolved to be equal to
|
|
|
|
/// another (more concrete) type, we must eliminate all references to other
|
|
|
|
/// types, to avoid some circular reference problems.
|
|
|
|
///
|
2004-02-09 05:40:24 +00:00
|
|
|
void dropAllTypeUses();
|
2004-02-17 02:58:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2001-09-07 16:19:29 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Abstract Type handling methods - These types have special lifetimes, which
|
|
|
|
// are managed by (add|remove)AbstractTypeUser. See comments in
|
|
|
|
// AbstractTypeUser.h for more information.
|
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// refineAbstractTypeTo - This function is used to when it is discovered that
|
|
|
|
/// the 'this' abstract type is actually equivalent to the NewType specified.
|
|
|
|
/// This causes all users of 'this' to switch to reference the more concrete
|
|
|
|
/// type NewType and for 'this' to be deleted.
|
|
|
|
///
|
2003-10-03 18:57:54 +00:00
|
|
|
void refineAbstractTypeTo(const Type *NewType);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2004-05-25 08:45:42 +00:00
|
|
|
void dump() const { Type::dump(); }
|
2003-10-02 19:44:23 +00:00
|
|
|
|
2001-10-01 18:26:53 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const DerivedType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2001-10-01 18:26:53 +00:00
|
|
|
return T->isDerivedType();
|
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
};
|
|
|
|
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
/// Class to represent integer types. Note that this class is also used to
|
|
|
|
/// represent the built-in integer types: Int1Ty, Int8Ty, Int16Ty, Int32Ty and
|
|
|
|
/// Int64Ty.
|
|
|
|
/// @brief Integer representation type
|
|
|
|
class IntegerType : public DerivedType {
|
|
|
|
protected:
|
2007-03-23 18:44:11 +00:00
|
|
|
explicit IntegerType(unsigned NumBits) : DerivedType(IntegerTyID) {
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
setSubclassData(NumBits);
|
|
|
|
}
|
|
|
|
friend class TypeMap<IntegerValType, IntegerType>;
|
|
|
|
public:
|
|
|
|
/// This enum is just used to hold constants we need for IntegerType.
|
|
|
|
enum {
|
|
|
|
MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified
|
|
|
|
MAX_INT_BITS = (1<<23)-1 ///< Maximum number of bits that can be specified
|
|
|
|
///< Note that bit width is stored in the Type classes SubclassData field
|
|
|
|
///< which has 23 bits. This yields a maximum bit width of 8,388,607 bits.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This static method is the primary way of constructing an IntegerType.
|
|
|
|
/// If an IntegerType with the same NumBits value was previously instantiated,
|
|
|
|
/// that instance will be returned. Otherwise a new one will be created. Only
|
|
|
|
/// one instance with a given NumBits value is ever created.
|
|
|
|
/// @brief Get or create an IntegerType instance.
|
|
|
|
static const IntegerType* get(unsigned NumBits);
|
|
|
|
|
|
|
|
/// @brief Get the number of bits in this IntegerType
|
|
|
|
unsigned getBitWidth() const { return getSubclassData(); }
|
|
|
|
|
2007-01-19 21:13:56 +00:00
|
|
|
/// getBitMask - Return a bitmask with ones set for all of the bits
|
|
|
|
/// that can be set by an unsigned version of this type. This is 0xFF for
|
|
|
|
/// sbyte/ubyte, 0xFFFF for shorts, etc.
|
|
|
|
uint64_t getBitMask() const {
|
2007-03-04 23:33:19 +00:00
|
|
|
return ~uint64_t(0UL) >> (64-getBitWidth());
|
2007-01-19 21:13:56 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 23:33:19 +00:00
|
|
|
/// getSignBit - Return a uint64_t with just the most significant bit set (the
|
|
|
|
/// sign bit, if the value is treated as a signed number).
|
|
|
|
uint64_t getSignBit() const {
|
|
|
|
return 1ULL << (getBitWidth()-1);
|
|
|
|
}
|
|
|
|
|
2007-03-01 02:25:03 +00:00
|
|
|
/// For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
|
|
|
|
/// @returns a bit mask with ones set for all the bits of this type.
|
|
|
|
/// @brief Get a bit mask for this type.
|
2007-03-01 04:02:06 +00:00
|
|
|
APInt getMask() const;
|
2007-03-01 02:25:03 +00:00
|
|
|
|
2007-01-18 02:59:54 +00:00
|
|
|
/// This method determines if the width of this IntegerType is a power-of-2
|
|
|
|
/// in terms of 8 bit bytes.
|
|
|
|
/// @returns true if this is a power-of-2 byte width.
|
|
|
|
/// @brief Is this a power-of-2 byte-width IntegerType ?
|
|
|
|
bool isPowerOf2ByteWidth() const;
|
|
|
|
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const IntegerType *T) { return true; }
|
2007-01-12 22:11:53 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
|
|
|
return T->getTypeID() == IntegerTyID;
|
|
|
|
}
|
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33113 91177308-0d34-0410-b5e6-96231b3b80d8
2007-01-12 07:05:14 +00:00
|
|
|
};
|
|
|
|
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// FunctionType - Class to represent function types
|
|
|
|
///
|
2004-02-09 04:12:57 +00:00
|
|
|
class FunctionType : public DerivedType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<FunctionValType, FunctionType>;
|
2001-07-25 22:47:55 +00:00
|
|
|
bool isVarArgs;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 03:15:32 +00:00
|
|
|
FunctionType(const FunctionType &); // Do not implement
|
|
|
|
const FunctionType &operator=(const FunctionType &); // Do not implement
|
2005-04-21 20:19:05 +00:00
|
|
|
FunctionType(const Type *Result, const std::vector<const Type*> &Params,
|
2007-11-27 13:23:08 +00:00
|
|
|
bool IsVarArgs);
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// FunctionType::get - This static method is the primary way of constructing
|
2006-12-31 05:22:12 +00:00
|
|
|
/// a FunctionType.
|
2004-02-10 21:49:59 +00:00
|
|
|
///
|
2006-12-31 05:22:12 +00:00
|
|
|
static FunctionType *get(
|
|
|
|
const Type *Result, ///< The result type
|
|
|
|
const std::vector<const Type*> &Params, ///< The types of the parameters
|
2007-11-27 13:23:08 +00:00
|
|
|
bool isVarArg ///< Whether this is a variable argument length function
|
2006-12-31 05:22:12 +00:00
|
|
|
);
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-07-25 22:47:55 +00:00
|
|
|
inline bool isVarArg() const { return isVarArgs; }
|
2004-02-09 05:40:24 +00:00
|
|
|
inline const Type *getReturnType() const { return ContainedTys[0]; }
|
2004-02-09 04:12:57 +00:00
|
|
|
|
2007-04-06 02:02:20 +00:00
|
|
|
typedef Type::subtype_iterator param_iterator;
|
|
|
|
param_iterator param_begin() const { return ContainedTys + 1; }
|
|
|
|
param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2002-03-29 19:04:19 +00:00
|
|
|
// Parameter type accessors...
|
2004-02-09 05:40:24 +00:00
|
|
|
const Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
|
2002-03-29 19:04:19 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// getNumParams - Return the number of fixed parameters this function type
|
|
|
|
/// requires. This does not consider varargs.
|
|
|
|
///
|
2007-04-06 02:02:20 +00:00
|
|
|
unsigned getNumParams() const { return NumContainedTys - 1; }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2001-10-01 16:18:37 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2002-03-29 03:15:32 +00:00
|
|
|
static inline bool classof(const FunctionType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == FunctionTyID;
|
2001-10-01 16:18:37 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-20 06:00:58 +00:00
|
|
|
/// CompositeType - Common super class of ArrayType, StructType, PointerType
|
2007-02-15 02:26:10 +00:00
|
|
|
/// and VectorType
|
2001-11-26 16:46:45 +00:00
|
|
|
class CompositeType : public DerivedType {
|
|
|
|
protected:
|
2007-03-23 18:44:11 +00:00
|
|
|
inline explicit CompositeType(TypeID id) : DerivedType(id) { }
|
2001-11-26 16:46:45 +00:00
|
|
|
public:
|
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// getTypeAtIndex - Given an index value into the type, return the type of
|
|
|
|
/// the element.
|
|
|
|
///
|
2001-11-26 16:46:45 +00:00
|
|
|
virtual const Type *getTypeAtIndex(const Value *V) const = 0;
|
|
|
|
virtual bool indexValid(const Value *V) const = 0;
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const CompositeType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2005-04-21 20:19:05 +00:00
|
|
|
return T->getTypeID() == ArrayTyID ||
|
2004-06-17 18:19:28 +00:00
|
|
|
T->getTypeID() == StructTyID ||
|
2004-08-20 06:00:58 +00:00
|
|
|
T->getTypeID() == PointerTyID ||
|
2007-02-15 02:26:10 +00:00
|
|
|
T->getTypeID() == VectorTyID;
|
2001-11-26 16:46:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// StructType - Class to represent struct types
|
|
|
|
///
|
2004-02-09 04:36:50 +00:00
|
|
|
class StructType : public CompositeType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<StructValType, StructType>;
|
2001-12-14 16:20:21 +00:00
|
|
|
StructType(const StructType &); // Do not implement
|
|
|
|
const StructType &operator=(const StructType &); // Do not implement
|
2006-12-08 18:06:16 +00:00
|
|
|
StructType(const std::vector<const Type*> &Types, bool isPacked);
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// StructType::get - This static method is the primary way to create a
|
|
|
|
/// StructType.
|
2004-02-10 21:49:59 +00:00
|
|
|
///
|
2006-12-08 18:06:16 +00:00
|
|
|
static StructType *get(const std::vector<const Type*> &Params,
|
|
|
|
bool isPacked=false);
|
2003-10-03 18:46:24 +00:00
|
|
|
|
2004-02-09 04:36:50 +00:00
|
|
|
// Iterator access to the elements
|
2007-04-06 02:02:20 +00:00
|
|
|
typedef Type::subtype_iterator element_iterator;
|
|
|
|
element_iterator element_begin() const { return ContainedTys; }
|
|
|
|
element_iterator element_end() const { return &ContainedTys[NumContainedTys];}
|
2004-02-09 04:36:50 +00:00
|
|
|
|
|
|
|
// Random access to the elements
|
2007-04-06 02:02:20 +00:00
|
|
|
unsigned getNumElements() const { return NumContainedTys; }
|
2004-02-09 04:36:50 +00:00
|
|
|
const Type *getElementType(unsigned N) const {
|
2007-04-06 02:02:20 +00:00
|
|
|
assert(N < NumContainedTys && "Element number out of range!");
|
2004-02-09 05:40:24 +00:00
|
|
|
return ContainedTys[N];
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// getTypeAtIndex - Given an index value into the type, return the type of
|
|
|
|
/// the element. For a structure type, this must be a constant value...
|
|
|
|
///
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual const Type *getTypeAtIndex(const Value *V) const ;
|
|
|
|
virtual bool indexValid(const Value *V) const;
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-12-14 16:20:21 +00:00
|
|
|
static inline bool classof(const StructType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == StructTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2006-12-08 18:06:16 +00:00
|
|
|
|
2007-10-17 14:56:40 +00:00
|
|
|
bool isPacked() const { return (0 != getSubclassData()) ? true : false; }
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2001-07-23 05:03:15 +00:00
|
|
|
|
2007-07-16 14:29:03 +00:00
|
|
|
/// SequentialType - This is the superclass of the array, pointer and vector
|
2004-08-20 06:00:58 +00:00
|
|
|
/// type classes. All of these represent "arrays" in memory. The array type
|
2004-02-10 21:49:59 +00:00
|
|
|
/// represents a specifically sized array, pointer types are unsized/unknown
|
2007-02-15 03:39:18 +00:00
|
|
|
/// size arrays, vector types represent specifically sized arrays that
|
2005-04-21 20:19:05 +00:00
|
|
|
/// allow for use of SIMD instructions. SequentialType holds the common
|
|
|
|
/// features of all, which stem from the fact that all three lay their
|
2004-08-20 06:00:58 +00:00
|
|
|
/// components out in memory identically.
|
2004-02-10 21:49:59 +00:00
|
|
|
///
|
2001-12-14 16:20:21 +00:00
|
|
|
class SequentialType : public CompositeType {
|
2007-04-06 02:02:20 +00:00
|
|
|
PATypeHandle ContainedType; ///< Storage for the single contained type
|
2001-12-14 16:20:21 +00:00
|
|
|
SequentialType(const SequentialType &); // Do not implement!
|
|
|
|
const SequentialType &operator=(const SequentialType &); // Do not implement!
|
2007-10-17 14:56:40 +00:00
|
|
|
|
|
|
|
// avoiding warning: 'this' : used in base member initializer list
|
|
|
|
SequentialType* this_() { return this; }
|
2001-06-06 20:29:01 +00:00
|
|
|
protected:
|
2007-04-06 02:02:20 +00:00
|
|
|
SequentialType(TypeID TID, const Type *ElType)
|
2007-10-17 14:56:40 +00:00
|
|
|
: CompositeType(TID), ContainedType(ElType, this_()) {
|
2007-04-06 02:02:20 +00:00
|
|
|
ContainedTys = &ContainedType;
|
|
|
|
NumContainedTys = 1;
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
2003-09-05 02:15:36 +00:00
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2004-02-09 05:40:24 +00:00
|
|
|
inline const Type *getElementType() const { return ContainedTys[0]; }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2004-07-04 10:48:27 +00:00
|
|
|
virtual bool indexValid(const Value *V) const;
|
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// getTypeAtIndex - Given an index value into the type, return the type of
|
|
|
|
/// the element. For sequential types, there is only one subtype...
|
|
|
|
///
|
2001-12-14 16:20:21 +00:00
|
|
|
virtual const Type *getTypeAtIndex(const Value *V) const {
|
2004-02-09 05:40:24 +00:00
|
|
|
return ContainedTys[0];
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2001-12-14 16:20:21 +00:00
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SequentialType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == ArrayTyID ||
|
2004-08-20 06:00:58 +00:00
|
|
|
T->getTypeID() == PointerTyID ||
|
2007-02-15 02:26:10 +00:00
|
|
|
T->getTypeID() == VectorTyID;
|
2001-12-14 16:20:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// ArrayType - Class to represent array types
|
|
|
|
///
|
2001-12-14 16:20:21 +00:00
|
|
|
class ArrayType : public SequentialType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<ArrayValType, ArrayType>;
|
2005-01-08 20:19:27 +00:00
|
|
|
uint64_t NumElements;
|
2001-12-14 16:20:21 +00:00
|
|
|
|
|
|
|
ArrayType(const ArrayType &); // Do not implement
|
|
|
|
const ArrayType &operator=(const ArrayType &); // Do not implement
|
2005-01-08 20:19:27 +00:00
|
|
|
ArrayType(const Type *ElType, uint64_t NumEl);
|
2001-12-14 16:20:21 +00:00
|
|
|
public:
|
2003-10-03 18:46:24 +00:00
|
|
|
/// ArrayType::get - This static method is the primary way to construct an
|
|
|
|
/// ArrayType
|
2004-02-10 21:49:59 +00:00
|
|
|
///
|
2005-01-08 20:19:27 +00:00
|
|
|
static ArrayType *get(const Type *ElementType, uint64_t NumElements);
|
2003-10-03 18:46:24 +00:00
|
|
|
|
2005-01-08 20:19:27 +00:00
|
|
|
inline uint64_t getNumElements() const { return NumElements; }
|
2001-11-26 16:46:45 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2001-12-14 16:20:21 +00:00
|
|
|
static inline bool classof(const ArrayType *T) { return true; }
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == ArrayTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-07-23 05:03:15 +00:00
|
|
|
};
|
2001-07-20 21:09:17 +00:00
|
|
|
|
2007-02-15 03:39:18 +00:00
|
|
|
/// VectorType - Class to represent vector types
|
2004-08-20 06:00:58 +00:00
|
|
|
///
|
2007-02-15 02:26:10 +00:00
|
|
|
class VectorType : public SequentialType {
|
|
|
|
friend class TypeMap<VectorValType, VectorType>;
|
2004-08-20 06:00:58 +00:00
|
|
|
unsigned NumElements;
|
|
|
|
|
2007-02-15 02:26:10 +00:00
|
|
|
VectorType(const VectorType &); // Do not implement
|
|
|
|
const VectorType &operator=(const VectorType &); // Do not implement
|
|
|
|
VectorType(const Type *ElType, unsigned NumEl);
|
2004-08-20 06:00:58 +00:00
|
|
|
public:
|
2007-02-15 02:26:10 +00:00
|
|
|
/// VectorType::get - This static method is the primary way to construct an
|
|
|
|
/// VectorType
|
2004-08-20 06:00:58 +00:00
|
|
|
///
|
2007-02-15 02:26:10 +00:00
|
|
|
static VectorType *get(const Type *ElementType, unsigned NumElements);
|
2004-08-20 06:00:58 +00:00
|
|
|
|
2007-02-15 02:26:10 +00:00
|
|
|
/// @brief Return the number of elements in the Vector type.
|
2004-10-19 05:49:46 +00:00
|
|
|
inline unsigned getNumElements() const { return NumElements; }
|
2004-08-20 06:00:58 +00:00
|
|
|
|
2007-02-15 02:26:10 +00:00
|
|
|
/// @brief Return the number of bits in the Vector type.
|
2006-11-15 03:02:41 +00:00
|
|
|
inline unsigned getBitWidth() const {
|
|
|
|
return NumElements *getElementType()->getPrimitiveSizeInBits();
|
|
|
|
}
|
|
|
|
|
2004-08-20 06:00:58 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
|
|
|
|
|
|
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2007-02-15 02:26:10 +00:00
|
|
|
static inline bool classof(const VectorType *T) { return true; }
|
2004-08-20 06:00:58 +00:00
|
|
|
static inline bool classof(const Type *T) {
|
2007-02-15 02:26:10 +00:00
|
|
|
return T->getTypeID() == VectorTyID;
|
2004-08-20 06:00:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-07-20 21:09:17 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// PointerType - Class to represent pointers
|
|
|
|
///
|
2001-12-14 16:20:21 +00:00
|
|
|
class PointerType : public SequentialType {
|
2003-09-05 02:30:18 +00:00
|
|
|
friend class TypeMap<PointerValType, PointerType>;
|
2007-12-11 08:59:05 +00:00
|
|
|
unsigned AddressSpace;
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
PointerType(const PointerType &); // Do not implement
|
|
|
|
const PointerType &operator=(const PointerType &); // Do not implement
|
2007-12-11 08:59:05 +00:00
|
|
|
explicit PointerType(const Type *ElType, unsigned AddrSpace);
|
2001-06-06 20:29:01 +00:00
|
|
|
public:
|
2007-12-17 01:12:55 +00:00
|
|
|
/// PointerType::get - This constructs a pointer to an object of the specified
|
|
|
|
/// type in a numbered address space.
|
|
|
|
static PointerType *get(const Type *ElementType, unsigned AddressSpace);
|
|
|
|
|
|
|
|
/// PointerType::getUnqual - This constructs a pointer to an object of the
|
|
|
|
/// specified type in the generic address space (address space zero).
|
|
|
|
static PointerType *getUnqual(const Type *ElementType) {
|
|
|
|
return PointerType::get(ElementType, 0);
|
|
|
|
}
|
2007-12-11 08:59:05 +00:00
|
|
|
|
|
|
|
/// @brief Return the address space of the Pointer type.
|
|
|
|
inline unsigned getAddressSpace() const { return AddressSpace; }
|
2001-09-07 16:19:29 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement the AbstractTypeUser interface.
|
2001-09-07 16:19:29 +00:00
|
|
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
|
2003-10-03 18:46:24 +00:00
|
|
|
virtual void typeBecameConcrete(const DerivedType *AbsTy);
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement support type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const PointerType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == PointerTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-09-07 16:19:29 +00:00
|
|
|
};
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2004-02-10 21:49:59 +00:00
|
|
|
/// OpaqueType - Class to represent abstract types
|
|
|
|
///
|
2001-09-07 16:19:29 +00:00
|
|
|
class OpaqueType : public DerivedType {
|
2003-09-01 16:38:43 +00:00
|
|
|
OpaqueType(const OpaqueType &); // DO NOT IMPLEMENT
|
|
|
|
const OpaqueType &operator=(const OpaqueType &); // DO NOT IMPLEMENT
|
2001-09-07 16:19:29 +00:00
|
|
|
OpaqueType();
|
|
|
|
public:
|
2004-02-10 21:49:59 +00:00
|
|
|
/// OpaqueType::get - Static factory method for the OpaqueType class...
|
|
|
|
///
|
2001-09-07 16:19:29 +00:00
|
|
|
static OpaqueType *get() {
|
|
|
|
return new OpaqueType(); // All opaque types are distinct
|
2001-07-20 19:09:11 +00:00
|
|
|
}
|
2001-10-01 18:26:53 +00:00
|
|
|
|
2003-10-03 18:46:24 +00:00
|
|
|
// Implement support for type inquiry through isa, cast, and dyn_cast:
|
2001-10-02 03:41:24 +00:00
|
|
|
static inline bool classof(const OpaqueType *T) { return true; }
|
|
|
|
static inline bool classof(const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
return T->getTypeID() == OpaqueTyID;
|
2001-10-01 18:26:53 +00:00
|
|
|
}
|
2001-06-06 20:29:01 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-06-06 20:29:01 +00:00
|
|
|
#endif
|