Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/include/llvm/CodeGen/LowLevelType.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ class LLT {
: 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
Expand Down
14 changes: 14 additions & 0 deletions llvm/unittests/CodeGen/LowLevelTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}