Skip to content

Commit

Permalink
Generate staging MachineValueType.h (partially) from ValueTypes.td
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
chapuni committed Apr 13, 2023
1 parent 8eb0ef2 commit fcc5f9e
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 509 deletions.
5 changes: 5 additions & 0 deletions llvm/unittests/Support/CMakeLists.txt
@@ -1,3 +1,6 @@
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/include/llvm/CodeGen/ValueTypes.td)
tablegen(LLVM GenVT.inc -gen-vt)

set(LLVM_LINK_COMPONENTS
Support
TargetParser
Expand Down Expand Up @@ -53,6 +56,7 @@ add_llvm_unittest(SupportTests
LockFileManagerTest.cpp
MatchersTest.cpp
MD5Test.cpp
MVTTest.cpp
ManagedStatic.cpp
MathExtrasTest.cpp
MemoryBufferRefTest.cpp
Expand Down Expand Up @@ -101,6 +105,7 @@ add_llvm_unittest(SupportTests
raw_pwrite_stream_test.cpp
raw_sha1_ostream_test.cpp
xxhashTest.cpp
GenVT.inc
)

target_link_libraries(SupportTests PRIVATE LLVMTestingSupport)
Expand Down
106 changes: 106 additions & 0 deletions llvm/unittests/Support/MVTTest.cpp
@@ -0,0 +1,106 @@
//===- llvm/unittest/Support/MVTTest.cpp - Test compatibility -------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Make sure the generated version of MachineValueType.h to be equivalent to
// the constant version of llvm/Support/MachineValueType.h.
//
//===----------------------------------------------------------------------===//

#include "MachineValueType.h"
#include "llvm/Support/MachineValueType.h"
#include "gtest/gtest.h"
#include <limits>
#include <string>

using namespace llvm;

namespace {

TEST(MVTTest, Properties) {
for (int i = 0; i <= std::numeric_limits<uint8_t>::max(); ++i) {
SCOPED_TRACE("i=" + std::to_string(i));
auto Org = MVT(MVT::SimpleValueType(i));
auto New = tmp::MVT(tmp::MVT::SimpleValueType(i));

#define MVTTEST_EXPECT_EQ_M(LHS, RHS, M) EXPECT_EQ((LHS).M(), (RHS).M())
#define MVTTEST_EXPECT_EQ_SVT(LHS, RHS) \
EXPECT_EQ(int((LHS).SimpleTy), int((RHS).SimpleTy))
#define MVTTEST_EXPECT_EQ_SVT_M(LHS, RHS, M) \
MVTTEST_EXPECT_EQ_SVT((LHS).M(), (RHS).M())
#define MVTTEST_EXPECT_EQ_SVT_F(F, ...) \
MVTTEST_EXPECT_EQ_SVT(MVT::F(__VA_ARGS__), tmp::MVT::F(__VA_ARGS__))

MVTTEST_EXPECT_EQ_M(New, Org, isValid);
MVTTEST_EXPECT_EQ_M(New, Org, isFloatingPoint);
MVTTEST_EXPECT_EQ_M(New, Org, isInteger);
MVTTEST_EXPECT_EQ_M(New, Org, isScalarInteger);
MVTTEST_EXPECT_EQ_M(New, Org, isVector);
MVTTEST_EXPECT_EQ_M(New, Org, isScalableVector);
MVTTEST_EXPECT_EQ_M(New, Org, isScalableTargetExtVT);
MVTTEST_EXPECT_EQ_M(New, Org, isScalableVT);
MVTTEST_EXPECT_EQ_M(New, Org, isFixedLengthVector);
MVTTEST_EXPECT_EQ_M(New, Org, is16BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is32BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is64BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is128BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is256BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is512BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is1024BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, is2048BitVector);
MVTTEST_EXPECT_EQ_M(New, Org, isOverloaded);
if (New.isVector()) {
MVTTEST_EXPECT_EQ_SVT_M(New, Org, changeVectorElementTypeToInteger);
MVTTEST_EXPECT_EQ_SVT_M(New, Org, changeTypeToInteger);
if (New.getVectorElementCount().isKnownEven()) {
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getHalfNumVectorElementsVT);
}
MVTTEST_EXPECT_EQ_M(New, Org, isPow2VectorType);
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getPow2VectorType);
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getVectorElementType);
MVTTEST_EXPECT_EQ_M(New, Org, getVectorMinNumElements);
MVTTEST_EXPECT_EQ_M(New, Org, getVectorElementCount);

auto n = New.getVectorMinNumElements();
auto sc = New.isScalableVector();
auto LHS = tmp::MVT::getVectorVT(New.getVectorElementType(), n, sc);
auto RHS = MVT::getVectorVT(Org.getVectorElementType(), n, sc);
MVTTEST_EXPECT_EQ_SVT(LHS, RHS);
} else if (New.isInteger()) {
auto bw = New.getSizeInBits();
MVTTEST_EXPECT_EQ_SVT_F(getIntegerVT, bw);
} else if (New.isFloatingPoint()) {
auto bw = New.getSizeInBits();
MVTTEST_EXPECT_EQ_SVT_F(getFloatingPointVT, bw);
}
MVTTEST_EXPECT_EQ_SVT_M(New, Org, getScalarType);
if (New.isValid()) {
switch (New.SimpleTy) {
case tmp::MVT::Other:
case tmp::MVT::Glue:
case tmp::MVT::isVoid:
case tmp::MVT::Untyped:
case tmp::MVT::spirvbuiltin:
break;
case tmp::MVT::aarch64svcount:
break;
default:
MVTTEST_EXPECT_EQ_M(New, Org, getSizeInBits);
MVTTEST_EXPECT_EQ_M(New, Org, getScalarSizeInBits);
MVTTEST_EXPECT_EQ_M(New, Org, getStoreSize);
MVTTEST_EXPECT_EQ_M(New, Org, getScalarStoreSize);
MVTTEST_EXPECT_EQ_M(New, Org, getStoreSizeInBits);
MVTTEST_EXPECT_EQ_M(New, Org, isByteSized);
if (!New.isScalableVector()) {
MVTTEST_EXPECT_EQ_M(New, Org, getFixedSizeInBits);
}
break;
}
}
}
}
} // namespace

0 comments on commit fcc5f9e

Please sign in to comment.