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

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Mon May 16 13:41:39 PDT 2016


> On 2016-May-16, at 01:50, Mehdi Amini via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> Author: mehdi_amini
> Date: Mon May 16 03:50:27 2016
> New Revision: 269635
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=269635&view=rev
> Log:
> ThinLTO: fix another non-determinism in bitcode writing
> 
> GlobalVars 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=269635&r1=269634&r2=269635&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon May 16 03:50:27 2016
> @@ -3213,8 +3213,15 @@ void ModuleBitcodeWriter::writeModuleLev
>   NameVals.push_back(getEncodedGVSummaryFlags(V));
>   auto *Summary = Index->getGlobalValueSummary(V);
>   GlobalVarSummary *VS = cast<GlobalVarSummary>(Summary);
> -  for (auto Ref : VS->refs())
> -    NameVals.push_back(VE.getValueID(Ref.getValue()));
> +
> +  // Compute refs in a separate vector to be able to sort them for determinism.
> +  std::vector<uint64_t> Refs;
> +  Refs.reserve(VS->refs().size());
> +  for (auto &RI : VS->refs())
> +    Refs.push_back(VE.getValueID(RI.getValue()));
> +  std::sort(Refs.begin(), Refs.end());
> +  NameVals.insert(NameVals.end(), Refs.begin(), Refs.end());

Same comment as r269634: there's no need for an auxiliary std::vector here.

> +
>   Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals,
>                     FSModRefsAbbrev);
>   NameVals.clear();
> 
> 
> _______________________________________________
> 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