[llvm] Update ModuleSummaryIndexBitcodeReader::makeCallList reserve amount (PR #95461)

Jan Voung via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 08:12:16 PDT 2024


================
@@ -7332,7 +7332,15 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
                                               bool IsOldProfileFormat,
                                               bool HasProfile, bool HasRelBF) {
   std::vector<FunctionSummary::EdgeTy> Ret;
-  Ret.reserve(Record.size());
+  // In the case of new profile formats, there are two Record entries per
+  // Edge. Otherwise, conservatively reserve up to Record.size and later
+  // shrink_to_fit when we are done (and shrink_to_fit for the exact
+  // case should be a no-op).
+  if (!IsOldProfileFormat && (HasProfile || HasRelBF)) {
----------------
jvoung wrote:

Thanks for taking a look! Yes, shrink_to_fit is only needed in the legacy case right now.

A reason I had added it was as a safeguard in case the format changed in the future, but the `reserve()` parts weren't updated. Then it would provide a bit of protection.

Otherwise, I am happy to remove the shrink_to_fit too.


https://github.com/llvm/llvm-project/pull/95461


More information about the llvm-commits mailing list