Skip to content

[AMDGPU] Avoid repeated hash lookups (NFC) #130706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Mar 11, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/130706.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp (+6-7)
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 {

@kazutakahirata kazutakahirata merged commit 21f1ef3 into llvm:main Mar 11, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_AMDGPU branch March 11, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants