[llvm] r352136 - GlobalISel: Add helper to LLT to get a scalar or vector
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 24 16:10:49 PST 2019
Author: arsenm
Date: Thu Jan 24 16:10:49 2019
New Revision: 352136
URL: http://llvm.org/viewvc/llvm-project?rev=352136&view=rev
Log:
GlobalISel: Add helper to LLT to get a scalar or vector
Modified:
llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
Modified: llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h?rev=352136&r1=352135&r2=352136&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h (original)
+++ llvm/trunk/include/llvm/Support/LowLevelTypeImpl.h Thu Jan 24 16:10:49 2019
@@ -70,6 +70,14 @@ public:
ScalarTy.isPointer() ? ScalarTy.getAddressSpace() : 0};
}
+ static LLT scalarOrVector(uint16_t NumElements, LLT ScalarTy) {
+ return NumElements == 1 ? ScalarTy : LLT::vector(NumElements, ScalarTy);
+ }
+
+ static LLT scalarOrVector(uint16_t NumElements, unsigned ScalarSize) {
+ return scalarOrVector(NumElements, LLT::scalar(ScalarSize));
+ }
+
explicit LLT(bool isPointer, bool isVector, uint16_t NumElements,
unsigned SizeInBits, unsigned AddressSpace) {
init(isPointer, isVector, NumElements, SizeInBits, AddressSpace);
Modified: llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp?rev=352136&r1=352135&r2=352136&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/LowLevelTypeTest.cpp Thu Jan 24 16:10:49 2019
@@ -103,6 +103,21 @@ TEST(LowLevelTypeTest, Vector) {
}
}
+TEST(LowLevelTypeTest, ScalarOrVector) {
+ // Test version with number of bits for scalar type.
+ EXPECT_EQ(LLT::scalar(32), LLT::scalarOrVector(1, 32));
+ EXPECT_EQ(LLT::vector(2, 32), LLT::scalarOrVector(2, 32));
+
+ // Test version with LLT for scalar type.
+ EXPECT_EQ(LLT::scalar(32), LLT::scalarOrVector(1, LLT::scalar(32)));
+ EXPECT_EQ(LLT::vector(2, 32), LLT::scalarOrVector(2, LLT::scalar(32)));
+
+ // Test with pointer elements.
+ EXPECT_EQ(LLT::pointer(1, 32), LLT::scalarOrVector(1, LLT::pointer(1, 32)));
+ EXPECT_EQ(LLT::vector(2, LLT::pointer(1, 32)),
+ LLT::scalarOrVector(2, LLT::pointer(1, 32)));
+}
+
TEST(LowLevelTypeTest, Pointer) {
LLVMContext C;
DataLayout DL("");
More information about the llvm-commits
mailing list