[llvm] [SPIRV] Avoid repeated hash lookups (NFC) (PR #128398)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 22 20:17:46 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/128398.diff
1 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h (+4-6)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
index c7f846b8e9bcc..2b3599259a739 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
@@ -197,12 +197,10 @@ struct ModuleAnalysisInfo {
// Convert MBB's number to corresponding ID register.
Register getOrCreateMBBRegister(const MachineBasicBlock &MBB) {
auto Key = std::make_pair(MBB.getParent(), MBB.getNumber());
- auto It = BBNumToRegMap.find(Key);
- if (It != BBNumToRegMap.end())
- return It->second;
- Register NewReg = Register::index2VirtReg(getNextID());
- BBNumToRegMap[Key] = NewReg;
- return NewReg;
+ auto [It, Inserted] = BBNumToRegMap.try_emplace(Key);
+ if (Inserted)
+ It->second = Register::index2VirtReg(getNextID());
+ return It->second;
}
};
} // namespace SPIRV
``````````
</details>
https://github.com/llvm/llvm-project/pull/128398
More information about the llvm-commits
mailing list