[llvm] [SPIRV] Avoid repeated hash lookups (NFC) (PR #128398)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 22 20:17:16 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/128398
None
>From 9bf27456e2dd44a94adb58806d5a52811924126a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 22 Feb 2025 02:30:04 -0800
Subject: [PATCH] [SPIRV] Avoid repeated hash lookups (NFC)
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
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
More information about the llvm-commits
mailing list