[llvm] b7ddd45 - [TableGen] Pass SmallVector to union_modes instead of returning a std::vector.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 18 16:00:55 PDT 2021
Author: Craig Topper
Date: 2021-04-18T15:59:52-07:00
New Revision: b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942
URL: https://github.com/llvm/llvm-project/commit/b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942
DIFF: https://github.com/llvm/llvm-project/commit/b7ddd45081a0bfebb32ab46a7a05ebaf7bc88942.diff
LOG: [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.
Added:
Modified:
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/utils/TableGen/InfoByHwMode.h
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 47e1085b9142..aee232e559ed 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 4233a581a632..c97add687ca2 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>
More information about the llvm-commits
mailing list