Skip to content

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

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Dec 20, 2024

@llvm/pr-subscribers-tablegen

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+1-2)
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 1a393beaa14f96..7a82581f2240ce 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -3508,9 +3508,8 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
         Val->getDef()->isSubClassOf("PointerLikeRegClass")) {
       if (Dest->getName().empty())
         I.error("set destination must have a name!");
-      if (InstResults.count(Dest->getName()))
+      if (!InstResults.try_emplace(Dest->getName(), Dest).second)
         I.error("cannot set '" + Dest->getName() + "' multiple times");
-      InstResults[Dest->getName()] = Dest;
     } else if (Val->getDef()->isSubClassOf("Register")) {
       InstImpResults.push_back(Val->getDef());
     } else {

@mshockwave
Copy link
Member

Your patch nerd-sniped me because with your change, technically InstResults will store a different value -- the original destination register rather than the one that comes after -- upon running into collision key, since I.error(...) won't bail out from the execution. However, I think even the flow won't stop right away with this ill-formed tree pattern instance, it will eventually top at the type inference stage that follows.

@kazutakahirata
Copy link
Contributor Author

Your patch nerd-sniped me because with your change, technically InstResults will store a different value -- the original destination register rather than the one that comes after -- upon running into collision key, since I.error(...) won't bail out from the execution. However, I think even the flow won't stop right away with this ill-formed tree pattern instance, it will eventually top at the type inference stage that follows.

Good point! Let me use insert_or_assign instead. I don't want to introduce subtlety here.

@kazutakahirata
Copy link
Contributor Author

@mshockwave I've updated the patch. Please take a look. Thanks!

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

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

Much better, thanks

@kazutakahirata kazutakahirata merged commit 0575815 into llvm:main Dec 20, 2024
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_tablegen_try_emplace branch December 20, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants