[llvm] 07ff786 - [TableGen] Avoid repeated hash lookups (NFC) (#122586)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 13:15:33 PST 2025
Author: Kazu Hirata
Date: 2025-01-11T13:15:30-08:00
New Revision: 07ff786e39e2190449998d3af1000454dee501be
URL: https://github.com/llvm/llvm-project/commit/07ff786e39e2190449998d3af1000454dee501be
DIFF: https://github.com/llvm/llvm-project/commit/07ff786e39e2190449998d3af1000454dee501be.diff
LOG: [TableGen] Avoid repeated hash lookups (NFC) (#122586)
Added:
Modified:
llvm/utils/TableGen/Common/CodeGenSchedule.cpp
Removed:
################################################################################
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