1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

LLT: Add changeNumElements

This is the element analog of changeElementType/changeElementSize
This commit is contained in:
Matt Arsenault 2020-01-28 13:14:06 -05:00
parent b357126bee
commit 332fa622b0
2 changed files with 29 additions and 0 deletions

View File

@ -137,6 +137,12 @@ public:
: 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 {

View File

@ -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