Skip to content

Commit fcc5f9e

Browse files
committed
Generate staging MachineValueType.h (partially) from ValueTypes.td
- Implement `VTEmitter` as `llvm-tblgen -gen-vt`. - Create a copy of `llvm/Support/MachineValueType.h` into `unittests/Support`. It includes `GenVT.inc` generated by `VTEmitter`. - Implement `MVTTest` in `SupportTests`. It checks equivalence between `llvm/Support/MachineValueType.h` and the generated header. Differential Revision: https://reviews.llvm.org/D146906
1 parent 8eb0ef2 commit fcc5f9e

File tree

6 files changed

+260
-509
lines changed

6 files changed

+260
-509
lines changed

llvm/unittests/Support/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/include/llvm/CodeGen/ValueTypes.td)
2+
tablegen(LLVM GenVT.inc -gen-vt)
3+
14
set(LLVM_LINK_COMPONENTS
25
Support
36
TargetParser
@@ -53,6 +56,7 @@ add_llvm_unittest(SupportTests
5356
LockFileManagerTest.cpp
5457
MatchersTest.cpp
5558
MD5Test.cpp
59+
MVTTest.cpp
5660
ManagedStatic.cpp
5761
MathExtrasTest.cpp
5862
MemoryBufferRefTest.cpp
@@ -101,6 +105,7 @@ add_llvm_unittest(SupportTests
101105
raw_pwrite_stream_test.cpp
102106
raw_sha1_ostream_test.cpp
103107
xxhashTest.cpp
108+
GenVT.inc
104109
)
105110

106111
target_link_libraries(SupportTests PRIVATE LLVMTestingSupport)

llvm/unittests/Support/MVTTest.cpp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//===- llvm/unittest/Support/MVTTest.cpp - Test compatibility -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// Make sure the generated version of MachineValueType.h to be equivalent to
10+
// the constant version of llvm/Support/MachineValueType.h.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#include "MachineValueType.h"
15+
#include "llvm/Support/MachineValueType.h"
16+
#include "gtest/gtest.h"
17+
#include <limits>
18+
#include <string>
19+
20+
using namespace llvm;
21+
22+
namespace {
23+
24+
TEST(MVTTest, Properties) {
25+
for (int i = 0; i <= std::numeric_limits<uint8_t>::max(); ++i) {
26+
SCOPED_TRACE("i=" + std::to_string(i));
27+
auto Org = MVT(MVT::SimpleValueType(i));
28+
auto New = tmp::MVT(tmp::MVT::SimpleValueType(i));
29+
30+
#define MVTTEST_EXPECT_EQ_M(LHS, RHS, M) EXPECT_EQ((LHS).M(), (RHS).M())
31+
#define MVTTEST_EXPECT_EQ_SVT(LHS, RHS) \
32+
EXPECT_EQ(int((LHS).SimpleTy), int((RHS).SimpleTy))
33+
#define MVTTEST_EXPECT_EQ_SVT_M(LHS, RHS, M) \
34+
MVTTEST_EXPECT_EQ_SVT((LHS).M(), (RHS).M())
35+
#define MVTTEST_EXPECT_EQ_SVT_F(F, ...) \
36+
MVTTEST_EXPECT_EQ_SVT(MVT::F(__VA_ARGS__), tmp::MVT::F(__VA_ARGS__))
37+
38+
MVTTEST_EXPECT_EQ_M(New, Org, isValid);
39+
MVTTEST_EXPECT_EQ_M(New, Org, isFloatingPoint);
40+
MVTTEST_EXPECT_EQ_M(New, Org, isInteger);
41+
MVTTEST_EXPECT_EQ_M(New, Org, isScalarInteger);
42+
MVTTEST_EXPECT_EQ_M(New, Org, isVector);
43+
MVTTEST_EXPECT_EQ_M(New, Org, isScalableVector);
44+
MVTTEST_EXPECT_EQ_M(New, Org, isScalableTargetExtVT);
45+
MVTTEST_EXPECT_EQ_M(New, Org, isScalableVT);
46+
MVTTEST_EXPECT_EQ_M(New, Org, isFixedLengthVector);
47+
MVTTEST_EXPECT_EQ_M(New, Org, is16BitVector);
48+
MVTTEST_EXPECT_EQ_M(New, Org, is32BitVector);
49+
MVTTEST_EXPECT_EQ_M(New, Org, is64BitVector);
50+
MVTTEST_EXPECT_EQ_M(New, Org, is128BitVector);
51+
MVTTEST_EXPECT_EQ_M(New, Org, is256BitVector);
52+
MVTTEST_EXPECT_EQ_M(New, Org, is512BitVector);
53+
MVTTEST_EXPECT_EQ_M(New, Org, is1024BitVector);
54+
MVTTEST_EXPECT_EQ_M(New, Org, is2048BitVector);
55+
MVTTEST_EXPECT_EQ_M(New, Org, isOverloaded);
56+
if (New.isVector()) {
57+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, changeVectorElementTypeToInteger);
58+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, changeTypeToInteger);
59+
if (New.getVectorElementCount().isKnownEven()) {
60+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getHalfNumVectorElementsVT);
61+
}
62+
MVTTEST_EXPECT_EQ_M(New, Org, isPow2VectorType);
63+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getPow2VectorType);
64+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getVectorElementType);
65+
MVTTEST_EXPECT_EQ_M(New, Org, getVectorMinNumElements);
66+
MVTTEST_EXPECT_EQ_M(New, Org, getVectorElementCount);
67+
68+
auto n = New.getVectorMinNumElements();
69+
auto sc = New.isScalableVector();
70+
auto LHS = tmp::MVT::getVectorVT(New.getVectorElementType(), n, sc);
71+
auto RHS = MVT::getVectorVT(Org.getVectorElementType(), n, sc);
72+
MVTTEST_EXPECT_EQ_SVT(LHS, RHS);
73+
} else if (New.isInteger()) {
74+
auto bw = New.getSizeInBits();
75+
MVTTEST_EXPECT_EQ_SVT_F(getIntegerVT, bw);
76+
} else if (New.isFloatingPoint()) {
77+
auto bw = New.getSizeInBits();
78+
MVTTEST_EXPECT_EQ_SVT_F(getFloatingPointVT, bw);
79+
}
80+
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getScalarType);
81+
if (New.isValid()) {
82+
switch (New.SimpleTy) {
83+
case tmp::MVT::Other:
84+
case tmp::MVT::Glue:
85+
case tmp::MVT::isVoid:
86+
case tmp::MVT::Untyped:
87+
case tmp::MVT::spirvbuiltin:
88+
break;
89+
case tmp::MVT::aarch64svcount:
90+
break;
91+
default:
92+
MVTTEST_EXPECT_EQ_M(New, Org, getSizeInBits);
93+
MVTTEST_EXPECT_EQ_M(New, Org, getScalarSizeInBits);
94+
MVTTEST_EXPECT_EQ_M(New, Org, getStoreSize);
95+
MVTTEST_EXPECT_EQ_M(New, Org, getScalarStoreSize);
96+
MVTTEST_EXPECT_EQ_M(New, Org, getStoreSizeInBits);
97+
MVTTEST_EXPECT_EQ_M(New, Org, isByteSized);
98+
if (!New.isScalableVector()) {
99+
MVTTEST_EXPECT_EQ_M(New, Org, getFixedSizeInBits);
100+
}
101+
break;
102+
}
103+
}
104+
}
105+
}
106+
} // namespace

0 commit comments

Comments
 (0)