From ea049181a020b233cfd8a33583e2784d590e1dcb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 18 Jun 2011 22:15:47 +0000 Subject: eliminate some pointless virtual methods. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133363 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Type.cpp | 58 +++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 26 deletions(-) (limited to 'lib/VMCore/Type.cpp') 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(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(this)) { + unsigned Idx = (unsigned)cast(V)->getZExtValue(); + assert(indexValid(Idx) && "Invalid structure index!"); + return STy->getElementType(Idx); + } + + return cast(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(V)->getZExtValue(); - return getTypeAtIndex(Idx); +const Type *CompositeType::getTypeAtIndex(unsigned Idx) const { + if (const StructType *STy = dyn_cast(this)) { + assert(indexValid(Idx) && "Invalid structure index!"); + return STy->getElementType(Idx); + } + + return cast(this)->getElementType(); +} +bool CompositeType::indexValid(const Value *V) const { + if (const StructType *STy = dyn_cast(this)) { + // Structure indexes require 32-bit integer constants. + if (V->getType()->isIntegerTy(32)) + if (const ConstantInt *CU = dyn_cast(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(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); -- cgit v1.2.3