From 367577aab9721ccdb46abe7b8bd3b5f9a01728a0 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 --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index c8248fe8179b..8722b88a2f91 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/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);