diff options
author | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 22:47:15 +0000 |
---|---|---|
committer | Mehdi Amini <mehdi.amini@apple.com> | 2016-05-16 22:47:15 +0000 |
commit | fdbb8f47eb9984dcbffd66123c196f7da8a3c421 (patch) | |
tree | be8a54c5e938ede93590d12da8da15ade8049cf3 | |
parent | e7d833defb62c1e4a1944cbad740f540c0ab44d2 (diff) | |
download | bcm5719-llvm-fdbb8f47eb9984dcbffd66123c196f7da8a3c421.tar.gz bcm5719-llvm-fdbb8f47eb9984dcbffd66123c196f7da8a3c421.zip |
Avoid temporary vector for sorting in BitcodeWriter
As suggested by Duncan, fixup for r269634 and r269635
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 269715
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 8722b88a2f9..ec3ecb2287e 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -3168,14 +3168,12 @@ void ModuleBitcodeWriter::writePerModuleFunctionSummaryRecord( 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::writeModuleLevelReferences( 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); |