[llvm] [TableGen] Avoid repeated hash lookups (NFC) (PR #122586)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 01:09:33 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-tablegen
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/122586.diff
1 Files Affected:
- (modified) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+5-7)
``````````diff
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));
``````````
</details>
https://github.com/llvm/llvm-project/pull/122586
More information about the llvm-commits
mailing list