diff options
author | Mandeep Singh Grang <mgrang@quicinc.com> | 2019-03-02 00:47:43 +0000 |
---|---|---|
committer | Mandeep Singh Grang <mgrang@quicinc.com> | 2019-03-02 00:47:43 +0000 |
commit | a14f20c5b3be18f63216091ee787428c734bed3d (patch) | |
tree | 29c3bc5f518a0cd4e57bb8c061c5a79d21c21ecd /llvm/lib | |
parent | a8af6ca065239865eaa28fae9abbce71b61d92f1 (diff) | |
download | bcm5719-llvm-a14f20c5b3be18f63216091ee787428c734bed3d.tar.gz bcm5719-llvm-a14f20c5b3be18f63216091ee787428c734bed3d.zip |
[ProfileData] Sort FuncData before iteration to remove non-determinism
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
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/ProfileData/InstrProfWriter.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index 3aaa193d687..38562e02fa6 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -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(); } |