[llvm-branch-commits] [llvm] 9c978dd - [TableGen] Fix D90844 introduced non-determinism due to iteration over a std::map over allocated object pointers

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 18 12:13:03 PST 2020


Author: Fangrui Song
Date: 2020-12-18T12:08:16-08:00
New Revision: 9c978dd6e12e5ffaf5441f459db47e9892b09a82

URL: https://github.com/llvm/llvm-project/commit/9c978dd6e12e5ffaf5441f459db47e9892b09a82
DIFF: https://github.com/llvm/llvm-project/commit/9c978dd6e12e5ffaf5441f459db47e9892b09a82.diff

LOG: [TableGen] Fix D90844 introduced non-determinism due to iteration over a std::map over allocated object pointers

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp
index f1bfe42001a3..8b54ff0d1d72 100644
--- a/llvm/utils/TableGen/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/CodeGenSchedule.cpp
@@ -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;
 }
 

diff  --git a/llvm/utils/TableGen/CodeGenSchedule.h b/llvm/utils/TableGen/CodeGenSchedule.h
index 3fa642607b63..9020447c940b 100644
--- a/llvm/utils/TableGen/CodeGenSchedule.h
+++ b/llvm/utils/TableGen/CodeGenSchedule.h
@@ -410,7 +410,7 @@ class STIPredicateFunction {
   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 {


        


More information about the llvm-branch-commits mailing list