[llvm] [TableGen] Avoid repeated hash lookups (NFC) (PR #123161)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 20:51:51 PST 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/123161

None

>From ccd2af4a50d39edfad3f10207d737bc75c1be16a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 15 Jan 2025 09:14:39 -0800
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)

---
 .../TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp    | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index a81f2b53f2846e..d56623ed60b36d 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -875,10 +875,8 @@ unsigned RuleMatcher::getInsnVarID(InstructionMatcher &InsnMatcher) const {
 }
 
 void RuleMatcher::defineOperand(StringRef SymbolicName, OperandMatcher &OM) {
-  if (!DefinedOperands.contains(SymbolicName)) {
-    DefinedOperands[SymbolicName] = &OM;
+  if (DefinedOperands.try_emplace(SymbolicName, &OM).second)
     return;
-  }
 
   // If the operand is already defined, then we must ensure both references in
   // the matcher have the exact same node.
@@ -889,8 +887,7 @@ void RuleMatcher::defineOperand(StringRef SymbolicName, OperandMatcher &OM) {
 }
 
 void RuleMatcher::definePhysRegOperand(const Record *Reg, OperandMatcher &OM) {
-  if (!PhysRegOperands.contains(Reg))
-    PhysRegOperands[Reg] = &OM;
+  PhysRegOperands.try_emplace(Reg, &OM);
 }
 
 InstructionMatcher &



More information about the llvm-commits mailing list