[llvm] [ThinLTO] Use StringRef instead of std::string (PR #97963)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 7 10:43:59 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: None (luxufan)

<details>
<summary>Changes</summary>

Use StringRef instead of std::string as the key of TypeIdCompatibleVtableMap.

---
Full diff: https://github.com/llvm/llvm-project/pull/97963.diff


3 Files Affected:

- (modified) llvm/include/llvm/IR/ModuleSummaryIndex.h (+2-2) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+1-1) 
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+1-1) 


``````````diff
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());

``````````

</details>


https://github.com/llvm/llvm-project/pull/97963


More information about the llvm-commits mailing list