Skip to content

Commit

Permalink
LLT: Add changeNumElements
Browse files Browse the repository at this point in the history
This is the element analog of changeElementType/changeElementSize
  • Loading branch information
arsenm committed Jan 29, 2020
1 parent df8f277 commit 24ab761
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions llvm/include/llvm/Support/LowLevelTypeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class LLT {
: LLT::scalar(NewEltSize);
}

/// Return a vector or scalar with the same element type and the new number of
/// elements.
LLT changeNumElements(unsigned NewNumElts) const {
return LLT::scalarOrVector(NewNumElts, getScalarType());
}

bool isByteSized() const { return (getSizeInBits() & 7) == 0; }

unsigned getScalarSizeInBits() const {
Expand Down
23 changes: 23 additions & 0 deletions llvm/unittests/CodeGen/LowLevelTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,29 @@ TEST(LowLevelTypeTest, ChangeElementType) {
EXPECT_EQ(V2S32, V2P0.changeElementType(S32));
}

TEST(LowLevelTypeTest, ChangeNumElements) {
const LLT P0 = LLT::pointer(0, 32);
const LLT V2P0 = LLT::vector(2, P0);
const LLT V3P0 = LLT::vector(3, P0);

const LLT S64 = LLT::scalar(64);
const LLT V2S64 = LLT::vector(2, 64);
const LLT V3S64 = LLT::vector(3, 64);

// Vector to scalar
EXPECT_EQ(S64, V2S64.changeNumElements(1));

// Vector to vector
EXPECT_EQ(V3S64, V2S64.changeNumElements(3));

// Scalar to vector
EXPECT_EQ(V2S64, S64.changeNumElements(2));

EXPECT_EQ(P0, V2P0.changeNumElements(1));
EXPECT_EQ(V3P0, V2P0.changeNumElements(3));
EXPECT_EQ(V2P0, P0.changeNumElements(2));
}

#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG

Expand Down

0 comments on commit 24ab761

Please sign in to comment.