Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

@kazutakahirata kazutakahirata commented Jan 26, 2025

This patch avoids repeated map lookups and constructions of temporary
std::string instances by switching to DenseSet.

This patch avoids repeated map lookups and constructions of temporary
std::string instances by switching to StringMap.
@kazutakahirata kazutakahirata requested a review from nikic January 26, 2025 05:57
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 26, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

This patch avoids repeated map lookups and constructions of temporary
std::string instances by switching to StringMap.


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

1 Files Affected:

  • (modified) clang/utils/TableGen/MveEmitter.cpp (+3-3)
diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index 8ebd0bb800feff..7f298d1cbd4376 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -60,6 +60,7 @@
 
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1955,18 +1956,17 @@ void MveEmitter::EmitBuiltinDef(raw_ostream &OS) {
        << ", \"\", \"n\")\n";
   }
 
-  std::set<std::string> ShortNamesSeen;
+  StringSet<> ShortNamesSeen;
 
   for (const auto &kv : ACLEIntrinsics) {
     const ACLEIntrinsic &Int = *kv.second;
     if (Int.polymorphic()) {
       StringRef Name = Int.shortName();
-      if (ShortNamesSeen.find(std::string(Name)) == ShortNamesSeen.end()) {
+      if (ShortNamesSeen.insert(Name).second) {
         OS << "BUILTIN(__builtin_arm_mve_" << Name << ", \"vi.\", \"nt";
         if (Int.nonEvaluating())
           OS << "u"; // indicate that this builtin doesn't evaluate its args
         OS << "\")\n";
-        ShortNamesSeen.insert(std::string(Name));
       }
     }
   }

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this use DenseSet? It looks like the names here live for the lifetime of the set.

@kazutakahirata
Copy link
Contributor Author

Can't this use DenseSet? It looks like the names here live for the lifetime of the set.

Good idea! Revised.

@kazutakahirata kazutakahirata merged commit ccc066e into llvm:main Jan 26, 2025
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_heterogenous_clang_TableGen branch January 26, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants