[llvm] [TableGen] Avoid repeated hash lookups (NFC) (PR #122586)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 01:09:03 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/122586
None
>From 0559f48aca3300f7724fc9f7f57f87b97672ae3d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Dec 2024 21:51:22 -0800
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)
---
llvm/utils/TableGen/Common/CodeGenSchedule.cpp | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index 06d82daebac0d5..7f4230affca09c 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -258,11 +258,9 @@ void CodeGenSchedModels::checkSTIPredicates() const {
// There cannot be multiple declarations with the same name.
for (const Record *R : Records.getAllDerivedDefinitions("STIPredicateDecl")) {
StringRef Name = R->getValueAsString("Name");
- const auto It = Declarations.find(Name);
- if (It == Declarations.end()) {
- Declarations[Name] = R;
+ const auto [It, Inserted] = Declarations.try_emplace(Name, R);
+ if (Inserted)
continue;
- }
PrintError(R->getLoc(), "STIPredicate " + Name + " multiply declared.");
PrintFatalNote(It->second->getLoc(), "Previous declaration was here.");
@@ -417,9 +415,9 @@ void CodeGenSchedModels::collectSTIPredicates() {
for (const Record *R : Records.getAllDerivedDefinitions("STIPredicate")) {
const Record *Decl = R->getValueAsDef("Declaration");
- const auto It = Decl2Index.find(Decl);
- if (It == Decl2Index.end()) {
- Decl2Index[Decl] = STIPredicates.size();
+ const auto [It, Inserted] =
+ Decl2Index.try_emplace(Decl, STIPredicates.size());
+ if (Inserted) {
STIPredicateFunction Predicate(Decl);
Predicate.addDefinition(R);
STIPredicates.emplace_back(std::move(Predicate));
More information about the llvm-commits
mailing list