[llvm] [ThinLTO] Use StringRef instead of std::string (PR #97963)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 08:27:14 PDT 2024
https://github.com/luxufan updated https://github.com/llvm/llvm-project/pull/97963
>From 3cb74500ea082f929bc2cc6126bc9f0aca1dc270 Mon Sep 17 00:00:00 2001
From: luxufan <luxufan981014 at gmail.com>
Date: Sat, 6 Jul 2024 23:48:26 +0800
Subject: [PATCH 1/2] [ThinLTO] Use StringRef instead of std::string
Use StringRef instead of std::string as the key of
TypeIdCompatibleVtableMap.
---
llvm/include/llvm/IR/ModuleSummaryIndex.h | 4 ++--
llvm/lib/AsmParser/LLParser.cpp | 2 +-
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index ecafb0e68fa7a..4cceb6b40ef73 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1326,7 +1326,7 @@ class ModuleSummaryIndex {
/// with that type identifier's metadata. Produced by per module summary
/// analysis and consumed by thin link. For more information, see description
/// above where TypeIdCompatibleVtableInfo is defined.
- std::map<std::string, TypeIdCompatibleVtableInfo, std::less<>>
+ std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
TypeIdCompatibleVtableMap;
/// Mapping from original ID to GUID. If original ID can map to multiple
@@ -1826,7 +1826,7 @@ class ModuleSummaryIndex {
/// the ThinLTO backends.
TypeIdCompatibleVtableInfo &
getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId) {
- return TypeIdCompatibleVtableMap[std::string(TypeId)];
+ return TypeIdCompatibleVtableMap[TypeId];
}
/// For the given \p TypeId, this returns the TypeIdCompatibleVtableMap
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 87cd8aac8d035..49880f3518449 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -8818,7 +8818,7 @@ bool LLParser::parseTypeIdCompatibleVtableEntry(unsigned ID) {
return true;
TypeIdCompatibleVtableInfo &TI =
- Index->getOrInsertTypeIdCompatibleVtableSummary(Name);
+ Index->getOrInsertTypeIdCompatibleVtableSummary(Index->saveString(Name));
if (parseToken(lltok::comma, "expected ',' here") ||
parseToken(lltok::kw_summary, "expected 'summary' here") ||
parseToken(lltok::colon, "expected ':' here") ||
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7a228fb6c08b9..59ae46bafce46 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4133,7 +4133,7 @@ static void writeTypeIdSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
static void writeTypeIdCompatibleVtableSummaryRecord(
SmallVector<uint64_t, 64> &NameVals, StringTableBuilder &StrtabBuilder,
- const std::string &Id, const TypeIdCompatibleVtableInfo &Summary,
+ const StringRef Id, const TypeIdCompatibleVtableInfo &Summary,
ValueEnumerator &VE) {
NameVals.push_back(StrtabBuilder.add(Id));
NameVals.push_back(Id.size());
>From c40d0504a892f9b729836961c9b41abbcae01473 Mon Sep 17 00:00:00 2001
From: luxufan <luxufan981014 at gmail.com>
Date: Mon, 8 Jul 2024 23:26:58 +0800
Subject: [PATCH 2/2] Address comments
---
llvm/include/llvm/IR/ModuleSummaryIndex.h | 6 ++++++
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 4cceb6b40ef73..4cf46363d6d4e 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -1326,6 +1326,12 @@ class ModuleSummaryIndex {
/// with that type identifier's metadata. Produced by per module summary
/// analysis and consumed by thin link. For more information, see description
/// above where TypeIdCompatibleVtableInfo is defined.
+ ///
+ /// The owner of StringRef has two situations:
+ /// 1. If the index is loaded from bitcode module, then the owner is the
+ /// string table of the bitcode module.
+ /// 2. If the index is parsed by LLParser, then the owner is the StringSaver
+ /// of the index.
std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
TypeIdCompatibleVtableMap;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 59ae46bafce46..3e04661e6ea5f 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4133,7 +4133,7 @@ static void writeTypeIdSummaryRecord(SmallVector<uint64_t, 64> &NameVals,
static void writeTypeIdCompatibleVtableSummaryRecord(
SmallVector<uint64_t, 64> &NameVals, StringTableBuilder &StrtabBuilder,
- const StringRef Id, const TypeIdCompatibleVtableInfo &Summary,
+ StringRef Id, const TypeIdCompatibleVtableInfo &Summary,
ValueEnumerator &VE) {
NameVals.push_back(StrtabBuilder.add(Id));
NameVals.push_back(Id.size());
More information about the llvm-commits
mailing list