[llvm] [NVPTX] Avoid repeated map lookups (NFC) (PR #127169)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 13 22:10:13 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-nvptx
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
Note that cacheAnnotationFromMD modifies AC.Cache.
---
Full diff: https://github.com/llvm/llvm-project/pull/127169.diff
1 Files Affected:
- (modified) llvm/lib/Target/NVPTX/NVPTXUtilities.cpp (+14-8)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/127169
More information about the llvm-commits
mailing list