[llvm] r269715 - Avoid temporary vector for sorting in BitcodeWriter
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Mon May 16 15:47:15 PDT 2016
Author: mehdi_amini
Date: Mon May 16 17:47:15 2016
New Revision: 269715
URL: http://llvm.org/viewvc/llvm-project?rev=269715&view=rev
Log:
Avoid temporary vector for sorting in BitcodeWriter
As suggested by Duncan, fixup for r269634 and r269635
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=269715&r1=269714&r2=269715&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon May 16 17:47:15 2016
@@ -3168,14 +3168,12 @@ 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;
- Refs.reserve(FS->refs().size());
+ unsigned SizeBeforeRefs = NameVals.size();
for (auto &RI : FS->refs())
- Refs.push_back(VE.getValueID(RI.getValue()));
- std::sort(Refs.begin(), Refs.end());
-
- NameVals.insert(NameVals.end(), Refs.begin(), Refs.end());
+ NameVals.push_back(VE.getValueID(RI.getValue()));
+ // Sort the refs for determinism output, the vector returned by FS->refs() has
+ // been initialized from a DenseSet.
+ std::sort(NameVals.begin() + SizeBeforeRefs, NameVals.end());
std::vector<FunctionSummary::EdgeTy> Calls = FS->calls();
std::sort(Calls.begin(), Calls.end(),
@@ -3215,13 +3213,12 @@ void ModuleBitcodeWriter::writeModuleLev
auto *Summary = Index->getGlobalValueSummary(V);
GlobalVarSummary *VS = cast<GlobalVarSummary>(Summary);
- // Compute refs in a separate vector to be able to sort them for determinism.
- std::vector<uint64_t> Refs;
- Refs.reserve(VS->refs().size());
+ unsigned SizeBeforeRefs = NameVals.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());
+ NameVals.push_back(VE.getValueID(RI.getValue()));
+ // Sort the refs for determinism output, the vector returned by FS->refs() has
+ // been initialized from a DenseSet.
+ std::sort(NameVals.begin() + SizeBeforeRefs, NameVals.end());
Stream.EmitRecord(bitc::FS_PERMODULE_GLOBALVAR_INIT_REFS, NameVals,
FSModRefsAbbrev);
More information about the llvm-commits
mailing list