[llvm] [ThinLTO]Use UniqueStringSaver to de-duplicate strings (PR #106176)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 21:22:54 PDT 2024
https://github.com/minglotus-6 created https://github.com/llvm/llvm-project/pull/106176
None
>From bf8ce0f66488363275478db95c2c493689ecfd0c Mon Sep 17 00:00:00 2001
From: mingmingl <mingmingl at google.com>
Date: Mon, 26 Aug 2024 21:21:46 -0700
Subject: [PATCH] [ThinLTO]Use UniqueStringSaver to save strings
---
llvm/include/llvm/LTO/LTO.h | 7 +++++++
llvm/lib/LTO/LTO.cpp | 5 +++--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index 30eda34cd7ba54..4ace6e6ee00380 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -21,8 +21,10 @@
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/LTO/Config.h"
#include "llvm/Object/IRSymtab.h"
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/Caching.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/thread.h"
#include "llvm/Transforms/IPO/FunctionAttrs.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
@@ -36,6 +38,7 @@ class MemoryBufferRef;
class Module;
class raw_pwrite_stream;
class ToolOutputFile;
+class UniqueStringSaver;
/// Resolve linkage for prevailing symbols in the \p Index. Linkage changes
/// recorded in the index and the ThinLTO backends must apply the changes to
@@ -405,6 +408,10 @@ class LTO {
};
};
+ std::unique_ptr<llvm::BumpPtrAllocator> Alloc =
+ std::make_unique<BumpPtrAllocator>();
+ llvm::UniqueStringSaver UniqueSymbolSaver{*Alloc};
+
// Global mapping from mangled symbol names to resolutions.
// Make this an optional to guard against accessing after it has been reset
// (to reduce memory after we're done with it).
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index bb3c9f7acdb8e5..ffef5c06a7e17f 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -632,7 +632,7 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
assert(!GlobalRes.Prevailing &&
"Multiple prevailing defs are not allowed");
GlobalRes.Prevailing = true;
- GlobalRes.IRName = std::string(Sym.getIRName());
+ GlobalRes.IRName = UniqueSymbolSaver.save(Sym.getIRName());
} else if (!GlobalRes.Prevailing && GlobalRes.IRName.empty()) {
// Sometimes it can be two copies of symbol in a module and prevailing
// symbol can have no IR name. That might happen if symbol is defined in
@@ -640,7 +640,7 @@ void LTO::addModuleToGlobalRes(ArrayRef<InputFile::Symbol> Syms,
// the same symbol we want to use IR name of the prevailing symbol.
// Otherwise, if we haven't seen a prevailing symbol, set the name so that
// we can later use it to check if there is any prevailing copy in IR.
- GlobalRes.IRName = std::string(Sym.getIRName());
+ GlobalRes.IRName = UniqueSymbolSaver.save(Sym.getIRName());
}
// In rare occasion, the symbol used to initialize GlobalRes has a different
@@ -1797,6 +1797,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache Cache,
// cross module importing, which adds to peak memory via the computed import
// and export lists.
GlobalResolutions.reset();
+ Alloc.reset();
if (Conf.OptLevel > 0)
ComputeCrossModuleImport(ThinLTO.CombinedIndex, ModuleToDefinedGVSummaries,
More information about the llvm-commits
mailing list