diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 08:50:27 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 08:50:27 +0000 |
commit | f606c8d633e288a7d2ac95f7372af374dcab7f39 (patch) | |
tree | 8f6f5c9362f48c3f6f20ab9ff44e85c57fd26288 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | 564c49a9389dd0260fa2424e894ff5f9b82bfab4 (diff) | |
download | llvm-f606c8d633e288a7d2ac95f7372af374dcab7f39.zip llvm-f606c8d633e288a7d2ac95f7372af374dcab7f39.tar.gz llvm-f606c8d633e288a7d2ac95f7372af374dcab7f39.tar.bz2 |
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
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index fff15e9..50e4ffe 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -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(); |