diff options
author | Craig Topper <craig.topper@sifive.com> | 2021-04-18 14:10:06 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@sifive.com> | 2021-04-18 15:59:52 -0700 |
commit | b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942 (patch) | |
tree | ef9b89d83734337906d0dce7dfa5f9cfc43bc9c4 | |
parent | fa6b54c44ab1d5f579304eadb7ac8bd7e72d0e77 (diff) | |
download | llvm-b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942.zip llvm-b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942.tar.gz llvm-b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942.tar.bz2 |
[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.
-rw-r--r-- | llvm/utils/TableGen/CodeGenDAGPatterns.cpp | 19 | ||||
-rw-r--r-- | 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<unsigned> Modes = union_modes(Small, Big); + SmallVector<unsigned, 4> 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<unsigned, 4> 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<unsigned, 4> 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<unsigned, 4> 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<unsigned, 4> 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 <map> -#include <set> #include <string> #include <vector> @@ -37,10 +37,10 @@ enum : unsigned { }; template <typename InfoT> -std::vector<unsigned> union_modes(const InfoByHwMode<InfoT> &A, - const InfoByHwMode<InfoT> &B) { - std::vector<unsigned> V; - std::set<unsigned> U; +void union_modes(const InfoByHwMode<InfoT> &A, + const InfoByHwMode<InfoT> &B, + SmallVectorImpl<unsigned> &Modes) { + SmallSet<unsigned, 4> U; for (const auto &P : A) U.insert(P.first); for (const auto &P : B) @@ -49,12 +49,11 @@ std::vector<unsigned> union_modes(const InfoByHwMode<InfoT> &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 <typename InfoT> |