diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h --- a/llvm/include/llvm/Support/TypeSize.h +++ b/llvm/include/llvm/Support/TypeSize.h @@ -31,279 +31,157 @@ /// done on a scalable vector. This function may not return. void reportInvalidSizeRequest(const char *Msg); -template struct LinearPolyBaseTypeTraits {}; - //===----------------------------------------------------------------------===// -// LinearPolyBase - a base class for linear polynomials with multiple -// dimensions. This can e.g. be used to describe offsets that are have both a -// fixed and scalable component. +// StackOffset - Represent an offset with named fixed and scalable components. //===----------------------------------------------------------------------===// -/// LinearPolyBase describes a linear polynomial: -/// c0 * scale0 + c1 * scale1 + ... + cK * scaleK -/// where the scale is implicit, so only the coefficients are encoded. -template -class LinearPolyBase { -public: - using ScalarTy = typename LinearPolyBaseTypeTraits::ScalarTy; - static constexpr auto Dimensions = LinearPolyBaseTypeTraits::Dimensions; - static_assert(Dimensions != std::numeric_limits::max(), - "Dimensions out of range"); - -private: - std::array Coefficients; +/// StackOffset is a class to represent an offset with 2 dimensions, +/// named fixed and scalable, respectively. This class allows a value for both +/// dimensions to depict e.g. "8 bytes and 16 scalable bytes", which is needed +/// to represent stack offsets. +class StackOffset { + int64_t Fixed = 0; + int64_t Scalable = 0; -protected: - LinearPolyBase(ArrayRef Values) { - std::copy(Values.begin(), Values.end(), Coefficients.begin()); - } + StackOffset(int64_t Fixed, int64_t Scalable) + : Fixed(Fixed), Scalable(Scalable) {} public: - friend LeafTy &operator+=(LeafTy &LHS, const LeafTy &RHS) { - for (unsigned I=0; I - friend std::enable_if_t::value, LeafTy> - operator-(const LeafTy &LHS) { - LeafTy Copy = LHS; - return Copy *= -1; + StackOffset &operator-=(const StackOffset &Rhs) { + Fixed -= Rhs.Fixed; + Scalable -= Rhs.Scalable; + return *this; } - bool operator==(const LinearPolyBase &RHS) const { - return std::equal(Coefficients.begin(), Coefficients.end(), - RHS.Coefficients.begin()); - } + StackOffset operator-() const { return {-Fixed, -Scalable}; } - bool operator!=(const LinearPolyBase &RHS) const { - return !(*this == RHS); + bool operator==(const StackOffset &Rhs) const { + return Fixed == Rhs.Fixed && Scalable == Rhs.Scalable; } + bool operator!=(const StackOffset &Rhs) const { return !(*this == Rhs); } - bool isZero() const { - return all_of(Coefficients, [](const ScalarTy &C) { return C == 0; }); - } - bool isNonZero() const { return !isZero(); } - explicit operator bool() const { return isNonZero(); } - - ScalarTy getValue(unsigned Dim) const { return Coefficients[Dim]; } + explicit operator bool() const { return Fixed != 0 || Scalable != 0; } }; //===----------------------------------------------------------------------===// -// StackOffset - Represent an offset with named fixed and scalable components. +// FixedOrScalableQuantity - base class for fixed- or scalable sizes. +// ^ ^ +// | | +// | +----- ElementCount - Leaf class to represent an element count +// | (vscale x unsigned) +// | +// +-------- TypeSize - Leaf class to represent a type size +// (vscale x uint64_t) //===----------------------------------------------------------------------===// -class StackOffset; -template <> struct LinearPolyBaseTypeTraits { - using ScalarTy = int64_t; - static constexpr unsigned Dimensions = 2; -}; - -/// StackOffset is a class to represent an offset with 2 dimensions, -/// named fixed and scalable, respectively. This class allows a value for both -/// dimensions to depict e.g. "8 bytes and 16 scalable bytes", which is needed -/// to represent stack offsets. -class StackOffset : public LinearPolyBase { -protected: - StackOffset(ScalarTy Fixed, ScalarTy Scalable) - : LinearPolyBase({Fixed, Scalable}) {} - -public: - StackOffset() : StackOffset({0, 0}) {} - StackOffset(const LinearPolyBase &Other) - : LinearPolyBase(Other) {} - static StackOffset getFixed(ScalarTy Fixed) { return {Fixed, 0}; } - static StackOffset getScalable(ScalarTy Scalable) { return {0, Scalable}; } - static StackOffset get(ScalarTy Fixed, ScalarTy Scalable) { - return {Fixed, Scalable}; - } - - ScalarTy getFixed() const { return this->getValue(0); } - ScalarTy getScalable() const { return this->getValue(1); } -}; - -//===----------------------------------------------------------------------===// -// UnivariateLinearPolyBase - a base class for linear polynomials with multiple -// dimensions, but where only one dimension can be set at any time. -// This can e.g. be used to describe sizes that are either fixed or scalable. -//===----------------------------------------------------------------------===// +template class FixedOrScalableQuantity { -/// UnivariateLinearPolyBase is a base class for ElementCount and TypeSize. -/// Like LinearPolyBase it tries to represent a linear polynomial -/// where only one dimension can be set at any time, e.g. -/// 0 * scale0 + 0 * scale1 + ... + cJ * scaleJ + ... + 0 * scaleK -/// The dimension that is set is the univariate dimension. -template -class UnivariateLinearPolyBase { public: - using ScalarTy = typename LinearPolyBaseTypeTraits::ScalarTy; - static constexpr auto Dimensions = LinearPolyBaseTypeTraits::Dimensions; - static_assert(Dimensions != std::numeric_limits::max(), - "Dimensions out of range"); + using ScalarTy = ScalarT; protected: - ScalarTy Value; // The value at the univeriate dimension. - unsigned UnivariateDim; // The univeriate dimension. + ScalarTy MinValue = 0; + bool Scalable = false; - UnivariateLinearPolyBase(ScalarTy Val, unsigned UnivariateDim) - : Value(Val), UnivariateDim(UnivariateDim) { - assert(UnivariateDim < Dimensions && "Dimension out of range"); - } + FixedOrScalableQuantity() = default; + FixedOrScalableQuantity(ScalarTy MinVal, bool Scalable) + : MinValue(MinVal), Scalable(Scalable) {} - friend LeafTy &operator+=(LeafTy &LHS, const LeafTy &RHS) { - assert(LHS.UnivariateDim == RHS.UnivariateDim && "Invalid dimensions"); - LHS.Value += RHS.Value; - return LHS; + friend LeafTy &operator+=(LeafTy &Lhs, const LeafTy &Rhs) { + assert(Lhs.Scalable == Rhs.Scalable && "Invalid dimensions"); + Lhs.MinValue += Rhs.MinValue; + return Lhs; } - friend LeafTy &operator-=(LeafTy &LHS, const LeafTy &RHS) { - assert(LHS.UnivariateDim == RHS.UnivariateDim && "Invalid dimensions"); - LHS.Value -= RHS.Value; - return LHS; + friend LeafTy &operator-=(LeafTy &Lhs, const LeafTy &Rhs) { + assert(Lhs.Scalable == Rhs.Scalable && "Invalid dimensions"); + Lhs.MinValue -= Rhs.MinValue; + return Lhs; } - friend LeafTy &operator*=(LeafTy &LHS, ScalarTy RHS) { - LHS.Value *= RHS; - return LHS; + friend LeafTy &operator*=(LeafTy &Lhs, ScalarTy Rhs) { + Lhs.MinValue *= Rhs; + return Lhs; } - friend LeafTy operator+(const LeafTy &LHS, const LeafTy &RHS) { - LeafTy Copy = LHS; - return Copy += RHS; + friend LeafTy operator+(const LeafTy &Lhs, const LeafTy &Rhs) { + LeafTy Copy = Lhs; + return Copy += Rhs; } - friend LeafTy operator-(const LeafTy &LHS, const LeafTy &RHS) { - LeafTy Copy = LHS; - return Copy -= RHS; + friend LeafTy operator-(const LeafTy &Lhs, const LeafTy &Rhs) { + LeafTy Copy = Lhs; + return Copy -= Rhs; } - friend LeafTy operator*(const LeafTy &LHS, ScalarTy RHS) { - LeafTy Copy = LHS; - return Copy *= RHS; + friend LeafTy operator*(const LeafTy &Lhs, ScalarTy Rhs) { + LeafTy Copy = Lhs; + return Copy *= Rhs; } template friend std::enable_if_t::value, LeafTy> - operator-(const LeafTy &LHS) { - LeafTy Copy = LHS; + operator-(const LeafTy &Lhs) { + LeafTy Copy = Lhs; return Copy *= -1; } +private: + auto tie() const { return std::tie(MinValue, Scalable); } + public: - bool operator==(const UnivariateLinearPolyBase &RHS) const { - return Value == RHS.Value && UnivariateDim == RHS.UnivariateDim; + bool operator==(const FixedOrScalableQuantity &Rhs) const { + return tie() == Rhs.tie(); } - bool operator!=(const UnivariateLinearPolyBase &RHS) const { - return !(*this == RHS); + bool operator!=(const FixedOrScalableQuantity &Rhs) const { + return tie() != Rhs.tie(); } - bool isZero() const { return !Value; } - bool isNonZero() const { return !isZero(); } + bool isZero() const { return MinValue == 0; } + bool isNonZero() const { return MinValue != 0; } explicit operator bool() const { return isNonZero(); } - ScalarTy getValue(unsigned Dim) const { - return Dim == UnivariateDim ? Value : 0; - } - /// Add \p RHS to the value at the univariate dimension. - LeafTy getWithIncrement(ScalarTy RHS) const { - return static_cast( - UnivariateLinearPolyBase(Value + RHS, UnivariateDim)); + /// Add \p Rhs to the value at the univariate dimension. + LeafTy getWithIncrement(ScalarTy Rhs) const { + return LeafTy::get(MinValue + Rhs, Scalable); } - /// Subtract \p RHS from the value at the univariate dimension. - LeafTy getWithDecrement(ScalarTy RHS) const { - return static_cast( - UnivariateLinearPolyBase(Value - RHS, UnivariateDim)); - } -}; - - -//===----------------------------------------------------------------------===// -// LinearPolySize - base class for fixed- or scalable sizes. -// ^ ^ -// | | -// | +----- ElementCount - Leaf class to represent an element count -// | (vscale x unsigned) -// | -// +-------- TypeSize - Leaf class to represent a type size -// (vscale x uint64_t) -//===----------------------------------------------------------------------===// - -/// LinearPolySize is a base class to represent sizes. It is either -/// fixed-sized or it is scalable-sized, but it cannot be both. -template -class LinearPolySize : public UnivariateLinearPolyBase { - // Make the parent class a friend, so that it can access the protected - // conversion/copy-constructor for UnivariatePolyBase -> - // LinearPolySize. - friend class UnivariateLinearPolyBase; - -public: - using ScalarTy = typename UnivariateLinearPolyBase::ScalarTy; - enum Dims : unsigned { FixedDim = 0, ScalableDim = 1 }; - -protected: - LinearPolySize(ScalarTy MinVal, Dims D) - : UnivariateLinearPolyBase(MinVal, D) {} - - LinearPolySize(const UnivariateLinearPolyBase &V) - : UnivariateLinearPolyBase(V) {} - -public: - - static LeafTy getFixed(ScalarTy MinVal) { - return static_cast(LinearPolySize(MinVal, FixedDim)); - } - static LeafTy getScalable(ScalarTy MinVal) { - return static_cast(LinearPolySize(MinVal, ScalableDim)); - } - static LeafTy get(ScalarTy MinVal, bool Scalable) { - return static_cast( - LinearPolySize(MinVal, Scalable ? ScalableDim : FixedDim)); - } - static LeafTy getNull() { return get(0, false); } - /// Returns the minimum value this size can represent. - ScalarTy getKnownMinValue() const { return this->Value; } + ScalarTy getKnownMinValue() const { return MinValue; } /// Returns whether the size is scaled by a runtime quantity (vscale). - bool isScalable() const { return this->UnivariateDim == ScalableDim; } + bool isScalable() const { return Scalable; } /// A return value of true indicates we know at compile time that the number /// of elements (vscale * Min) is definitely even. However, returning false /// does not guarantee that the total number of elements is odd. bool isKnownEven() const { return (getKnownMinValue() & 0x1) == 0; } /// This function tells the caller whether the element count is known at - /// compile time to be a multiple of the scalar value RHS. - bool isKnownMultipleOf(ScalarTy RHS) const { - return getKnownMinValue() % RHS == 0; + /// compile time to be a multiple of the scalar value Rhs. + bool isKnownMultipleOf(ScalarTy Rhs) const { + return getKnownMinValue() % Rhs == 0; } // Return the minimum value with the assumption that the count is exact. @@ -325,66 +203,68 @@ // All the functions below make use of the fact vscale is always >= 1, which // means that is guaranteed to be >= <4 x i32>, etc. - static bool isKnownLT(const LinearPolySize &LHS, const LinearPolySize &RHS) { - if (!LHS.isScalable() || RHS.isScalable()) - return LHS.getKnownMinValue() < RHS.getKnownMinValue(); + static bool isKnownLT(const FixedOrScalableQuantity &Lhs, + const FixedOrScalableQuantity &Rhs) { + if (!Lhs.isScalable() || Rhs.isScalable()) + return Lhs.getKnownMinValue() < Rhs.getKnownMinValue(); return false; } - static bool isKnownGT(const LinearPolySize &LHS, const LinearPolySize &RHS) { - if (LHS.isScalable() || !RHS.isScalable()) - return LHS.getKnownMinValue() > RHS.getKnownMinValue(); + static bool isKnownGT(const FixedOrScalableQuantity &Lhs, + const FixedOrScalableQuantity &Rhs) { + if (Lhs.isScalable() || !Rhs.isScalable()) + return Lhs.getKnownMinValue() > Rhs.getKnownMinValue(); return false; } - static bool isKnownLE(const LinearPolySize &LHS, const LinearPolySize &RHS) { - if (!LHS.isScalable() || RHS.isScalable()) - return LHS.getKnownMinValue() <= RHS.getKnownMinValue(); + static bool isKnownLE(const FixedOrScalableQuantity &Lhs, + const FixedOrScalableQuantity &Rhs) { + if (!Lhs.isScalable() || Rhs.isScalable()) + return Lhs.getKnownMinValue() <= Rhs.getKnownMinValue(); return false; } - static bool isKnownGE(const LinearPolySize &LHS, const LinearPolySize &RHS) { - if (LHS.isScalable() || !RHS.isScalable()) - return LHS.getKnownMinValue() >= RHS.getKnownMinValue(); + static bool isKnownGE(const FixedOrScalableQuantity &Lhs, + const FixedOrScalableQuantity &Rhs) { + if (Lhs.isScalable() || !Rhs.isScalable()) + return Lhs.getKnownMinValue() >= Rhs.getKnownMinValue(); return false; } /// We do not provide the '/' operator here because division for polynomial /// types does not work in the same way as for normal integer types. We can - /// only divide the minimum value (or coefficient) by RHS, which is not the + /// only divide the minimum value (or coefficient) by Rhs, which is not the /// same as - /// (Min * Vscale) / RHS + /// (Min * Vscale) / Rhs /// The caller is recommended to use this function in combination with - /// isKnownMultipleOf(RHS), which lets the caller know if it's possible to - /// perform a lossless divide by RHS. - LeafTy divideCoefficientBy(ScalarTy RHS) const { - return static_cast( - LinearPolySize::get(getKnownMinValue() / RHS, isScalable())); + /// isKnownMultipleOf(Rhs), which lets the caller know if it's possible to + /// perform a lossless divide by Rhs. + LeafTy divideCoefficientBy(ScalarTy Rhs) const { + return LeafTy::get(getKnownMinValue() / Rhs, isScalable()); } - LeafTy multiplyCoefficientBy(ScalarTy RHS) const { - return static_cast( - LinearPolySize::get(getKnownMinValue() * RHS, isScalable())); + LeafTy multiplyCoefficientBy(ScalarTy Rhs) const { + return LeafTy::get(getKnownMinValue() * Rhs, isScalable()); } LeafTy coefficientNextPowerOf2() const { - return static_cast(LinearPolySize::get( + return LeafTy::get( static_cast(llvm::NextPowerOf2(getKnownMinValue())), - isScalable())); + isScalable()); } - /// Returns true if there exists a value X where RHS.multiplyCoefficientBy(X) + /// Returns true if there exists a value X where Rhs.multiplyCoefficientBy(X) /// will result in a value whose size matches our own. - bool hasKnownScalarFactor(const LinearPolySize &RHS) const { - return isScalable() == RHS.isScalable() && - getKnownMinValue() % RHS.getKnownMinValue() == 0; + bool hasKnownScalarFactor(const FixedOrScalableQuantity &Rhs) const { + return isScalable() == Rhs.isScalable() && + getKnownMinValue() % Rhs.getKnownMinValue() == 0; } - /// Returns a value X where RHS.multiplyCoefficientBy(X) will result in a + /// Returns a value X where Rhs.multiplyCoefficientBy(X) will result in a /// value whose size matches our own. - ScalarTy getKnownScalarFactor(const LinearPolySize &RHS) const { - assert(hasKnownScalarFactor(RHS) && "Expected RHS to be a known factor!"); - return getKnownMinValue() / RHS.getKnownMinValue(); + ScalarTy getKnownScalarFactor(const FixedOrScalableQuantity &Rhs) const { + assert(hasKnownScalarFactor(Rhs) && "Expected Rhs to be a known factor!"); + return getKnownMinValue() / Rhs.getKnownMinValue(); } /// Printing function. @@ -395,48 +275,52 @@ } }; -class ElementCount; -template <> struct LinearPolyBaseTypeTraits { - using ScalarTy = unsigned; - static constexpr unsigned Dimensions = 2; -}; +class ElementCount : public FixedOrScalableQuantity { + ElementCount(ScalarTy MinVal, bool Scalable) + : FixedOrScalableQuantity(MinVal, Scalable) {} + + ElementCount(const FixedOrScalableQuantity &V) + : FixedOrScalableQuantity(V) {} -class ElementCount : public LinearPolySize { public: - ElementCount() : LinearPolySize(LinearPolySize::getNull()) {} + ElementCount() : FixedOrScalableQuantity() {} - ElementCount(const LinearPolySize &V) : LinearPolySize(V) {} + static ElementCount getFixed(ScalarTy MinVal) { + return ElementCount(MinVal, false); + } + static ElementCount getScalable(ScalarTy MinVal) { + return ElementCount(MinVal, true); + } + static ElementCount get(ScalarTy MinVal, bool Scalable) { + return ElementCount(MinVal, Scalable); + } - /// Counting predicates. - /// - ///@{ Number of elements.. /// Exactly one element. bool isScalar() const { return !isScalable() && getKnownMinValue() == 1; } /// One or more elements. bool isVector() const { return (isScalable() && getKnownMinValue() != 0) || getKnownMinValue() > 1; } - ///@} }; -// This class is used to represent the size of types. If the type is of fixed -class TypeSize; -template <> struct LinearPolyBaseTypeTraits { - using ScalarTy = uint64_t; - static constexpr unsigned Dimensions = 2; -}; - -// TODO: Most functionality in this class will gradually be phased out -// so it will resemble LinearPolySize as much as possible. -// // TypeSize is used to represent the size of types. If the type is of fixed // size, it will represent the exact size. If the type is a scalable vector, // it will represent the known minimum size. -class TypeSize : public LinearPolySize { +class TypeSize : public FixedOrScalableQuantity { + TypeSize(const FixedOrScalableQuantity &V) + : FixedOrScalableQuantity(V) {} + public: - TypeSize(const LinearPolySize &V) : LinearPolySize(V) {} - TypeSize(ScalarTy MinVal, bool IsScalable) - : LinearPolySize(LinearPolySize::get(MinVal, IsScalable)) {} + TypeSize(ScalarTy MinVal, bool Scalable) + : FixedOrScalableQuantity(MinVal, Scalable) {} + + static TypeSize getFixed(ScalarTy MinVal) { return TypeSize(MinVal, false); } + static TypeSize getScalable(ScalarTy MinVal) { + return TypeSize(MinVal, true); + } + static TypeSize get(ScalarTy MinVal, bool Scalable) { + return TypeSize(MinVal, Scalable); + } static TypeSize Fixed(ScalarTy MinVal) { return TypeSize(MinVal, false); } static TypeSize Scalable(ScalarTy MinVal) { return TypeSize(MinVal, true); } @@ -472,26 +356,26 @@ // Additional operators needed to avoid ambiguous parses // because of the implicit conversion hack. - friend TypeSize operator*(const TypeSize &LHS, const int RHS) { - return LHS * (ScalarTy)RHS; + friend TypeSize operator*(const TypeSize &Lhs, const int Rhs) { + return Lhs * (ScalarTy)Rhs; } - friend TypeSize operator*(const TypeSize &LHS, const unsigned RHS) { - return LHS * (ScalarTy)RHS; + friend TypeSize operator*(const TypeSize &Lhs, const unsigned Rhs) { + return Lhs * (ScalarTy)Rhs; } - friend TypeSize operator*(const TypeSize &LHS, const int64_t RHS) { - return LHS * (ScalarTy)RHS; + friend TypeSize operator*(const TypeSize &Lhs, const int64_t Rhs) { + return Lhs * (ScalarTy)Rhs; } - friend TypeSize operator*(const int LHS, const TypeSize &RHS) { - return RHS * LHS; + friend TypeSize operator*(const int Lhs, const TypeSize &Rhs) { + return Rhs * Lhs; } - friend TypeSize operator*(const unsigned LHS, const TypeSize &RHS) { - return RHS * LHS; + friend TypeSize operator*(const unsigned Lhs, const TypeSize &Rhs) { + return Rhs * Lhs; } - friend TypeSize operator*(const int64_t LHS, const TypeSize &RHS) { - return RHS * LHS; + friend TypeSize operator*(const int64_t Lhs, const TypeSize &Rhs) { + return Rhs * Lhs; } - friend TypeSize operator*(const uint64_t LHS, const TypeSize &RHS) { - return RHS * LHS; + friend TypeSize operator*(const uint64_t Lhs, const TypeSize &Rhs) { + return Rhs * Lhs; } }; @@ -500,7 +384,7 @@ //===----------------------------------------------------------------------===// /// Returns a TypeSize with a known minimum size that is the next integer -/// (mod 2**64) that is greater than or equal to \p Value and is a multiple +/// (mod 2**64) that is greater than or equal to \p MinValue and is a multiple /// of \p Align. \p Align must be non-zero. /// /// Similar to the alignTo functions in MathExtras.h @@ -510,10 +394,11 @@ Size.isScalable()}; } -/// Stream operator function for `LinearPolySize`. -template -inline raw_ostream &operator<<(raw_ostream &OS, - const LinearPolySize &PS) { +/// Stream operator function for `FixedOrScalableQuantity`. +template +inline raw_ostream & +operator<<(raw_ostream &OS, + const FixedOrScalableQuantity &PS) { PS.print(OS); return OS; } @@ -532,9 +417,8 @@ return HashVal; } - - static bool isEqual(const ElementCount &LHS, const ElementCount &RHS) { - return LHS == RHS; + static bool isEqual(const ElementCount &Lhs, const ElementCount &Rhs) { + return Lhs == Rhs; } }; diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -51,7 +51,6 @@ JSONTest.cpp KnownBitsTest.cpp LEB128Test.cpp - LinearPolyBaseTest.cpp LineIteratorTest.cpp LockFileManagerTest.cpp MatchersTest.cpp diff --git a/llvm/unittests/Support/LinearPolyBaseTest.cpp b/llvm/unittests/Support/LinearPolyBaseTest.cpp deleted file mode 100644 --- a/llvm/unittests/Support/LinearPolyBaseTest.cpp +++ /dev/null @@ -1,176 +0,0 @@ -//===- TestPoly3D.cpp - Poly3D unit tests------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/TypeSize.h" -#include "gtest/gtest.h" - -using namespace llvm; - -class Poly3D; - -namespace llvm { -template <> struct LinearPolyBaseTypeTraits { - using ScalarTy = int64_t; - static const unsigned Dimensions = 3; -}; -} - -using Poly3DBase = LinearPolyBase; -class Poly3D : public Poly3DBase { -public: - using ScalarTy = Poly3DBase::ScalarTy; - Poly3D(ScalarTy x, ScalarTy y, ScalarTy z) : Poly3DBase({x, y, z}) {} - Poly3D(const Poly3DBase &Convert) : Poly3DBase(Convert) {} -}; - -TEST(LinearPolyBase, Poly3D_isZero) { - EXPECT_TRUE(Poly3D(0, 0, 0).isZero()); - EXPECT_TRUE(Poly3D(0, 0, 1).isNonZero()); - EXPECT_TRUE(Poly3D(0, 0, 1)); -} - -TEST(LinearPolyBase, Poly3D_Equality) { - EXPECT_EQ(Poly3D(1, 2, 3), Poly3D(1, 2, 3)); - EXPECT_NE(Poly3D(1, 2, 3), Poly3D(1, 2, 4)); -} - -TEST(LinearPolyBase, Poly3D_GetValue) { - EXPECT_EQ(Poly3D(1, 2, 3).getValue(0), 1); - EXPECT_EQ(Poly3D(1, 2, 3).getValue(1), 2); - EXPECT_EQ(Poly3D(1, 2, 3).getValue(2), 3); -} - -TEST(LinearPolyBase, Poly3D_Add) { - // Test operator+ - EXPECT_EQ(Poly3D(42, 0, 0) + Poly3D(0, 42, 0) + Poly3D(0, 0, 42), - Poly3D(42, 42, 42)); - - // Test operator+= - Poly3D X(42, 0, 0); - X += Poly3D(0, 42, 0); - X += Poly3D(0, 0, 42); - EXPECT_EQ(X, Poly3D(42, 42, 42)); -} - -TEST(LinearPolyBase, Poly3D_Sub) { - // Test operator- - EXPECT_EQ(Poly3D(42, 42, 42) - Poly3D(42, 0, 0) - Poly3D(0, 42, 0) - - Poly3D(0, 0, 42), - Poly3D(0, 0, 0)); - - // Test operator-= - Poly3D X(42, 42, 42); - X -= Poly3D(42, 0, 0); - X -= Poly3D(0, 42, 0); - X -= Poly3D(0, 0, 42); - EXPECT_EQ(X, Poly3D(0, 0, 0)); -} - -TEST(LinearPolyBase, Poly3D_Scale) { - // Test operator* - EXPECT_EQ(Poly3D(1, 2, 4) * 2, Poly3D(2, 4, 8)); - EXPECT_EQ(Poly3D(1, 2, 4) * -2, Poly3D(-2, -4, -8)); -} - -TEST(LinearPolyBase, Poly3D_Invert) { - // Test operator- - EXPECT_EQ(-Poly3D(2, 4, 8), Poly3D(-2, -4, -8)); -} - -class Univariate3D; -namespace llvm { -template <> struct LinearPolyBaseTypeTraits { - using ScalarTy = int64_t; - static const unsigned Dimensions = 3; -}; -} - -using Univariate3DBase = UnivariateLinearPolyBase; -class Univariate3D : public Univariate3DBase { -public: - using ScalarTy = Univariate3DBase::ScalarTy; - Univariate3D(ScalarTy x, unsigned Dim) : Univariate3DBase(x, Dim) {} - Univariate3D(const Univariate3DBase &Convert) : Univariate3DBase(Convert) {} -}; - -TEST(UnivariateLinearPolyBase, Univariate3D_isZero) { - EXPECT_TRUE(Univariate3D(0, 0).isZero()); - EXPECT_TRUE(Univariate3D(0, 1).isZero()); - EXPECT_TRUE(Univariate3D(0, 2).isZero()); - EXPECT_TRUE(Univariate3D(1, 0).isNonZero()); - EXPECT_TRUE(Univariate3D(1, 1).isNonZero()); - EXPECT_TRUE(Univariate3D(1, 2).isNonZero()); - EXPECT_TRUE(Univariate3D(1, 0)); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_Equality) { - EXPECT_EQ(Univariate3D(1, 0), Univariate3D(1, 0)); - EXPECT_NE(Univariate3D(1, 0), Univariate3D(1, 2)); - EXPECT_NE(Univariate3D(1, 0), Univariate3D(1, 1)); - EXPECT_NE(Univariate3D(1, 0), Univariate3D(2, 0)); - EXPECT_NE(Univariate3D(1, 0), Univariate3D(0, 0)); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_GetValue) { - EXPECT_EQ(Univariate3D(42, 0).getValue(0), 42); - EXPECT_EQ(Univariate3D(42, 0).getValue(1), 0); - EXPECT_EQ(Univariate3D(42, 0).getValue(2), 0); - - EXPECT_EQ(Univariate3D(42, 1).getValue(0), 0); - EXPECT_EQ(Univariate3D(42, 1).getValue(1), 42); - EXPECT_EQ(Univariate3D(42, 1).getValue(2), 0); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_Add) { - // Test operator+ - EXPECT_EQ(Univariate3D(42, 0) + Univariate3D(42, 0), Univariate3D(84, 0)); - EXPECT_EQ(Univariate3D(42, 1) + Univariate3D(42, 1), Univariate3D(84, 1)); - EXPECT_DEBUG_DEATH(Univariate3D(42, 0) + Univariate3D(42, 1), - "Invalid dimensions"); - - // Test operator+= - Univariate3D X(42, 0); - X += Univariate3D(42, 0); - EXPECT_EQ(X, Univariate3D(84, 0)); - - // Test 'getWithIncrement' method - EXPECT_EQ(Univariate3D(42, 0).getWithIncrement(1), Univariate3D(43, 0)); - EXPECT_EQ(Univariate3D(42, 1).getWithIncrement(2), Univariate3D(44, 1)); - EXPECT_EQ(Univariate3D(42, 2).getWithIncrement(3), Univariate3D(45, 2)); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_Sub) { - // Test operator+ - EXPECT_EQ(Univariate3D(84, 0) - Univariate3D(42, 0), Univariate3D(42, 0)); - EXPECT_EQ(Univariate3D(84, 1) - Univariate3D(42, 1), Univariate3D(42, 1)); - EXPECT_DEBUG_DEATH(Univariate3D(84, 0) - Univariate3D(42, 1), - "Invalid dimensions"); - - // Test operator+= - Univariate3D X(84, 0); - X -= Univariate3D(42, 0); - EXPECT_EQ(X, Univariate3D(42, 0)); - - // Test 'getWithDecrement' method - EXPECT_EQ(Univariate3D(43, 0).getWithDecrement(1), Univariate3D(42, 0)); - EXPECT_EQ(Univariate3D(44, 1).getWithDecrement(2), Univariate3D(42, 1)); - EXPECT_EQ(Univariate3D(45, 2).getWithDecrement(3), Univariate3D(42, 2)); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_Scale) { - // Test operator* - EXPECT_EQ(Univariate3D(4, 0) * 2, Univariate3D(8, 0)); - EXPECT_EQ(Univariate3D(4, 1) * -2, Univariate3D(-8, 1)); -} - -TEST(UnivariateLinearPolyBase, Univariate3D_Invert) { - // Test operator- - EXPECT_EQ(-Univariate3D(4, 0), Univariate3D(-4, 0)); - EXPECT_EQ(-Univariate3D(4, 1), Univariate3D(-4, 1)); -} - diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -740,7 +740,7 @@ auto NoLength = [](const SmallDenseSet &Lengths, MVT T) -> bool { return !Lengths.count(T.isVector() ? T.getVectorElementCount() - : ElementCount::getNull()); + : ElementCount()); }; SmallVector Modes; @@ -751,11 +751,9 @@ SmallDenseSet VN, WN; for (MVT T : VS) - VN.insert(T.isVector() ? T.getVectorElementCount() - : ElementCount::getNull()); + VN.insert(T.isVector() ? T.getVectorElementCount() : ElementCount()); for (MVT T : WS) - WN.insert(T.isVector() ? T.getVectorElementCount() - : ElementCount::getNull()); + WN.insert(T.isVector() ? T.getVectorElementCount() : ElementCount()); Changed |= berase_if(VS, std::bind(NoLength, WN, std::placeholders::_1)); Changed |= berase_if(WS, std::bind(NoLength, VN, std::placeholders::_1));