ThinLTO: fix another non-determinism in bitcode writing

GlobalVars Refs are initialized from a DenseSet. We can sort them
using the value id to recover some determinism during serialization.

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 269635
This commit is contained in:
Mehdi Amini 2016-05-16 08:50:27 +00:00
parent 564c49a938
commit f606c8d633
1 changed files with 9 additions and 2 deletions

View File

@ -3213,8 +3213,15 @@ void ModuleBitcodeWriter::writeModuleLevelReferences(
NameVals.push_back(getEncodedGVSummaryFlags(V));
auto *Summary = Index->getGlobalValueSummary(V);
GlobalVarSummary *VS = cast<GlobalVarSummary>(Summary);
for (auto Ref : VS->refs())
NameVals.push_back(VE.getValueID(Ref.getValue()));
// Compute refs in a separate vector to be able to sort them for determinism.
std::vector<uint64_t> Refs;
Refs.reserve(VS->refs().size());
for (auto &RI : VS->refs())
Refs.push_back(VE.getValueID(RI.getValue()));
std::sort(Refs.begin(), Refs.end());
NameVals.insert(NameVals.end(), Refs.begin(), Refs.end());
Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals,
FSModRefsAbbrev);
NameVals.clear();