[llvm] [CodeGen] Avoid repeated hash lookups (NFC) (PR #130388)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 7 19:54:00 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-regalloc
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/130388.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/RegisterBankInfo.cpp (+9-9)
``````````diff
diff --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp b/llvm/lib/CodeGen/RegisterBankInfo.cpp
index a0061ece8add6..eaef13969a7a1 100644
--- a/llvm/lib/CodeGen/RegisterBankInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp
@@ -282,13 +282,13 @@ RegisterBankInfo::getPartialMapping(unsigned StartIdx, unsigned Length,
++NumPartialMappingsAccessed;
hash_code Hash = hashPartialMapping(StartIdx, Length, &RegBank);
- const auto &It = MapOfPartialMappings.find(Hash);
- if (It != MapOfPartialMappings.end())
+ auto [It, Inserted] = MapOfPartialMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumPartialMappingsCreated;
- auto &PartMapping = MapOfPartialMappings[Hash];
+ auto &PartMapping = It->second;
PartMapping = std::make_unique<PartialMapping>(StartIdx, Length, RegBank);
return *PartMapping;
}
@@ -316,13 +316,13 @@ RegisterBankInfo::getValueMapping(const PartialMapping *BreakDown,
++NumValueMappingsAccessed;
hash_code Hash = hashValueMapping(BreakDown, NumBreakDowns);
- const auto &It = MapOfValueMappings.find(Hash);
- if (It != MapOfValueMappings.end())
+ auto [It, Inserted] = MapOfValueMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumValueMappingsCreated;
- auto &ValMapping = MapOfValueMappings[Hash];
+ auto &ValMapping = It->second;
ValMapping = std::make_unique<ValueMapping>(BreakDown, NumBreakDowns);
return *ValMapping;
}
@@ -390,13 +390,13 @@ RegisterBankInfo::getInstructionMappingImpl(
hash_code Hash =
hashInstructionMapping(ID, Cost, OperandsMapping, NumOperands);
- const auto &It = MapOfInstructionMappings.find(Hash);
- if (It != MapOfInstructionMappings.end())
+ auto [It, Inserted] = MapOfInstructionMappings.try_emplace(Hash);
+ if (!Inserted)
return *It->second;
++NumInstructionMappingsCreated;
- auto &InstrMapping = MapOfInstructionMappings[Hash];
+ auto &InstrMapping = It->second;
InstrMapping = std::make_unique<InstructionMapping>(
ID, Cost, OperandsMapping, NumOperands);
return *InstrMapping;
``````````
</details>
https://github.com/llvm/llvm-project/pull/130388
More information about the llvm-commits
mailing list