[llvm] r288464 - IR: Move NumElements field from {Array, Vector}Type to SequentialType.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 19:20:59 PST 2016
Author: pcc
Date: Thu Dec 1 21:20:58 2016
New Revision: 288464
URL: http://llvm.org/viewvc/llvm-project?rev=288464&view=rev
Log:
IR: Move NumElements field from {Array,Vector}Type to SequentialType.
Now that PointerType is no longer a SequentialType, all SequentialTypes
have an associated number of elements, so we can move that information to
the base class, allowing for a number of simplifications.
Differential Revision: https://reviews.llvm.org/D27122
Modified:
llvm/trunk/docs/ProgrammersManual.rst
llvm/trunk/include/llvm/IR/DerivedTypes.h
llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/lib/IR/Constants.cpp
llvm/trunk/lib/IR/Type.cpp
llvm/trunk/lib/Linker/IRMover.cpp
llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
llvm/trunk/lib/Transforms/Scalar/SROA.cpp
llvm/trunk/lib/Transforms/Utils/FunctionComparator.cpp
Modified: llvm/trunk/docs/ProgrammersManual.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.rst?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/docs/ProgrammersManual.rst (original)
+++ llvm/trunk/docs/ProgrammersManual.rst Thu Dec 1 21:20:58 2016
@@ -3283,13 +3283,13 @@ Important Derived Types
* ``const Type * getElementType() const``: Returns the type of each
of the elements in the sequential type.
+ * ``uint64_t getNumElements() const``: Returns the number of elements
+ in the sequential type.
+
``ArrayType``
This is a subclass of SequentialType and defines the interface for array
types.
- * ``unsigned getNumElements() const``: Returns the number of elements
- in the array.
-
``PointerType``
Subclass of Type for pointer types.
Modified: llvm/trunk/include/llvm/IR/DerivedTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DerivedTypes.h?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DerivedTypes.h (original)
+++ llvm/trunk/include/llvm/IR/DerivedTypes.h Thu Dec 1 21:20:58 2016
@@ -313,18 +313,21 @@ Type *Type::getStructElementType(unsigne
/// identically.
class SequentialType : public CompositeType {
Type *ContainedType; ///< Storage for the single contained type.
+ uint64_t NumElements;
SequentialType(const SequentialType &) = delete;
const SequentialType &operator=(const SequentialType &) = delete;
protected:
- SequentialType(TypeID TID, Type *ElType)
- : CompositeType(ElType->getContext(), TID), ContainedType(ElType) {
+ SequentialType(TypeID TID, Type *ElType, uint64_t NumElements)
+ : CompositeType(ElType->getContext(), TID), ContainedType(ElType),
+ NumElements(NumElements) {
ContainedTys = &ContainedType;
NumContainedTys = 1;
}
public:
- Type *getElementType() const { return getSequentialElementType(); }
+ uint64_t getNumElements() const { return NumElements; }
+ Type *getElementType() const { return ContainedType; }
/// Methods for support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const Type *T) {
@@ -334,8 +337,6 @@ public:
/// Class to represent array types.
class ArrayType : public SequentialType {
- uint64_t NumElements;
-
ArrayType(const ArrayType &) = delete;
const ArrayType &operator=(const ArrayType &) = delete;
ArrayType(Type *ElType, uint64_t NumEl);
@@ -347,8 +348,6 @@ public:
/// Return true if the specified type is valid as a element type.
static bool isValidElementType(Type *ElemTy);
- uint64_t getNumElements() const { return NumElements; }
-
/// Methods for support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const Type *T) {
return T->getTypeID() == ArrayTyID;
@@ -361,8 +360,6 @@ uint64_t Type::getArrayNumElements() con
/// Class to represent vector types.
class VectorType : public SequentialType {
- unsigned NumElements;
-
VectorType(const VectorType &) = delete;
const VectorType &operator=(const VectorType &) = delete;
VectorType(Type *ElType, unsigned NumEl);
@@ -418,13 +415,10 @@ public:
/// Return true if the specified type is valid as a element type.
static bool isValidElementType(Type *ElemTy);
- /// Return the number of elements in the Vector type.
- unsigned getNumElements() const { return NumElements; }
-
/// Return the number of bits in the Vector type.
/// Returns zero when the vector is a vector of pointers.
unsigned getBitWidth() const {
- return NumElements * getElementType()->getPrimitiveSizeInBits();
+ return getNumElements() * getElementType()->getPrimitiveSizeInBits();
}
/// Methods for support type inquiry through isa, cast, and dyn_cast.
Modified: llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h (original)
+++ llvm/trunk/include/llvm/IR/GetElementPtrTypeIterator.h Thu Dec 1 21:20:58 2016
@@ -74,12 +74,9 @@ namespace llvm {
generic_gep_type_iterator& operator++() { // Preincrement
Type *Ty = getIndexedType();
- if (auto *ATy = dyn_cast<ArrayType>(Ty)) {
- CurTy = ATy->getElementType();
- NumElements = ATy->getNumElements();
- } else if (auto *VTy = dyn_cast<VectorType>(Ty)) {
- CurTy = VTy->getElementType();
- NumElements = VTy->getNumElements();
+ if (auto *STy = dyn_cast<SequentialType>(Ty)) {
+ CurTy = STy->getElementType();
+ NumElements = STy->getNumElements();
} else
CurTy = dyn_cast<StructType>(Ty);
++OpIt;
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Thu Dec 1 21:20:58 2016
@@ -891,10 +891,8 @@ Constant *llvm::ConstantFoldInsertValueI
unsigned NumElts;
if (StructType *ST = dyn_cast<StructType>(Agg->getType()))
NumElts = ST->getNumElements();
- else if (ArrayType *AT = dyn_cast<ArrayType>(Agg->getType()))
- NumElts = AT->getNumElements();
else
- NumElts = Agg->getType()->getVectorNumElements();
+ NumElts = cast<SequentialType>(Agg->getType())->getNumElements();
SmallVector<Constant*, 32> Result;
for (unsigned i = 0; i != NumElts; ++i) {
@@ -2210,10 +2208,7 @@ Constant *llvm::ConstantFoldGetElementPt
Unknown = true;
continue;
}
- if (isIndexInRangeOfArrayType(isa<ArrayType>(STy)
- ? cast<ArrayType>(STy)->getNumElements()
- : cast<VectorType>(STy)->getNumElements(),
- CI))
+ if (isIndexInRangeOfArrayType(STy->getNumElements(), CI))
// It's in range, skip to the next index.
continue;
if (isa<StructType>(Prev)) {
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Thu Dec 1 21:20:58 2016
@@ -794,10 +794,8 @@ UndefValue *UndefValue::getElementValue(
unsigned UndefValue::getNumElements() const {
Type *Ty = getType();
- if (auto *AT = dyn_cast<ArrayType>(Ty))
- return AT->getNumElements();
- if (auto *VT = dyn_cast<VectorType>(Ty))
- return VT->getNumElements();
+ if (auto *ST = dyn_cast<SequentialType>(Ty))
+ return ST->getNumElements();
return Ty->getStructNumElements();
}
Modified: llvm/trunk/lib/IR/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Type.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Type.cpp (original)
+++ llvm/trunk/lib/IR/Type.cpp Thu Dec 1 21:20:58 2016
@@ -601,9 +601,7 @@ bool CompositeType::indexValid(unsigned
//===----------------------------------------------------------------------===//
ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
- : SequentialType(ArrayTyID, ElType) {
- NumElements = NumEl;
-}
+ : SequentialType(ArrayTyID, ElType, NumEl) {}
ArrayType *ArrayType::get(Type *ElementType, uint64_t NumElements) {
assert(isValidElementType(ElementType) && "Invalid type for array element!");
@@ -628,9 +626,7 @@ bool ArrayType::isValidElementType(Type
//===----------------------------------------------------------------------===//
VectorType::VectorType(Type *ElType, unsigned NumEl)
- : SequentialType(VectorTyID, ElType) {
- NumElements = NumEl;
-}
+ : SequentialType(VectorTyID, ElType, NumEl) {}
VectorType *VectorType::get(Type *ElementType, unsigned NumElements) {
assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
Modified: llvm/trunk/lib/Linker/IRMover.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/IRMover.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/IRMover.cpp (original)
+++ llvm/trunk/lib/Linker/IRMover.cpp Thu Dec 1 21:20:58 2016
@@ -169,11 +169,9 @@ bool TypeMapTy::areTypesIsomorphic(Type
if (DSTy->isLiteral() != SSTy->isLiteral() ||
DSTy->isPacked() != SSTy->isPacked())
return false;
- } else if (ArrayType *DATy = dyn_cast<ArrayType>(DstTy)) {
- if (DATy->getNumElements() != cast<ArrayType>(SrcTy)->getNumElements())
- return false;
- } else if (VectorType *DVTy = dyn_cast<VectorType>(DstTy)) {
- if (DVTy->getNumElements() != cast<VectorType>(SrcTy)->getNumElements())
+ } else if (auto *DSeqTy = dyn_cast<SequentialType>(DstTy)) {
+ if (DSeqTy->getNumElements() !=
+ cast<SequentialType>(SrcTy)->getNumElements())
return false;
}
Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Thu Dec 1 21:20:58 2016
@@ -467,12 +467,7 @@ static GlobalVariable *SRAGlobal(GlobalV
NGV->setAlignment(NewAlign);
}
} else if (SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
- unsigned NumElements = 0;
- if (ArrayType *ATy = dyn_cast<ArrayType>(STy))
- NumElements = ATy->getNumElements();
- else
- NumElements = cast<VectorType>(STy)->getNumElements();
-
+ unsigned NumElements = STy->getNumElements();
if (NumElements > 16 && GV->hasNUsesOrMore(16))
return nullptr; // It's not worth it.
NewGlobals.reserve(NumElements);
@@ -2119,12 +2114,7 @@ static Constant *EvaluateStoreInto(Const
ConstantInt *CI = cast<ConstantInt>(Addr->getOperand(OpNo));
SequentialType *InitTy = cast<SequentialType>(Init->getType());
-
- uint64_t NumElts;
- if (ArrayType *ATy = dyn_cast<ArrayType>(InitTy))
- NumElts = ATy->getNumElements();
- else
- NumElts = InitTy->getVectorNumElements();
+ uint64_t NumElts = InitTy->getNumElements();
// Break up the array into elements.
for (uint64_t i = 0, e = NumElts; i != e; ++i)
Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Thu Dec 1 21:20:58 2016
@@ -3222,13 +3222,8 @@ static Type *getTypePartition(const Data
Type *ElementTy = SeqTy->getElementType();
uint64_t ElementSize = DL.getTypeAllocSize(ElementTy);
uint64_t NumSkippedElements = Offset / ElementSize;
- if (ArrayType *ArrTy = dyn_cast<ArrayType>(SeqTy)) {
- if (NumSkippedElements >= ArrTy->getNumElements())
- return nullptr;
- } else if (VectorType *VecTy = dyn_cast<VectorType>(SeqTy)) {
- if (NumSkippedElements >= VecTy->getNumElements())
- return nullptr;
- }
+ if (NumSkippedElements >= SeqTy->getNumElements())
+ return nullptr;
Offset -= NumSkippedElements * ElementSize;
// First check if we need to recurse.
Modified: llvm/trunk/lib/Transforms/Utils/FunctionComparator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/FunctionComparator.cpp?rev=288464&r1=288463&r2=288464&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/FunctionComparator.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/FunctionComparator.cpp Thu Dec 1 21:20:58 2016
@@ -387,12 +387,6 @@ int FunctionComparator::cmpTypes(Type *T
case Type::IntegerTyID:
return cmpNumbers(cast<IntegerType>(TyL)->getBitWidth(),
cast<IntegerType>(TyR)->getBitWidth());
- case Type::VectorTyID: {
- VectorType *VTyL = cast<VectorType>(TyL), *VTyR = cast<VectorType>(TyR);
- if (int Res = cmpNumbers(VTyL->getNumElements(), VTyR->getNumElements()))
- return Res;
- return cmpTypes(VTyL->getElementType(), VTyR->getElementType());
- }
// TyL == TyR would have returned true earlier, because types are uniqued.
case Type::VoidTyID:
case Type::FloatTyID:
@@ -445,12 +439,13 @@ int FunctionComparator::cmpTypes(Type *T
return 0;
}
- case Type::ArrayTyID: {
- ArrayType *ATyL = cast<ArrayType>(TyL);
- ArrayType *ATyR = cast<ArrayType>(TyR);
- if (ATyL->getNumElements() != ATyR->getNumElements())
- return cmpNumbers(ATyL->getNumElements(), ATyR->getNumElements());
- return cmpTypes(ATyL->getElementType(), ATyR->getElementType());
+ case Type::ArrayTyID:
+ case Type::VectorTyID: {
+ auto *STyL = cast<SequentialType>(TyL);
+ auto *STyR = cast<SequentialType>(TyR);
+ if (STyL->getNumElements() != STyR->getNumElements())
+ return cmpNumbers(STyL->getNumElements(), STyR->getNumElements());
+ return cmpTypes(STyL->getElementType(), STyR->getElementType());
}
}
}
More information about the llvm-commits
mailing list