[llvm] [Bitcode] Use DenseSet instead of std::map (NFC) (PR #105851)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 09:26:06 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/105851

DefOrUseGUIDs is used only for membership checking purposes.  We don't
need std::set's strengths like iterators staying valid or the ability
to traverse in a sorted order.

While I am at it, this patch replaces count with contains for slightly
increased readability.


>From b4b3230af0c4f7d4ff96e6fb2ffc7570d39ea2f7 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 23 Aug 2024 09:13:27 -0700
Subject: [PATCH] [Bitcode] Use DenseSet instead of std::map (NFC)

DefOrUseGUIDs is used only for membership checking purposes.  We don't
need std::set's strengths like iterators staying valid or the ability
to traverse in a sorted order.

While I am at it, this patch replaces count with contains for slightly
increased readability.
---
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 03d0537291dada..20737c0812cf86 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4628,7 +4628,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
     NameVals.clear();
   };
 
-  std::set<GlobalValue::GUID> DefOrUseGUIDs;
+  DenseSet<GlobalValue::GUID> DefOrUseGUIDs;
   forEachSummary([&](GVInfo I, bool IsAliasee) {
     GlobalValueSummary *S = I.second;
     assert(S);
@@ -4777,7 +4777,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
 
   if (!Index.cfiFunctionDefs().empty()) {
     for (auto &S : Index.cfiFunctionDefs()) {
-      if (DefOrUseGUIDs.count(
+      if (DefOrUseGUIDs.contains(
               GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
         NameVals.push_back(StrtabBuilder.add(S));
         NameVals.push_back(S.size());
@@ -4791,7 +4791,7 @@ void IndexBitcodeWriter::writeCombinedGlobalValueSummary() {
 
   if (!Index.cfiFunctionDecls().empty()) {
     for (auto &S : Index.cfiFunctionDecls()) {
-      if (DefOrUseGUIDs.count(
+      if (DefOrUseGUIDs.contains(
               GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
         NameVals.push_back(StrtabBuilder.add(S));
         NameVals.push_back(S.size());



More information about the llvm-commits mailing list