[llvm] [NVPTX] Avoid repeated map lookups (NFC) (PR #127169)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 22:09:40 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/127169
Note that cacheAnnotationFromMD modifies AC.Cache.
>From c7600fcbef02c31cd1421d2af183cc0e6a001579 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 13 Feb 2025 09:43:50 -0800
Subject: [PATCH] [NVPTX] Avoid repeated map lookups (NFC)
Note that cacheAnnotationFromMD modifies AC.Cache.
---
llvm/lib/Target/NVPTX/NVPTXUtilities.cpp | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
index 430502d85dfb4..f34d18160b6e0 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
@@ -128,13 +128,16 @@ static std::optional<unsigned> findOneNVVMAnnotation(const GlobalValue *gv,
auto &AC = getAnnotationCache();
std::lock_guard<sys::Mutex> Guard(AC.Lock);
const Module *m = gv->getParent();
- if (AC.Cache.find(m) == AC.Cache.end())
+ auto ACIt = AC.Cache.find(m);
+ if (ACIt == AC.Cache.end())
cacheAnnotationFromMD(m, gv);
- else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
+ else if (ACIt->second.find(gv) == ACIt->second.end())
cacheAnnotationFromMD(m, gv);
- if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
+ auto &KVP = AC.Cache[m][gv];
+ auto It = KVP.find(prop);
+ if (It == KVP.end())
return std::nullopt;
- return AC.Cache[m][gv][prop][0];
+ return It->second[0];
}
static bool findAllNVVMAnnotation(const GlobalValue *gv,
@@ -143,13 +146,16 @@ static bool findAllNVVMAnnotation(const GlobalValue *gv,
auto &AC = getAnnotationCache();
std::lock_guard<sys::Mutex> Guard(AC.Lock);
const Module *m = gv->getParent();
- if (AC.Cache.find(m) == AC.Cache.end())
+ auto ACIt = AC.Cache.find(m);
+ if (ACIt == AC.Cache.end())
cacheAnnotationFromMD(m, gv);
- else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
+ else if (ACIt->second.find(gv) == ACIt->second.end())
cacheAnnotationFromMD(m, gv);
- if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
+ auto &KVP = AC.Cache[m][gv];
+ auto It = KVP.find(prop);
+ if (It == KVP.end())
return false;
- retval = AC.Cache[m][gv][prop];
+ retval = It->second;
return true;
}
More information about the llvm-commits
mailing list