Skip to content

Commit 21f1ef3

Browse files
[AMDGPU] Avoid repeated hash lookups (NFC) (#130706)
1 parent d48a36f commit 21f1ef3

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

llvm/lib/Target/AMDGPU/AMDGPURegBankLegalize.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ const RegBankLegalizeRules &getRules(const GCNSubtarget &ST,
8989
static SmallDenseMap<unsigned, std::unique_ptr<RegBankLegalizeRules>>
9090
CacheForRuleSet;
9191
std::lock_guard<std::mutex> Lock(GlobalMutex);
92-
if (!CacheForRuleSet.contains(ST.getGeneration())) {
93-
auto Rules = std::make_unique<RegBankLegalizeRules>(ST, MRI);
94-
CacheForRuleSet[ST.getGeneration()] = std::move(Rules);
95-
} else {
96-
CacheForRuleSet[ST.getGeneration()]->refreshRefs(ST, MRI);
97-
}
98-
return *CacheForRuleSet[ST.getGeneration()];
92+
auto [It, Inserted] = CacheForRuleSet.try_emplace(ST.getGeneration());
93+
if (Inserted)
94+
It->second = std::make_unique<RegBankLegalizeRules>(ST, MRI);
95+
else
96+
It->second->refreshRefs(ST, MRI);
97+
return *It->second;
9998
}
10099

101100
class AMDGPURegBankLegalizeCombiner {

0 commit comments

Comments
 (0)