diff options
author | Chris Lattner <sabre@nondot.org> | 2011-06-18 22:15:47 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-06-18 22:15:47 +0000 |
commit | ea049181a020b233cfd8a33583e2784d590e1dcb (patch) | |
tree | 790508d7d7f2f13cc8f4c2ad8909b6f160eda627 /lib/VMCore/Type.cpp | |
parent | ebb2189904564c7c6193e7f23904f1ced7975480 (diff) | |
download | llvm-ea049181a020b233cfd8a33583e2784d590e1dcb.tar.gz llvm-ea049181a020b233cfd8a33583e2784d590e1dcb.tar.bz2 llvm-ea049181a020b233cfd8a33583e2784d590e1dcb.tar.xz |
eliminate some pointless virtual methods.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Type.cpp')
-rw-r--r-- | lib/VMCore/Type.cpp | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 6c348be18f..ebe431bdc2 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -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; -} - -bool StructType::indexValid(unsigned V) const { - return V < NumContainedTys; +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(); } - -// 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 *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(); } -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); |