From 2de1a20106913792a81367fd2521c4ede4fd84d6 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Fri, 25 Jan 2019 00:10:49 +0000 Subject: [PATCH] GlobalISel: Add helper to LLT to get a scalar or vector git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352136 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/LowLevelTypeImpl.h | 8 ++++++++ unittests/CodeGen/LowLevelTypeTest.cpp | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/llvm/Support/LowLevelTypeImpl.h b/include/llvm/Support/LowLevelTypeImpl.h index cfa830cd6a3..f81999f3df8 100644 --- a/include/llvm/Support/LowLevelTypeImpl.h +++ b/include/llvm/Support/LowLevelTypeImpl.h @@ -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); diff --git a/unittests/CodeGen/LowLevelTypeTest.cpp b/unittests/CodeGen/LowLevelTypeTest.cpp index 400436f1ddf..684a2cfd395 100644 --- a/unittests/CodeGen/LowLevelTypeTest.cpp +++ b/unittests/CodeGen/LowLevelTypeTest.cpp @@ -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(""); -- 2.50.1