Skip to content

[TableGen] Use heterogenous lookups with std::map (NFC) #115633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
@kazutakahirata kazutakahirata requested a review from nikic November 10, 2024 06:15
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Nov 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 10, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


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

1 Files Affected:

  • (modified) clang/utils/TableGen/NeonEmitter.cpp (+3-3)
diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index c6d82646b40de2..7081e5c9ae93e8 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -578,7 +578,7 @@ class Intrinsic {
 class NeonEmitter {
   const RecordKeeper &Records;
   DenseMap<const Record *, ClassKind> ClassMap;
-  std::map<std::string, std::deque<Intrinsic>> IntrinsicMap;
+  std::map<std::string, std::deque<Intrinsic>, std::less<>> IntrinsicMap;
   unsigned UniqueNumber;
 
   void createIntrinsic(const Record *R, SmallVectorImpl<Intrinsic *> &Out);
@@ -1937,9 +1937,9 @@ void Intrinsic::indexBody() {
 Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types,
                                      std::optional<std::string> MangledName) {
   // First, look up the name in the intrinsic map.
-  assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
+  assert_with_loc(IntrinsicMap.find(Name) != IntrinsicMap.end(),
                   ("Intrinsic '" + Name + "' not found!").str());
-  auto &V = IntrinsicMap.find(Name.str())->second;
+  auto &V = IntrinsicMap.find(Name)->second;
   std::vector<Intrinsic *> GoodVec;
 
   // Create a string to print if we end up failing.

@kazutakahirata kazutakahirata merged commit a44ee8e into llvm:main Nov 10, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_heterogenous_clang_TableGen branch November 10, 2024 15:24
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
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