[TableGen] Remove an assumption about the order of encodings in the MVT::SimpleValueType enum. Instead of assuming the types are sorted by size, scan the typeset arrays to find the smallest/largest type. NFC

llvm-svn: 254589
This commit is contained in:
Craig Topper 2015-12-03 05:57:37 +00:00
parent 8be7499507
commit 1282df50c4
1 changed files with 13 additions and 2 deletions

View File

@ -388,7 +388,13 @@ bool EEVT::TypeSet::EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP) {
// the size of the smallest type.
{
TypeSet InputSet(Other);
MVT Smallest = TypeVec[0];
MVT Smallest = *std::min_element(TypeVec.begin(), TypeVec.end(),
[](MVT A, MVT B) {
return A.getScalarSizeInBits() < B.getScalarSizeInBits() ||
(A.getScalarSizeInBits() == B.getScalarSizeInBits() &&
A.getSizeInBits() < B.getSizeInBits());
});
auto I = std::remove_if(Other.TypeVec.begin(), Other.TypeVec.end(),
[Smallest](MVT OtherVT) {
// Don't compare vector and non-vector types.
@ -416,7 +422,12 @@ bool EEVT::TypeSet::EnforceSmallerThan(EEVT::TypeSet &Other, TreePattern &TP) {
// the size of the largest type.
{
TypeSet InputSet(*this);
MVT Largest = Other.TypeVec[Other.TypeVec.size()-1];
MVT Largest = *std::max_element(Other.TypeVec.begin(), Other.TypeVec.end(),
[](MVT A, MVT B) {
return A.getScalarSizeInBits() < B.getScalarSizeInBits() ||
(A.getScalarSizeInBits() == B.getScalarSizeInBits() &&
A.getSizeInBits() < B.getSizeInBits());
});
auto I = std::remove_if(TypeVec.begin(), TypeVec.end(),
[Largest](MVT OtherVT) {
// Don't compare vector and non-vector types.