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

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 18:04:18 PDT 2024


Author: Jan Voung
Date: 2024-06-20T21:04:14-04:00
New Revision: e1e5ed5893c50918dc9b6b56acfe6242f03354dc

URL: https://github.com/llvm/llvm-project/commit/e1e5ed5893c50918dc9b6b56acfe6242f03354dc
DIFF: https://github.com/llvm/llvm-project/commit/e1e5ed5893c50918dc9b6b56acfe6242f03354dc.diff

LOG: Update ModuleSummaryIndexBitcodeReader::makeCallList reserve amount (#95461)

Tighten the reserve() to `Record.size() / 2` instead of `Record.size()`
in the HasProfile/HasRelBF cases. For the uncommon old profile format
cases we leave it as is, but those should be rare and not worth
optimizing.
This reduces peak memory during ThinLTO indexing by ~3% in one example.

Alternatively, we could make the branching for reserve more complex and
try to cover every case.

Added: 
    

Modified: 
    llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 06d99366a8c3e..6bcd0c17400d6 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -7333,7 +7333,13 @@ 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.
+  if (!IsOldProfileFormat && (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