From 028250d333a994fefa555150e2038e009716ceb7 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Mon, 16 May 2016 09:04:55 +0000 Subject: [PATCH] ThinLTO: fix non-determinism in bitcode writing Calls are initialized from a DenseMap. We can sort them using the value id to recover some determinism during serialization. From: mehdi_amini llvm-svn: 269638 --- lib/Bitcode/Writer/BitcodeWriter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index c8248fe8179..8722b88a2f9 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3177,8 +3177,15 @@ void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord( NameVals.insert(NameVals.end(), Refs.begin(), Refs.end()); + std::vector Calls = FS->calls(); + std::sort(Calls.begin(), Calls.end(), + [this](const FunctionSummary::EdgeTy &L, + const FunctionSummary::EdgeTy &R) { + return VE.getValueID(L.first.getValue()) < + VE.getValueID(R.first.getValue()); + }); bool HasProfileData = F.getEntryCount().hasValue(); - for (auto &ECI : FS->calls()) { + for (auto &ECI : Calls) { NameVals.push_back(VE.getValueID(ECI.first.getValue())); assert(ECI.second.CallsiteCount > 0 && "Expected at least one callsite"); NameVals.push_back(ECI.second.CallsiteCount);