[llvm] [TableGen] Avoid repeated hash lookups (NFC) (PR #123562)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 19 23:56:31 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/123562
None
>From 3faab3a11354b67f27a2ec7ff1b4fdd36803d1c8 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 19 Jan 2025 12:09:09 -0800
Subject: [PATCH] [TableGen] Avoid repeated hash lookups (NFC)
---
llvm/utils/TableGen/Common/CodeGenSchedule.cpp | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index 7ae18d3ccc7bc5..8eaba05e65ce92 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -311,15 +311,13 @@ static void processSTIPredicate(STIPredicateFunction &Fn,
ConstRecVec Classes = Def->getValueAsListOfDefs("Classes");
for (const Record *EC : Classes) {
const Record *Pred = EC->getValueAsDef("Predicate");
- if (!Predicate2Index.contains(Pred))
- Predicate2Index[Pred] = NumUniquePredicates++;
+ if (Predicate2Index.try_emplace(Pred, NumUniquePredicates).second)
+ ++NumUniquePredicates;
ConstRecVec Opcodes = EC->getValueAsListOfDefs("Opcodes");
for (const Record *Opcode : Opcodes) {
- if (!Opcode2Index.contains(Opcode)) {
- Opcode2Index[Opcode] = OpcodeMappings.size();
+ if (Opcode2Index.try_emplace(Opcode, OpcodeMappings.size()).second)
OpcodeMappings.emplace_back(Opcode, OpcodeInfo());
- }
}
}
}
@@ -452,11 +450,9 @@ void CodeGenSchedModels::checkMCInstPredicates() const {
for (const Record *TIIPred :
Records.getAllDerivedDefinitions("TIIPredicate")) {
StringRef Name = TIIPred->getValueAsString("FunctionName");
- StringMap<const Record *>::const_iterator It = TIIPredicates.find(Name);
- if (It == TIIPredicates.end()) {
- TIIPredicates[Name] = TIIPred;
+ auto [It, Inserted] = TIIPredicates.try_emplace(Name, TIIPred);
+ if (Inserted)
continue;
- }
PrintError(TIIPred->getLoc(),
"TIIPredicate " + Name + " is multiply defined.");
More information about the llvm-commits
mailing list