[llvm] 1150d84 - [TableGen] Remove unnecessary sorts from writeToStream in InfoByHwMode subclasses. NFC (#218977)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 10:49:42 PDT 2026


Author: Craig Topper
Date: 2026-08-26T17:49:29Z
New Revision: 1150d8440698b3799273d1ac4b05cc1d3433f8aa

URL: https://github.com/llvm/llvm-project/commit/1150d8440698b3799273d1ac4b05cc1d3433f8aa
DIFF: https://github.com/llvm/llvm-project/commit/1150d8440698b3799273d1ac4b05cc1d3433f8aa.diff

LOG: [TableGen] Remove unnecessary sorts from writeToStream in InfoByHwMode subclasses. NFC (#218977)

The underlying map is already sorted by mode, so we can iterate over it.

---------

Co-authored-by: Kazu Hirata <kazu at google.com>

Added: 
    

Modified: 
    llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
    llvm/utils/TableGen/Common/InfoByHwMode.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index c695213b5e9e4..cca943e9c4cad 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 &[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 a666148481d36..035d39cd31bb9 100644
--- a/llvm/utils/TableGen/Common/InfoByHwMode.cpp
+++ b/llvm/utils/TableGen/Common/InfoByHwMode.cpp
@@ -79,16 +79,10 @@ 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 &[Mode, VT] : Map)
+    OS << LS << '(' << getModeName(Mode) << ':' << getMVTName(VT) << ')';
   OS << '}';
 }
 
@@ -167,16 +161,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 &[Mode, Info] : Map)
+    OS << LS << '(' << getModeName(Mode) << ':' << Info << ')';
   OS << '}';
 }
 


        


More information about the llvm-commits mailing list