diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-04-06 17:03:49 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-04-06 17:03:49 -0700 |
commit | 68b03aee1a15678ab5b518148d5e75c9dc0436fd (patch) | |
tree | f839c1aad6785c8316dac773ad2033a6987af029 /llvm/lib/IR/Constants.cpp | |
parent | 8f2d2a7cb46572d51a7dddcf151fb202e4abeb4d (diff) | |
download | llvm-68b03aee1a15678ab5b518148d5e75c9dc0436fd.zip llvm-68b03aee1a15678ab5b518148d5e75c9dc0436fd.tar.gz llvm-68b03aee1a15678ab5b518148d5e75c9dc0436fd.tar.bz2 |
Remove SequentialType from the type heirarchy.
Now that we have scalable vectors, there's a distinction that isn't
getting captured in the original SequentialType: some vectors don't have
a known element count, so counting the number of elements doesn't make
sense.
In some cases, there's a better way to express the commonality using
other methods. If we're dealing with GEPs, there's GEP methods; if we're
dealing with a ConstantDataSequential, we can query its element type
directly.
In the relatively few remaining cases, I just decided to write out
the type checks. We're talking about relatively few places, and I think
the abstraction doesn't really carry its weight. (See thread "[RFC]
Refactor class hierarchy of VectorType in the IR" on llvmdev.)
Differential Revision: https://reviews.llvm.org/D75661
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 60ab1a5..95b7d85 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -923,7 +923,9 @@ void ConstantFP::destroyConstantImpl() { //===----------------------------------------------------------------------===// Constant *ConstantAggregateZero::getSequentialElement() const { - return Constant::getNullValue(getType()->getSequentialElementType()); + if (auto *AT = dyn_cast<ArrayType>(getType())) + return Constant::getNullValue(AT->getElementType()); + return Constant::getNullValue(cast<VectorType>(getType())->getElementType()); } Constant *ConstantAggregateZero::getStructElement(unsigned Elt) const { @@ -931,13 +933,13 @@ Constant *ConstantAggregateZero::getStructElement(unsigned Elt) const { } Constant *ConstantAggregateZero::getElementValue(Constant *C) const { - if (isa<SequentialType>(getType())) + if (isa<ArrayType>(getType()) || isa<VectorType>(getType())) return getSequentialElement(); return getStructElement(cast<ConstantInt>(C)->getZExtValue()); } Constant *ConstantAggregateZero::getElementValue(unsigned Idx) const { - if (isa<SequentialType>(getType())) + if (isa<ArrayType>(getType()) || isa<VectorType>(getType())) return getSequentialElement(); return getStructElement(Idx); } @@ -956,7 +958,9 @@ unsigned ConstantAggregateZero::getNumElements() const { //===----------------------------------------------------------------------===// UndefValue *UndefValue::getSequentialElement() const { - return UndefValue::get(getType()->getSequentialElementType()); + if (ArrayType *ATy = dyn_cast<ArrayType>(getType())) + return UndefValue::get(ATy->getElementType()); + return UndefValue::get(cast<VectorType>(getType())->getElementType()); } UndefValue *UndefValue::getStructElement(unsigned Elt) const { @@ -964,21 +968,23 @@ UndefValue *UndefValue::getStructElement(unsigned Elt) const { } UndefValue *UndefValue::getElementValue(Constant *C) const { - if (isa<SequentialType>(getType())) + if (isa<ArrayType>(getType()) || isa<VectorType>(getType())) return getSequentialElement(); return getStructElement(cast<ConstantInt>(C)->getZExtValue()); } UndefValue *UndefValue::getElementValue(unsigned Idx) const { - if (isa<SequentialType>(getType())) + if (isa<ArrayType>(getType()) || isa<VectorType>(getType())) return getSequentialElement(); return getStructElement(Idx); } unsigned UndefValue::getNumElements() const { Type *Ty = getType(); - if (auto *ST = dyn_cast<SequentialType>(Ty)) - return ST->getNumElements(); + if (auto *AT = dyn_cast<ArrayType>(Ty)) + return AT->getNumElements(); + if (auto *VT = dyn_cast<VectorType>(Ty)) + return VT->getNumElements(); return Ty->getStructNumElements(); } @@ -2536,7 +2542,9 @@ Type *GetElementPtrConstantExpr::getResultElementType() const { // ConstantData* implementations Type *ConstantDataSequential::getElementType() const { - return getType()->getElementType(); + if (ArrayType *ATy = dyn_cast<ArrayType>(getType())) + return ATy->getElementType(); + return cast<VectorType>(getType())->getElementType(); } StringRef ConstantDataSequential::getRawDataValues() const { @@ -2589,7 +2597,12 @@ static bool isAllZeros(StringRef Arr) { /// the correct element type. We take the bytes in as a StringRef because /// we *want* an underlying "char*" to avoid TBAA type punning violations. Constant *ConstantDataSequential::getImpl(StringRef Elements, Type *Ty) { - assert(isElementTypeCompatible(Ty->getSequentialElementType())); +#ifndef NDEBUG + if (ArrayType *ATy = dyn_cast<ArrayType>(Ty)) + assert(isElementTypeCompatible(ATy->getElementType())); + else + assert(isElementTypeCompatible(cast<VectorType>(Ty)->getElementType())); +#endif // If the elements are all zero or there are no elements, return a CAZ, which // is more dense and canonical. if (isAllZeros(Elements)) |