[PATCH] D156580: [FunctionImport] Reduce string duplication (NFC)

Teresa Johnson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 28 16:13:55 PDT 2023


tejohnson created this revision.
tejohnson added a reviewer: mtrofin.
Herald added subscribers: hoy, ormris, steven_wu, hiraditya.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added projects: clang, LLVM.
Herald added a subscriber: cfe-commits.

The import/export maps, and the ModuleToDefinedGVSummaries map, are all
indexed by module paths, which are StringRef obtained from the module
summary index, which already has a data structure than owns these
strings (the ModulePathStringTable). Because these other maps are also
StringMap, which makes a copy of the string key, we were keeping
multiple extra copies of the module paths, leading to memory overhead.

Change these to DenseMap keyed by StringRef, and document that the
strings are owned by the index.

The only exception is the llvm-link tool which synthesizes an import list
from command line options, and I have added a string cache to maintain
ownership there.

I measured around 5% memory reduction in the thin link of a large
binary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156580

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/LTO/LTO.h
  llvm/include/llvm/Transforms/IPO/FunctionImport.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/FunctionImport.cpp
  llvm/tools/llvm-link/llvm-link.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156580.545303.patch
Type: text/x-patch
Size: 25865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230728/8540cc23/attachment-0001.bin>


More information about the cfe-commits mailing list