[CodeGen][LLT] Add isFixedVector and isScalableVector (#71713)

The current isScalable function requires a user to call isVector before
hand in order to avoid an assertion failure in the case that the LLT is
not a vector.

This patch addds helper functions that allow a user to query whether the
LLT is fixed or scalable, not wanting an assertion failure in the case
that the LLT was never a vector in the first place.
This commit is contained in:
Michael Maitland 2023-11-09 14:31:38 -05:00 committed by GitHub
parent 1a2f83366b
commit bede0106d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -163,6 +163,14 @@ public:
: getFieldValue(VectorScalableFieldInfo);
}
/// Returns true if the LLT is a fixed vector. Returns false otherwise, even
/// if the LLT is not a vector type.
constexpr bool isFixedVector() const { return isVector() && !isScalable(); }
/// Returns true if the LLT is a scalable vector. Returns false otherwise,
/// even if the LLT is not a vector type.
constexpr bool isScalableVector() const { return isVector() && isScalable(); }
constexpr ElementCount getElementCount() const {
assert(IsVector && "cannot get number of elements on scalar/aggregate");
return ElementCount::get(IsPointer

View File

@ -412,4 +412,18 @@ TEST(LowLevelTypeTest, ConstExpr) {
EXPECT_EQ(LLT::pointer(0, 32), CEP0);
EXPECT_EQ(LLT::scalable_vector(2, 32), CESV2S32);
}
TEST(LowLevelTypeTest, IsFixedVector) {
EXPECT_FALSE(LLT::scalar(32).isFixedVector());
EXPECT_TRUE(LLT::fixed_vector(2, 32).isFixedVector());
EXPECT_FALSE(LLT::scalable_vector(2, 32).isFixedVector());
EXPECT_FALSE(LLT::scalable_vector(1, 32).isFixedVector());
}
TEST(LowLevelTypeTest, IsScalableVector) {
EXPECT_FALSE(LLT::scalar(32).isScalableVector());
EXPECT_FALSE(LLT::fixed_vector(2, 32).isScalableVector());
EXPECT_TRUE(LLT::scalable_vector(2, 32).isScalableVector());
EXPECT_TRUE(LLT::scalable_vector(1, 32).isScalableVector());
}
}