[llvm] [DWARFLinker] Only extract unit DIEs when cloning clang modules (PR #69495)

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 11:31:35 PDT 2023


https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/69495

Reduce memory usage by only extract unit DIEs when cloning clang modules. We don't need the full debug info yet at this stage. This reduces peak memory usage of dsymutil when linking the swift driver by multiple gigabytes.

>From c937031b877f6392c94905f583b27984266a963b Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Wed, 18 Oct 2023 11:29:24 -0700
Subject: [PATCH] [DWARFLinker] Only extract unit DIEs when cloning clang
 modules

Reduce memory usage by only extract unit DIEs when cloning clang
modules. We don't need the full debug info yet at this stage. This
reduces peak memory usage of dsymutil when linking the swift driver by
multiple gigabytes.
---
 llvm/lib/DWARFLinker/DWARFLinker.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/DWARFLinker/DWARFLinker.cpp b/llvm/lib/DWARFLinker/DWARFLinker.cpp
index 5ed4923dc0125a6..2d8360f100c1172 100644
--- a/llvm/lib/DWARFLinker/DWARFLinker.cpp
+++ b/llvm/lib/DWARFLinker/DWARFLinker.cpp
@@ -2682,12 +2682,12 @@ Error DWARFLinker::link() {
       continue;
     }
 
-    // In a first phase, just read in the debug info and load all clang modules.
+    // Clone all the clang modules with requires extracting the DIE units. We
+    // don't need the full debug info until the Analyze phase.
     OptContext.CompileUnits.reserve(
         OptContext.File.Dwarf->getNumCompileUnits());
-
     for (const auto &CU : OptContext.File.Dwarf->compile_units()) {
-      auto CUDie = CU->getUnitDIE(false);
+      auto CUDie = CU->getUnitDIE(/*ExtractUnitDIEOnly=*/true);
       if (Options.Verbose) {
         outs() << "Input compilation unit:";
         DIDumpOptions DumpOpts;
@@ -2728,9 +2728,9 @@ Error DWARFLinker::link() {
       return;
 
     for (const auto &CU : Context.File.Dwarf->compile_units()) {
-      // The !isClangModuleRef condition effectively skips over fully resolved
-      // skeleton units.
-      auto CUDie = CU->getUnitDIE();
+      // Previously we only extracted the unit DIEs. We need the full debug info
+      // now.
+      auto CUDie = CU->getUnitDIE(/*ExtractUnitDIEOnly=*/false);
       std::string PCMFile = getPCMFile(CUDie, Options.ObjectPrefixMap);
 
       if (!CUDie || LLVM_UNLIKELY(Options.Update) ||



More information about the llvm-commits mailing list