[TableGen][GlobalISel] Use MapVector to stabilize iteration order after D153757
authorFangrui Song <i@maskray.me>
Thu, 20 Jul 2023 04:21:26 +0000 (21:21 -0700)
committerFangrui Song <i@maskray.me>
Thu, 20 Jul 2023 04:21:26 +0000 (21:21 -0700)
StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).

llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp

index 1a391e9..c1186fb 100644 (file)
@@ -20,6 +20,7 @@
 #include "GlobalISelMatchTableExecutorEmitter.h"
 #include "SubtargetFeatureInfo.h"
 #include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CommandLine.h"
@@ -552,7 +553,7 @@ private:
   /// Set by findRoots.
   Pattern *MatchRoot = nullptr;
 
-  StringMap<OperandTableEntry> OperandTable;
+  MapVector<StringRef, OperandTableEntry> OperandTable;
   SmallVector<MatchDataInfo, 2> MatchDatas;
 };
 
@@ -640,9 +641,8 @@ void CombineRuleBuilder::print(raw_ostream &OS) const {
     OS << "<empty>)\n";
   else {
     OS << "\n";
-    for (const auto &Entry : OperandTable) {
-      OS << "    [" << Entry.getKey();
-      auto &Val = Entry.getValue();
+    for (const auto &[Key, Val] : OperandTable) {
+      OS << "    [" << Key;
       if (const auto *P = Val.MatchPat)
         OS << " match_pat:" << P->getName();
       if (const auto *P = Val.ApplyPat)
@@ -1106,7 +1106,7 @@ bool CombineRuleBuilder::emitInstructionMatchPattern(
 
   unsigned OpIdx = 0;
   for (auto &O : P.operands()) {
-    auto &OpTableEntry = OperandTable.at(O.Name);
+    auto &OpTableEntry = OperandTable.find(O.Name)->second;
 
     OperandMatcher &OM =
         IM.addOperand(OpIdx++, O.Name, AllocatedTemporariesBaseID++);