From b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 18 Apr 2021 14:10:06 -0700 Subject: [PATCH] [TableGen] Pass SmallVector to union_modes instead of returning a std::vector. The number of modes is small so this should avoid a heap allocation. Also replace std::set with SmallSet. --- llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 19 ++++++++++++++----- llvm/utils/TableGen/InfoByHwMode.h | 15 +++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp index 47e1085..aee232e 100644 --- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp @@ -466,7 +466,8 @@ bool TypeInfer::EnforceSmallerThan(TypeSetByHwMode &Small, assert(Small.hasDefault() && Big.hasDefault()); - std::vector Modes = union_modes(Small, Big); + SmallVector Modes; + union_modes(Small, Big, Modes); // 1. Only allow integer or floating point types and make sure that // both sides are both integer or both floating point. @@ -573,7 +574,9 @@ bool TypeInfer::EnforceVectorEltTypeIs(TypeSetByHwMode &Vec, if (Elem.empty()) Changed |= EnforceScalar(Elem); - for (unsigned M : union_modes(Vec, Elem)) { + SmallVector Modes; + union_modes(Vec, Elem, Modes); + for (unsigned M : Modes) { TypeSetByHwMode::SetType &V = Vec.get(M); TypeSetByHwMode::SetType &E = Elem.get(M); @@ -656,7 +659,9 @@ bool TypeInfer::EnforceVectorSubVectorTypeIs(TypeSetByHwMode &Vec, if (Sub.empty()) Changed |= EnforceVector(Sub); - for (unsigned M : union_modes(Vec, Sub)) { + SmallVector Modes; + union_modes(Vec, Sub, Modes); + for (unsigned M : Modes) { TypeSetByHwMode::SetType &S = Sub.get(M); TypeSetByHwMode::SetType &V = Vec.get(M); @@ -696,7 +701,9 @@ bool TypeInfer::EnforceSameNumElts(TypeSetByHwMode &V, TypeSetByHwMode &W) { return !Lengths.count(T.isVector() ? T.getVectorNumElements() : 0); }; - for (unsigned M : union_modes(V, W)) { + SmallVector Modes; + union_modes(V, W, Modes); + for (unsigned M : Modes) { TypeSetByHwMode::SetType &VS = V.get(M); TypeSetByHwMode::SetType &WS = W.get(M); @@ -741,7 +748,9 @@ bool TypeInfer::EnforceSameSize(TypeSetByHwMode &A, TypeSetByHwMode &B) { return !Sizes.count(T.getSizeInBits()); }; - for (unsigned M : union_modes(A, B)) { + SmallVector Modes; + union_modes(A, B, Modes); + for (unsigned M : Modes) { TypeSetByHwMode::SetType &AS = A.get(M); TypeSetByHwMode::SetType &BS = B.get(M); TypeSizeSet AN, BN; diff --git a/llvm/utils/TableGen/InfoByHwMode.h b/llvm/utils/TableGen/InfoByHwMode.h index 4233a58..c97add6 100644 --- a/llvm/utils/TableGen/InfoByHwMode.h +++ b/llvm/utils/TableGen/InfoByHwMode.h @@ -15,10 +15,10 @@ #define LLVM_UTILS_TABLEGEN_INFOBYHWMODE_H #include "CodeGenHwModes.h" +#include "llvm/ADT/SmallSet.h" #include "llvm/Support/MachineValueType.h" #include -#include #include #include @@ -37,10 +37,10 @@ enum : unsigned { }; template -std::vector union_modes(const InfoByHwMode &A, - const InfoByHwMode &B) { - std::vector V; - std::set U; +void union_modes(const InfoByHwMode &A, + const InfoByHwMode &B, + SmallVectorImpl &Modes) { + SmallSet U; for (const auto &P : A) U.insert(P.first); for (const auto &P : B) @@ -49,12 +49,11 @@ std::vector union_modes(const InfoByHwMode &A, bool HasDefault = false; for (unsigned M : U) if (M != DefaultMode) - V.push_back(M); + Modes.push_back(M); else HasDefault = true; if (HasDefault) - V.push_back(DefaultMode); - return V; + Modes.push_back(DefaultMode); } template -- 2.7.4