Skip to content
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

[TableGen] Avoid repeated hash lookups (NFC) #111089

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@kazutakahirata kazutakahirata requested a review from nikic October 4, 2024 02:58
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang/utils/TableGen/MveEmitter.cpp (+16-12)
diff --git a/clang/utils/TableGen/MveEmitter.cpp b/clang/utils/TableGen/MveEmitter.cpp
index 57e6353e60a141..915e914d6b9287 100644
--- a/clang/utils/TableGen/MveEmitter.cpp
+++ b/clang/utils/TableGen/MveEmitter.cpp
@@ -994,9 +994,10 @@ class EmitterBase {
   const VectorType *getVectorType(const ScalarType *ST, unsigned Lanes) {
     std::tuple<ScalarTypeKind, unsigned, unsigned> key(ST->kind(),
                                                        ST->sizeInBits(), Lanes);
-    if (VectorTypes.find(key) == VectorTypes.end())
-      VectorTypes[key] = std::make_unique<VectorType>(ST, Lanes);
-    return VectorTypes[key].get();
+    auto [It, Inserted] = VectorTypes.try_emplace(key);
+    if (Inserted)
+      It->second = std::make_unique<VectorType>(ST, Lanes);
+    return It->second.get();
   }
   const VectorType *getVectorType(const ScalarType *ST) {
     return getVectorType(ST, 128 / ST->sizeInBits());
@@ -1004,22 +1005,25 @@ class EmitterBase {
   const MultiVectorType *getMultiVectorType(unsigned Registers,
                                             const VectorType *VT) {
     std::pair<std::string, unsigned> key(VT->cNameBase(), Registers);
-    if (MultiVectorTypes.find(key) == MultiVectorTypes.end())
-      MultiVectorTypes[key] = std::make_unique<MultiVectorType>(Registers, VT);
-    return MultiVectorTypes[key].get();
+    auto [It, Inserted] = MultiVectorTypes.try_emplace(key);
+    if (Inserted)
+      It->second = std::make_unique<MultiVectorType>(Registers, VT);
+    return It->second.get();
   }
   const PredicateType *getPredicateType(unsigned Lanes) {
     unsigned key = Lanes;
-    if (PredicateTypes.find(key) == PredicateTypes.end())
-      PredicateTypes[key] = std::make_unique<PredicateType>(Lanes);
-    return PredicateTypes[key].get();
+    auto [It, Inserted] = PredicateTypes.try_emplace(key);
+    if (Inserted)
+      It->second = std::make_unique<PredicateType>(Lanes);
+    return It->second.get();
   }
   const PointerType *getPointerType(const Type *T, bool Const) {
     PointerType PT(T, Const);
     std::string key = PT.cName();
-    if (PointerTypes.find(key) == PointerTypes.end())
-      PointerTypes[key] = std::make_unique<PointerType>(PT);
-    return PointerTypes[key].get();
+    auto [It, Inserted] = PointerTypes.try_emplace(key);
+    if (Inserted)
+      It->second = std::make_unique<PointerType>(PT);
+    return It->second.get();
   }
 
   // Methods to construct a type from various pieces of Tablegen. These are

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.

LGTM

@kazutakahirata kazutakahirata merged commit 6a8fcb0 into llvm:main Oct 4, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_MveEmitter branch October 4, 2024 14:37
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