[llvm] 6de2735 - [TableGen][GlobalISel] Use MapVector to stabilize iteration order after D153757

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 21:21:31 PDT 2023


Author: Fangrui Song
Date: 2023-07-19T21:21:26-07:00
New Revision: 6de2735c2428789f99a26bee66030ddfb0841b9e

URL: https://github.com/llvm/llvm-project/commit/6de2735c2428789f99a26bee66030ddfb0841b9e
DIFF: https://github.com/llvm/llvm-project/commit/6de2735c2428789f99a26bee66030ddfb0841b9e.diff

LOG: [TableGen][GlobalISel] Use MapVector to stabilize iteration order after D153757

StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).

Added: 
    

Modified: 
    llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
index 1a391e96e7b81d..c1186fb324dcd7 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerMatchTableEmitter.cpp
@@ -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 @@ class CombineRuleBuilder {
   /// 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++);


        


More information about the llvm-commits mailing list