eliminate some pointless virtual methods.

llvm-svn: 133363
This commit is contained in:
Chris Lattner 2011-06-18 22:15:47 +00:00
parent 67733f6557
commit b97d926bce
2 changed files with 38 additions and 55 deletions

View File

@ -205,10 +205,10 @@ public:
/// getTypeAtIndex - Given an index value into the type, return the type of
/// the element.
///
virtual const Type *getTypeAtIndex(const Value *V) const = 0;
virtual const Type *getTypeAtIndex(unsigned Idx) const = 0;
virtual bool indexValid(const Value *V) const = 0;
virtual bool indexValid(unsigned Idx) const = 0;
const Type *getTypeAtIndex(const Value *V) const;
const Type *getTypeAtIndex(unsigned Idx) const;
bool indexValid(const Value *V) const;
bool indexValid(unsigned Idx) const;
// Methods for support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const CompositeType *) { return true; }
@ -264,14 +264,6 @@ public:
return ContainedTys[N];
}
/// getTypeAtIndex - Given an index value into the type, return the type of
/// the element. For a structure type, this must be a constant value...
///
virtual const Type *getTypeAtIndex(const Value *V) const;
virtual const Type *getTypeAtIndex(unsigned Idx) const;
virtual bool indexValid(const Value *V) const;
virtual bool indexValid(unsigned Idx) const;
// Implement the AbstractTypeUser interface.
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
virtual void typeBecameConcrete(const DerivedType *AbsTy);
@ -306,22 +298,7 @@ protected:
}
public:
inline const Type *getElementType() const { return ContainedTys[0]; }
virtual bool indexValid(const Value *V) const;
virtual bool indexValid(unsigned) const {
return true;
}
/// getTypeAtIndex - Given an index value into the type, return the type of
/// the element. For sequential types, there is only one subtype...
///
virtual const Type *getTypeAtIndex(const Value *) const {
return ContainedTys[0];
}
virtual const Type *getTypeAtIndex(unsigned) const {
return ContainedTys[0];
}
const Type *getElementType() const { return ContainedTys[0]; }
// Methods for support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const SequentialType *) { return true; }

View File

@ -286,29 +286,41 @@ void Type::typeBecameConcrete(const DerivedType *AbsTy) {
llvm_unreachable("DerivedType is already a concrete type!");
}
bool StructType::indexValid(const Value *V) const {
// Structure indexes require 32-bit integer constants.
if (V->getType()->isIntegerTy(32))
if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
return indexValid(CU->getZExtValue());
return false;
const Type *CompositeType::getTypeAtIndex(const Value *V) const {
if (const StructType *STy = dyn_cast<StructType>(this)) {
unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
assert(indexValid(Idx) && "Invalid structure index!");
return STy->getElementType(Idx);
}
return cast<SequentialType>(this)->getElementType();
}
const Type *CompositeType::getTypeAtIndex(unsigned Idx) const {
if (const StructType *STy = dyn_cast<StructType>(this)) {
assert(indexValid(Idx) && "Invalid structure index!");
return STy->getElementType(Idx);
}
return cast<SequentialType>(this)->getElementType();
}
bool CompositeType::indexValid(const Value *V) const {
if (const StructType *STy = dyn_cast<StructType>(this)) {
// Structure indexes require 32-bit integer constants.
if (V->getType()->isIntegerTy(32))
if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
return CU->getZExtValue() < STy->getNumElements();
return false;
}
// Sequential types can be indexed by any integer.
return V->getType()->isIntegerTy();
}
bool StructType::indexValid(unsigned V) const {
return V < NumContainedTys;
}
// getTypeAtIndex - Given an index value into the type, return the type of the
// element. For a structure type, this must be a constant value...
//
const Type *StructType::getTypeAtIndex(const Value *V) const {
unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
return getTypeAtIndex(Idx);
}
const Type *StructType::getTypeAtIndex(unsigned Idx) const {
assert(indexValid(Idx) && "Invalid structure index!");
return ContainedTys[Idx];
bool CompositeType::indexValid(unsigned Idx) const {
if (const StructType *STy = dyn_cast<StructType>(this))
return Idx < STy->getNumElements();
// Sequential types can be indexed by any integer.
return true;
}
@ -1201,12 +1213,6 @@ void PointerType::typeBecameConcrete(const DerivedType *AbsTy) {
pImpl->PointerTypes.TypeBecameConcrete(this, AbsTy);
}
bool SequentialType::indexValid(const Value *V) const {
if (V->getType()->isIntegerTy())
return true;
return false;
}
namespace llvm {
raw_ostream &operator<<(raw_ostream &OS, const Type &T) {
T.print(OS);