[llvm] [TableGen] Remove unnecessary sorts from writeToStream in InfoByHwMode subclasses. NFC (PR #218977)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 09:49:39 PDT 2026
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/218977
>From ed717cfe62d93e9a8644919147f3b7b22bc042dc Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 26 Aug 2026 08:43:26 -0700
Subject: [PATCH 1/2] [TableGen] Remove unnecessary sorts from writeToStream in
InfoByHwMode subclasses. NFC
The underlying map is already sorted by mode, so we can iterate over it.
---
.../TableGen/Common/CodeGenDAGPatterns.cpp | 15 ++++---------
llvm/utils/TableGen/Common/InfoByHwMode.cpp | 21 +++++--------------
2 files changed, 9 insertions(+), 27 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index c695213b5e9e4..9c2513088f7c7 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -188,21 +188,14 @@ bool TypeSetByHwMode::assign_if(const TypeSetByHwMode &VTS, Predicate P) {
}
void TypeSetByHwMode::writeToStream(raw_ostream &OS) const {
- SmallVector<unsigned, 4> Modes;
- Modes.reserve(Map.size());
-
- for (const auto &I : *this)
- Modes.push_back(I.first);
- if (Modes.empty()) {
+ if (Map.empty()) {
OS << "{}";
return;
}
- array_pod_sort(Modes.begin(), Modes.end());
-
OS << '{';
- for (unsigned M : Modes) {
- OS << ' ' << getModeName(M) << ':';
- get(M).writeToStream(OS);
+ for (const auto &P : Map) {
+ OS << ' ' << getModeName(P.first) << ':';
+ P.second.writeToStream(OS);
}
OS << " }";
}
diff --git a/llvm/utils/TableGen/Common/InfoByHwMode.cpp b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
index a666148481d36..70d4b49362120 100644
--- a/llvm/utils/TableGen/Common/InfoByHwMode.cpp
+++ b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
@@ -79,16 +79,11 @@ void ValueTypeByHwMode::writeToStream(raw_ostream &OS) const {
return;
}
- std::vector<const PairType *> Pairs;
- for (const auto &P : Map)
- Pairs.push_back(&P);
- llvm::sort(Pairs, deref<std::less<PairType>>());
-
OS << '{';
ListSeparator LS(",");
- for (const PairType *P : Pairs)
- OS << LS << '(' << getModeName(P->first) << ':'
- << getMVTName(P->second).str() << ')';
+ for (const auto &P : Map)
+ OS << LS << '(' << getModeName(P.first) << ':' << getMVTName(P.second).str()
+ << ')';
OS << '}';
}
@@ -167,16 +162,10 @@ bool RegSizeInfoByHwMode::hasStricterSpillThan(
}
void RegSizeInfoByHwMode::writeToStream(raw_ostream &OS) const {
- using PairType = decltype(Map)::value_type;
- std::vector<const PairType *> Pairs;
- for (const auto &P : Map)
- Pairs.push_back(&P);
- llvm::sort(Pairs, deref<std::less<PairType>>());
-
OS << '{';
ListSeparator LS(",");
- for (const PairType *P : Pairs)
- OS << LS << '(' << getModeName(P->first) << ':' << P->second << ')';
+ for (const auto &P : Map)
+ OS << LS << '(' << getModeName(P.first) << ':' << P.second << ')';
OS << '}';
}
>From e037b2412acd0aa4bdb35d90d92fee843ceeb983 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Wed, 26 Aug 2026 09:49:30 -0700
Subject: [PATCH 2/2] Apply suggestions from code review
Co-authored-by: Kazu Hirata <kazu at google.com>
---
llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 6 +++---
llvm/utils/TableGen/Common/InfoByHwMode.cpp | 8 ++++----
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 9c2513088f7c7..cca943e9c4cad 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -193,9 +193,9 @@ void TypeSetByHwMode::writeToStream(raw_ostream &OS) const {
return;
}
OS << '{';
- for (const auto &P : Map) {
- OS << ' ' << getModeName(P.first) << ':';
- P.second.writeToStream(OS);
+ for (const auto &[Mode, Types] : Map) {
+ OS << ' ' << getModeName(Mode) << ':';
+ Types.writeToStream(OS);
}
OS << " }";
}
diff --git a/llvm/utils/TableGen/Common/InfoByHwMode.cpp b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
index 70d4b49362120..72caecac7c00f 100644
--- a/llvm/utils/TableGen/Common/InfoByHwMode.cpp
+++ b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
@@ -81,8 +81,8 @@ void ValueTypeByHwMode::writeToStream(raw_ostream &OS) const {
OS << '{';
ListSeparator LS(",");
- for (const auto &P : Map)
- OS << LS << '(' << getModeName(P.first) << ':' << getMVTName(P.second).str()
+ for (const auto &[Mode, VT] : Map)
+ OS << LS << '(' << getModeName(Mode) << ':' << getMVTName(VT).str()
<< ')';
OS << '}';
}
@@ -164,8 +164,8 @@ bool RegSizeInfoByHwMode::hasStricterSpillThan(
void RegSizeInfoByHwMode::writeToStream(raw_ostream &OS) const {
OS << '{';
ListSeparator LS(",");
- for (const auto &P : Map)
- OS << LS << '(' << getModeName(P.first) << ':' << P.second << ')';
+ for (const auto &[Mode, Info] : Map)
+ OS << LS << '(' << getModeName(Mode) << ':' << Info << ')';
OS << '}';
}
More information about the llvm-commits
mailing list