From 3faab3a11354b67f27a2ec7ff1b4fdd36803d1c8 Mon Sep 17 00:00:00 2001 From: Kazu Hirata 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 7ae18d3ccc7bc..8eaba05e65ce9 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_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.");