Skip to content

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

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

No description provided.

@kazutakahirata kazutakahirata requested a review from nikic March 20, 2025 03:41
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang/utils/TableGen/NeonEmitter.cpp (+7-9)
diff --git a/clang/utils/TableGen/NeonEmitter.cpp b/clang/utils/TableGen/NeonEmitter.cpp
index 5669b5e329587..bc142526ac973 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -1809,12 +1809,11 @@ Intrinsic::DagEmitter::emitDagSaveTemp(const DagInit *DI) {
   assert_with_loc(!N.empty(),
                   "save_temp() expects a name as the first argument");
 
-  assert_with_loc(Intr.Variables.find(N) == Intr.Variables.end(),
-                  "Variable already defined!");
-  Intr.Variables[N] = Variable(A.first, N + Intr.VariablePostfix);
+  auto [It, Inserted] =
+      Intr.Variables.try_emplace(N, A.first, N + Intr.VariablePostfix);
+  assert_with_loc(Inserted, "Variable already defined!");
 
-  std::string S =
-      A.first.str() + " " + Intr.Variables[N].getName() + " = " + A.second;
+  std::string S = A.first.str() + " " + It->second.getName() + " = " + A.second;
 
   return std::make_pair(Type::getVoid(), S);
 }
@@ -2246,9 +2245,9 @@ void NeonEmitter::genIntrinsicRangeCheckCode(
     // Sorted by immediate argument index
     ArrayRef<ImmCheck> Checks = Def->getImmChecks();
 
-    const auto it = Emitted.find(Def->getMangledName());
-    if (it != Emitted.end()) {
-      assert(areRangeChecksCompatible(Checks, it->second) &&
+    auto [It, Inserted] = Emitted.try_emplace(Def->getMangledName(), Checks);
+    if (!Inserted) {
+      assert(areRangeChecksCompatible(Checks, It->second) &&
              "Neon intrinsics with incompatible immediate range checks cannot "
              "share a builtin.");
       continue; // Ensure this is emitted only once
@@ -2262,7 +2261,6 @@ void NeonEmitter::genIntrinsicRangeCheckCode(
          << Check.getVecSizeInBits() << ");\n"
          << " break;\n";
     }
-    Emitted[Def->getMangledName()] = Checks;
   }
 
   OS << "#endif\n\n";

@kazutakahirata kazutakahirata merged commit 69b7011 into llvm:main Mar 20, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_clang_TableGen branch March 20, 2025 16:10
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