From efdbbbabac59ec701402d463daabd44a060f6ac2 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 16 May 2016 04:50:47 +0000 Subject: [PATCH] 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269629 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 050294da166..1bd2e6f9b99 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3168,8 +3168,14 @@ void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord( 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 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()) {