aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2025-02-01 08:14:39 -0800
committerGitHub <noreply@github.com>2025-02-01 08:14:39 -0800
commit8266eedfdccddfc8901679ee55e358793e29bba5 (patch)
tree5e7601c7e78eb00bda51c153a7c7cc4e7ed8cb7f /llvm
parente11e65f08b00a96916ce5ec21bf31d061158829d (diff)
downloadllvm-8266eedfdccddfc8901679ee55e358793e29bba5.zip
llvm-8266eedfdccddfc8901679ee55e358793e29bba5.tar.gz
llvm-8266eedfdccddfc8901679ee55e358793e29bba5.tar.bz2
[SandboxIR] Avoid repeated hash lookups (NFC) (#125337)
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/SandboxIR/Region.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/llvm/lib/SandboxIR/Region.cpp b/llvm/lib/SandboxIR/Region.cpp
index 8c84d0c..dbb000e 100644
--- a/llvm/lib/SandboxIR/Region.cpp
+++ b/llvm/lib/SandboxIR/Region.cpp
@@ -94,16 +94,12 @@ Region::createRegionsFromMD(Function &F, TargetTransformInfo &TTI) {
for (BasicBlock &BB : F) {
for (Instruction &Inst : BB) {
if (auto *MDN = cast<llvm::Instruction>(Inst.Val)->getMetadata(MDKind)) {
- Region *R = nullptr;
- auto It = MDNToRegion.find(MDN);
- if (It == MDNToRegion.end()) {
+ auto [It, Inserted] = MDNToRegion.try_emplace(MDN);
+ if (Inserted) {
Regions.push_back(std::make_unique<Region>(Ctx, TTI));
- R = Regions.back().get();
- MDNToRegion[MDN] = R;
- } else {
- R = It->second;
+ It->second = Regions.back().get();
}
- R->add(&Inst);
+ It->second->add(&Inst);
}
}
}