[llvm] 21f1ef3 - [AMDGPU] Avoid repeated hash lookups (NFC) (#130706)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 11 07:33:56 PDT 2025
Author: Kazu Hirata
Date: 2025-03-11T07:33:52-07:00
New Revision: 21f1ef330f22faddef0c820fb4c1fa912bc05323
URL: https://github.com/llvm/llvm-project/commit/21f1ef330f22faddef0c820fb4c1fa912bc05323
DIFF: https://github.com/llvm/llvm-project/commit/21f1ef330f22faddef0c820fb4c1fa912bc05323.diff
LOG: [AMDGPU] Avoid repeated hash lookups (NFC) (#130706)
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp
index 8d3e7829e10e1..75eb440d99c03 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp
@@ -89,13 +89,12 @@ const RegBankLegalizeRules &getRules(const GCNSubtarget &ST,
static SmallDenseMap<unsigned, std::unique_ptr<RegBankLegalizeRules>>
CacheForRuleSet;
std::lock_guard<std::mutex> Lock(GlobalMutex);
- if (!CacheForRuleSet.contains(ST.getGeneration())) {
- auto Rules = std::make_unique<RegBankLegalizeRules>(ST, MRI);
- CacheForRuleSet[ST.getGeneration()] = std::move(Rules);
- } else {
- CacheForRuleSet[ST.getGeneration()]->refreshRefs(ST, MRI);
- }
- return *CacheForRuleSet[ST.getGeneration()];
+ auto [It, Inserted] = CacheForRuleSet.try_emplace(ST.getGeneration());
+ if (Inserted)
+ It->second = std::make_unique<RegBankLegalizeRules>(ST, MRI);
+ else
+ It->second->refreshRefs(ST, MRI);
+ return *It->second;
}
class AMDGPURegBankLegalizeCombiner {
More information about the llvm-commits
mailing list