[TableGen] Fix D90844 introduced non-determinism due to iteration over a std::map...
authorFangrui Song <i@maskray.me>
Fri, 18 Dec 2020 20:08:16 +0000 (12:08 -0800)
committerFangrui Song <i@maskray.me>
Fri, 18 Dec 2020 20:08:16 +0000 (12:08 -0800)
993eaf2d69d8beb97e4695cbd919b927ed1cfe86 (D90844) is still wrong.
The allocated const Record* pointers do not have an order guarantee
so switching from DenseMap to std::map does not help.

ProcModelMapTy = std::map<const Record*, unsigned>

Sort the values instead.

llvm/utils/TableGen/CodeGenSchedule.cpp
llvm/utils/TableGen/CodeGenSchedule.h

index f1bfe42..8b54ff0 100644 (file)
@@ -1718,6 +1718,9 @@ std::vector<unsigned> CodeGenSchedModels::getAllProcIndices() const {
   for (const auto &PM : ProcModelMap)
     if (PM.second != 0)
       ProcIdVec.push_back(PM.second);
+  // The order of the keys (Record pointers) of ProcModelMap are not stable.
+  // Sort to stabalize the values.
+  llvm::sort(ProcIdVec);
   return ProcIdVec;
 }
 
index 3fa6426..9020447 100644 (file)
@@ -410,7 +410,7 @@ public:
   ArrayRef<OpcodeGroup> getGroups() const { return Groups; }
 };
 
-using ProcModelMapTy = std::map<const Record*, unsigned>;
+using ProcModelMapTy = DenseMap<const Record *, unsigned>;
 
 /// Top level container for machine model data.
 class CodeGenSchedModels {