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

Jan Voung via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 12:42:38 PDT 2024


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

Tighten the reserve() to `Record.size() / 2` instead of `Record.size()`
in the HasProfile/HasRelBF cases (or even / 3 for IsOldProfileFormat).
This reduces peak memory during ThinLTO indexing by ~3% in one example.

Alternatively, we could reserve and then shrink_to_fit(), but seemed
like we should just reserve the right amount (though that is a little
more complex code).


>From 0852462b3aa0cfb06d4a3c2fa8e1f4369f3dfc11 Mon Sep 17 00:00:00 2001
From: Jan Voung <jvoung at gmail.com>
Date: Thu, 13 Jun 2024 18:06:15 +0000
Subject: [PATCH] Update ModuleSummaryIndexBitcodeReader::makeCallList reserve
 amount

Tighten the reserve() to `Record.size() / 2` instead of `Record.size()`
in the HasProfile/HasRelBF cases (or even / 3 for IsOldProfileFormat).
This reduces peak memory during ThinLTO indexing by ~3% in one example.

Alternatively, we could reserve and then shrink_to_fit(), but seemed
like we should just reserve the right amount (though that is a little
more complex code).
---
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 4ad3a2eaceea9..2309bdba684cd 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7332,7 +7332,16 @@ ModuleSummaryIndexBitcodeReader::makeCallList(ArrayRef<uint64_t> Record,
                                               bool IsOldProfileFormat,
                                               bool HasProfile, bool HasRelBF) {
   std::vector<FunctionSummary::EdgeTy> Ret;
-  Ret.reserve(Record.size());
+  if (IsOldProfileFormat) {
+    if (HasProfile)
+      Ret.reserve(Record.size() / 3);
+    else
+      Ret.reserve(Record.size() / 2);
+  } else if (HasProfile || HasRelBF) {
+    Ret.reserve(Record.size() / 2);
+  } else
+    Ret.reserve(Record.size());
+
   for (unsigned I = 0, E = Record.size(); I != E; ++I) {
     CalleeInfo::HotnessType Hotness = CalleeInfo::HotnessType::Unknown;
     bool HasTailCall = false;



More information about the llvm-commits mailing list