Remove the Type::getNumElements() method, which is only called in 4 places,
authorChris Lattner <sabre@nondot.org>
Wed, 25 Jan 2012 01:32:59 +0000 (01:32 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 25 Jan 2012 01:32:59 +0000 (01:32 +0000)
did something extremely surprising, and shadowed actually useful
implementations that had completely different behavior.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148898 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Type.h
lib/VMCore/Constants.cpp
lib/VMCore/Instructions.cpp
lib/VMCore/Type.cpp

index 95edb50459e91a7160cf731aab0417c664e357b0..e7c165b1bf132e4988b1c76fad349ce975a8c88d 100644 (file)
@@ -294,10 +294,6 @@ public:
   /// otherwise return 'this'.
   Type *getScalarType();
 
-  /// getNumElements - If this is a vector type, return the number of elements,
-  /// otherwise return zero.
-  unsigned getNumElements();
-
   //===--------------------------------------------------------------------===//
   // Type Iteration support.
   //
index 1976832294dcef71db1742e1f69b6f4b058133c8..0fcce0940841a3993531650e954d265868cfcfb1 100644 (file)
@@ -1505,8 +1505,10 @@ Constant *ConstantExpr::getPtrToInt(Constant *C, Type *DstTy) {
          "PtrToInt source must be pointer or pointer vector");
   assert(DstTy->getScalarType()->isIntegerTy() && 
          "PtrToInt destination must be integer or integer vector");
-  assert(C->getType()->getNumElements() == DstTy->getNumElements() &&
-    "Invalid cast between a different number of vector elements");
+  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
+  if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
+    assert(VT->getNumElements() == cast<VectorType>(DstTy)->getNumElements() &&
+           "Invalid cast between a different number of vector elements");
   return getFoldedCast(Instruction::PtrToInt, C, DstTy);
 }
 
@@ -1515,8 +1517,10 @@ Constant *ConstantExpr::getIntToPtr(Constant *C, Type *DstTy) {
          "IntToPtr source must be integer or integer vector");
   assert(DstTy->getScalarType()->isPointerTy() &&
          "IntToPtr destination must be a pointer or pointer vector");
-  assert(C->getType()->getNumElements() == DstTy->getNumElements() &&
-    "Invalid cast between a different number of vector elements");
+  assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
+  if (VectorType *VT = dyn_cast<VectorType>(C->getType()))
+    assert(VT->getNumElements() == cast<VectorType>(DstTy)->getNumElements() &&
+           "Invalid cast between a different number of vector elements");
   return getFoldedCast(Instruction::IntToPtr, C, DstTy);
 }
 
@@ -2018,7 +2022,9 @@ bool ConstantDataSequential::isElementTypeCompatible(const Type *Ty) {
 
 /// getNumElements - Return the number of elements in the array or vector.
 unsigned ConstantDataSequential::getNumElements() const {
-  return getType()->getNumElements();
+  if (ArrayType *AT = dyn_cast<ArrayType>(getType()))
+    return AT->getNumElements();
+  return cast<VectorType>(getType())->getNumElements();
 }
 
 
index 8c375c2af3f8ca2a30a081fb7f3937c9096d3d39..2c6987485ffe9858b145cad28bc98608b3446c89 100644 (file)
@@ -2671,13 +2671,19 @@ CastInst::castIsValid(Instruction::CastOps op, Value *S, Type *DstTy) {
     return SrcTy->isFPOrFPVectorTy() && DstTy->isIntOrIntVectorTy() &&
       SrcLength == DstLength;
   case Instruction::PtrToInt:
-    if (SrcTy->getNumElements() != DstTy->getNumElements())
+    if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
       return false;
+    if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
+      if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
+        return false;
     return SrcTy->getScalarType()->isPointerTy() &&
            DstTy->getScalarType()->isIntegerTy();
   case Instruction::IntToPtr:
-    if (SrcTy->getNumElements() != DstTy->getNumElements())
+    if (isa<VectorType>(SrcTy) != isa<VectorType>(DstTy))
       return false;
+    if (VectorType *VT = dyn_cast<VectorType>(SrcTy))
+      if (VT->getNumElements() != cast<VectorType>(DstTy)->getNumElements())
+        return false;
     return SrcTy->getScalarType()->isIntegerTy() &&
            DstTy->getScalarType()->isPointerTy();
   case Instruction::BitCast:
index fe07e9e12e085e15c7621d71a7da5150b8d06bde..7edd9e63f5a88a6265fa867dfed6edf4160f41e8 100644 (file)
@@ -47,14 +47,6 @@ Type *Type::getScalarType() {
   return this;
 }
 
-/// getNumElements - If this is a vector type, return the number of elements,
-/// otherwise return zero.
-unsigned Type::getNumElements() {
-  if (VectorType *VTy = dyn_cast<VectorType>(this))
-    return VTy->getNumElements();
-  return 0;
-}
-
 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
 bool Type::isIntegerTy(unsigned Bitwidth) const {
   return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;