[llvm] r269635 - ThinLTO: fix another non-determinism in bitcode writing
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 01:50:27 PDT 2016
Author: mehdi_amini
Date: Mon May 16 03:50:27 2016
New Revision: 269635
URL: http://llvm.org/viewvc/llvm-project?rev=269635&view=rev
Log:
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 at apple.com>
Modified:
llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=269635&r1=269634&r2=269635&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon May 16 03:50:27 2016
@@ -3213,8 +3213,15 @@ void ModuleBitcodeWriter::writeModuleLev
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();
More information about the llvm-commits
mailing list