[llvm] r269629 - ThinLTO: fix non-determinism in bitcode writing

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Sun May 15 21:50:48 PDT 2016


Author: mehdi_amini
Date: Sun May 15 23:50:47 2016
New Revision: 269629

URL: http://llvm.org/viewvc/llvm-project?rev=269629&view=rev
Log:
ThinLTO: fix non-determinism in bitcode writing

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=269629&r1=269628&r2=269629&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Sun May 15 23:50:47 2016
@@ -3168,8 +3168,14 @@ void ModuleBitcodeWriter::writePerModule
   NameVals.push_back(FS->instCount());
   NameVals.push_back(FS->refs().size());
 
+  // Compute refs in a separate vector to be able to sort them for determinism.
+  std::vector<uint64_t> Refs;
+  Refs.reserve(FS->refs().size());
   for (auto &RI : FS->refs())
-    NameVals.push_back(VE.getValueID(RI.getValue()));
+    Refs.push_back(VE.getValueID(RI.getValue()));
+  std::sort(Refs.begin(), Refs.end());
+
+  NameVals.insert(NameVals.end(), Refs.begin(), Refs.end());
 
   bool HasProfileData = F.getEntryCount().hasValue();
   for (auto &ECI : FS->calls()) {




More information about the llvm-commits mailing list