[llvm] r269629 - ThinLTO: fix non-determinism in bitcode writing
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 13:39:40 PDT 2016
> On 2016-May-15, at 21:50, Mehdi Amini via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> 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
You committed a bunch of these. It would be great if the subjects somehow described what was different about them. E.g., "ThinLTO: Fix non-determinism when refs to bitcode".
> 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;
I would probably add a scope around this variable to make it clear that it's dead.
> + 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());
You don't need a separate vector/allocation. Instead:
--
{
unsigned SizeBeforeRefs = NameVals.size();
for (...)
NameVals.push_back(...);
std::sort(NameVals.begin() + SizeBeforeRefs, NameVals.end());
}
--
>
> bool HasProfileData = F.getEntryCount().hasValue();
> for (auto &ECI : FS->calls()) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list