Skip to content

Commit

Permalink
[ProfileData] Sort FuncData before iteration to remove non-determinism
Browse files Browse the repository at this point in the history
Reviewers: rsmith, bogner, dblaikie

Reviewed By: dblaikie

Subscribers: Hahnfeld, jdoerfert, vsk, dblaikie, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57986

llvm-svn: 355252
  • Loading branch information
Mandeep Singh Grang committed Mar 2, 2019
1 parent a8af6ca commit a14f20c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions llvm/lib/ProfileData/InstrProfWriter.cpp
Expand Up @@ -408,14 +408,30 @@ Error InstrProfWriter::writeText(raw_fd_ostream &OS) {
else if (ProfileKind == PF_IRLevelWithCS)
OS << "# CSIR level Instrumentation Flag\n:csir\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) {
return std::tie(A.first, A.second.first) <
std::tie(B.first, B.second.first);
});

for (const auto &record : OrderedFuncData) {
const StringRef &Name = record.first;
const FuncPair &Func = record.second;
writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
}

return Error::success();
}

0 comments on commit a14f20c

Please sign in to comment.