Skip to content

Commit bede010

Browse files
[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.
1 parent 1a2f833 commit bede010

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/include/llvm/CodeGen/LowLevelType.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ class LLT {
163163
: getFieldValue(VectorScalableFieldInfo);
164164
}
165165

166+
/// Returns true if the LLT is a fixed vector. Returns false otherwise, even
167+
/// if the LLT is not a vector type.
168+
constexpr bool isFixedVector() const { return isVector() && !isScalable(); }
169+
170+
/// Returns true if the LLT is a scalable vector. Returns false otherwise,
171+
/// even if the LLT is not a vector type.
172+
constexpr bool isScalableVector() const { return isVector() && isScalable(); }
173+
166174
constexpr ElementCount getElementCount() const {
167175
assert(IsVector && "cannot get number of elements on scalar/aggregate");
168176
return ElementCount::get(IsPointer

llvm/unittests/CodeGen/LowLevelTypeTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,18 @@ TEST(LowLevelTypeTest, ConstExpr) {
412412
EXPECT_EQ(LLT::pointer(0, 32), CEP0);
413413
EXPECT_EQ(LLT::scalable_vector(2, 32), CESV2S32);
414414
}
415+
416+
TEST(LowLevelTypeTest, IsFixedVector) {
417+
EXPECT_FALSE(LLT::scalar(32).isFixedVector());
418+
EXPECT_TRUE(LLT::fixed_vector(2, 32).isFixedVector());
419+
EXPECT_FALSE(LLT::scalable_vector(2, 32).isFixedVector());
420+
EXPECT_FALSE(LLT::scalable_vector(1, 32).isFixedVector());
421+
}
422+
423+
TEST(LowLevelTypeTest, IsScalableVector) {
424+
EXPECT_FALSE(LLT::scalar(32).isScalableVector());
425+
EXPECT_FALSE(LLT::fixed_vector(2, 32).isScalableVector());
426+
EXPECT_TRUE(LLT::scalable_vector(2, 32).isScalableVector());
427+
EXPECT_TRUE(LLT::scalable_vector(1, 32).isScalableVector());
428+
}
415429
}

0 commit comments

Comments
 (0)