[llvm-commits] [llvm] r148898 - in /llvm/trunk: include/llvm/Type.h lib/VMCore/Constants.cpp lib/VMCore/Instructions.cpp lib/VMCore/Type.cpp
Chris Lattner
sabre at nondot.org
Tue Jan 24 17:32:59 PST 2012
Author: lattner
Date: Tue Jan 24 19:32:59 2012
New Revision: 148898
URL: http://llvm.org/viewvc/llvm-project?rev=148898&view=rev
Log:
Remove the Type::getNumElements() method, which is only called in 4 places,
did something extremely surprising, and shadowed actually useful
implementations that had completely different behavior.
Modified:
llvm/trunk/include/llvm/Type.h
llvm/trunk/lib/VMCore/Constants.cpp
llvm/trunk/lib/VMCore/Instructions.cpp
llvm/trunk/lib/VMCore/Type.cpp
Modified: llvm/trunk/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Type.h?rev=148898&r1=148897&r2=148898&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Type.h (original)
+++ llvm/trunk/include/llvm/Type.h Tue Jan 24 19:32:59 2012
@@ -294,10 +294,6 @@
/// 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.
//
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=148898&r1=148897&r2=148898&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Jan 24 19:32:59 2012
@@ -1505,8 +1505,10 @@
"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 @@
"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 @@
/// 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();
}
Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=148898&r1=148897&r2=148898&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Tue Jan 24 19:32:59 2012
@@ -2671,13 +2671,19 @@
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:
Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=148898&r1=148897&r2=148898&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Jan 24 19:32:59 2012
@@ -47,14 +47,6 @@
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;
More information about the llvm-commits
mailing list