Skip to content

Commit 9c978dd

Browse files
committed
[TableGen] Fix D90844 introduced non-determinism due to iteration over a std::map over allocated object pointers
993eaf2 (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.
1 parent 2af2f58 commit 9c978dd

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/utils/TableGen/CodeGenSchedule.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,9 @@ std::vector<unsigned> CodeGenSchedModels::getAllProcIndices() const {
17181718
for (const auto &PM : ProcModelMap)
17191719
if (PM.second != 0)
17201720
ProcIdVec.push_back(PM.second);
1721+
// The order of the keys (Record pointers) of ProcModelMap are not stable.
1722+
// Sort to stabalize the values.
1723+
llvm::sort(ProcIdVec);
17211724
return ProcIdVec;
17221725
}
17231726

llvm/utils/TableGen/CodeGenSchedule.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class STIPredicateFunction {
410410
ArrayRef<OpcodeGroup> getGroups() const { return Groups; }
411411
};
412412

413-
using ProcModelMapTy = std::map<const Record*, unsigned>;
413+
using ProcModelMapTy = DenseMap<const Record *, unsigned>;
414414

415415
/// Top level container for machine model data.
416416
class CodeGenSchedModels {

0 commit comments

Comments
 (0)