[llvm] [BOLT][DWARF][NFC] Change how we re-size CloneUnitCtxMap (PR #75876)

Alexander Yermolovich via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 15:54:44 PST 2023


https://github.com/ayermolo created https://github.com/llvm/llvm-project/pull/75876

We would always allocate maximum amount for vector containing DWARFUnitInfo. In real usecases what ends up hapenning is we allocate a giant vector when processing one CU, or for thin-lto case multiple CUs. This lead to a lot of memory overhead, and 2x BOLT processing slowdown for at least one service built with monolithic DWARF.

For binaries built with LTO with clang all of CUs that have cross references will share an abbrev table and will be processed in one batch. Rest of CUs are processesd in --cu-processing-batch-size size. Which defaults to 1.

For theoretical cases where cross-cu references are present, but they do not share abbrev will increase the size of CloneUnitCtxMap as each CU is being processsed.

>From 721d8a6d5113cf93b125789027b1fcbfe240a2ea Mon Sep 17 00:00:00 2001
From: Alexander Yermolovich <ayermolo at meta.com>
Date: Mon, 18 Dec 2023 14:11:10 -0800
Subject: [PATCH] [BOLT][DWARF][NFC] Change how we re-size CloneUnitCtxMap

We would always allocate maximum amount for vector containing DWARFUnitInfo. In
real usecases what ends up hapenning is we allocate a giant vector when
processing one CU, or for thin-lto case multiple CUs. This lead to a lot of
memory overhead, and 2x BOLT processing slowdown for at least one service built
with monolithic DWARF.

For binaries built with LTO with clang all of CUs that have cross references
will share an abbrev table and will be processed in one batch. Rest of CUs are
processesd in --cu-processing-batch-size size. Which defaults to 1.

For theoretical cases where cross-cu references are present, but they do not
share abbrev will increase the size of CloneUnitCtxMap as each CU is being
processsed.
---
 bolt/lib/Core/DIEBuilder.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/bolt/lib/Core/DIEBuilder.cpp b/bolt/lib/Core/DIEBuilder.cpp
index caa5ecbea521dc..4aa54521076e31 100644
--- a/bolt/lib/Core/DIEBuilder.cpp
+++ b/bolt/lib/Core/DIEBuilder.cpp
@@ -272,7 +272,7 @@ void DIEBuilder::buildCompileUnits(const std::vector<DWARFUnit *> &CUs) {
   // set, even if they themselves don't have src cross cu ref. We could have
   // cases where this is not the case. In which case this container needs to be
   // big enough for all.
-  getState().CloneUnitCtxMap.resize(DwarfContext->getNumCompileUnits());
+  getState().CloneUnitCtxMap.resize(CUs.size());
   getState().Type = ProcessingType::CUs;
   for (DWARFUnit *CU : CUs)
     registerUnit(*CU, false);
@@ -897,6 +897,8 @@ void DIEBuilder::registerUnit(DWARFUnit &DU, bool NeedSort) {
                 });
   }
   getState().UnitIDMap[getHash(DU)] = getState().DUList.size();
+  if (getState().DUList.size() == getState().CloneUnitCtxMap.size())
+    getState().CloneUnitCtxMap.emplace_back();
   getState().DUList.push_back(&DU);
 }
 



More information about the llvm-commits mailing list