[PATCH] D57986: [ProfileData] Sort FuncData before iteration to remove non-determinism
Mandeep Singh Grang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 28 20:39:47 PST 2019
mgrang updated this revision to Diff 188843.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57986/new/
https://reviews.llvm.org/D57986
Files:
lib/ProfileData/InstrProfWriter.cpp
Index: lib/ProfileData/InstrProfWriter.cpp
===================================================================
--- lib/ProfileData/InstrProfWriter.cpp
+++ lib/ProfileData/InstrProfWriter.cpp
@@ -376,14 +376,37 @@
if (ProfileKind == PF_IRLevel)
OS << "# IR level Instrumentation Flag\n:ir\n";
InstrProfSymtab Symtab;
- for (const auto &I : FunctionData)
- if (shouldEncodeData(I.getValue()))
+
+ using FuncPair = detail::DenseMapPair<uint64_t, InstrProfRecord>;
+ using RecordType = std::pair<StringRef, FuncPair>;
+
+ SmallVector<RecordType, 4> OrderedFuncData;
+ for (const auto &I : FunctionData) {
+ if (shouldEncodeData(I.getValue())) {
if (Error E = Symtab.addFuncName(I.getKey()))
return E;
-
- for (const auto &I : FunctionData)
- if (shouldEncodeData(I.getValue()))
for (const auto &Func : I.getValue())
- writeRecordInText(I.getKey(), Func.first, Func.second, Symtab, OS);
+ OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
+ }
+ }
+
+ llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
+ auto nameA = A.first;
+ auto nameB = B.first;
+ int comp = nameA.compare(nameB);
+ if (comp)
+ return comp < 0;
+
+ auto hashA = A.second.first;
+ auto hashB = B.second.first;
+ return hashA < hashB;
+ });
+
+ for (const auto &record : OrderedFuncData) {
+ const auto &name = record.first;
+ const auto &Func = record.second;
+ writeRecordInText(name, Func.first, Func.second, Symtab, OS);
+ }
+
return Error::success();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57986.188843.patch
Type: text/x-patch
Size: 1827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190301/2071c238/attachment.bin>
More information about the cfe-commits
mailing list