Skip to content

Commit 818d6e5

Browse files
[TableGen] Avoid repeated hash lookups (NFC) (#123562)
1 parent efae9f3 commit 818d6e5

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

llvm/utils/TableGen/Common/CodeGenSchedule.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,15 +311,13 @@ static void processSTIPredicate(STIPredicateFunction &Fn,
311311
ConstRecVec Classes = Def->getValueAsListOfDefs("Classes");
312312
for (const Record *EC : Classes) {
313313
const Record *Pred = EC->getValueAsDef("Predicate");
314-
if (!Predicate2Index.contains(Pred))
315-
Predicate2Index[Pred] = NumUniquePredicates++;
314+
if (Predicate2Index.try_emplace(Pred, NumUniquePredicates).second)
315+
++NumUniquePredicates;
316316

317317
ConstRecVec Opcodes = EC->getValueAsListOfDefs("Opcodes");
318318
for (const Record *Opcode : Opcodes) {
319-
if (!Opcode2Index.contains(Opcode)) {
320-
Opcode2Index[Opcode] = OpcodeMappings.size();
319+
if (Opcode2Index.try_emplace(Opcode, OpcodeMappings.size()).second)
321320
OpcodeMappings.emplace_back(Opcode, OpcodeInfo());
322-
}
323321
}
324322
}
325323
}
@@ -452,11 +450,9 @@ void CodeGenSchedModels::checkMCInstPredicates() const {
452450
for (const Record *TIIPred :
453451
Records.getAllDerivedDefinitions("TIIPredicate")) {
454452
StringRef Name = TIIPred->getValueAsString("FunctionName");
455-
StringMap<const Record *>::const_iterator It = TIIPredicates.find(Name);
456-
if (It == TIIPredicates.end()) {
457-
TIIPredicates[Name] = TIIPred;
453+
auto [It, Inserted] = TIIPredicates.try_emplace(Name, TIIPred);
454+
if (Inserted)
458455
continue;
459-
}
460456

461457
PrintError(TIIPred->getLoc(),
462458
"TIIPredicate " + Name + " is multiply defined.");

0 commit comments

Comments
 (0)