ThinLTO: fix non-determinism in bitcode writing

Calls are initialized from a DenseMap. We can sort them using the
value id to recover some determinism during serialization.

From: mehdi_amini <mehdi_amini@91177308-0d34-0410-b5e6-96231b3b80d8>
llvm-svn: 269638
This commit is contained in:
Mehdi Amini 2016-05-16 09:04:55 +00:00
parent fe97408495
commit 367577aab9
1 changed files with 8 additions and 1 deletions

View File

@ -3177,8 +3177,15 @@ void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord(
NameVals.insert(NameVals.end(), Refs.begin(), Refs.end());
std::vector<FunctionSummary::EdgeTy> Calls = FS->calls();
std::sort(Calls.begin(), Calls.end(),
[this](const FunctionSummary::EdgeTy &L,
const FunctionSummary::EdgeTy &R) {
return VE.getValueID(L.first.getValue()) <
VE.getValueID(R.first.getValue());
});
bool HasProfileData = F.getEntryCount().hasValue();
for (auto &ECI : FS->calls()) {
for (auto &ECI : Calls) {
NameVals.push_back(VE.getValueID(ECI.first.getValue()));
assert(ECI.second.CallsiteCount > 0 && "Expected at least one callsite");
NameVals.push_back(ECI.second.CallsiteCount);