[llvm] [NVPTX] Avoid repeated hash lookups (NFC) (PR #112117)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 21:12:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-nvptx

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/112117.diff


1 Files Affected:

- (modified) llvm/lib/Target/NVPTX/NVPTXUtilities.cpp (+4-9) 


``````````diff
diff --git a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
index 2d62f34726e88c..44c50827764b08 100644
--- a/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXUtilities.cpp
@@ -87,8 +87,9 @@ static void cacheAnnotationFromMD(const MDNode *MetadataNode,
       // assert: there can only exist one unique key value pair of
       // the form (string key, MDNode node). Operands of such a node
       // shall always be unsigned ints.
-      if (retval.find(Key) == retval.end()) {
-        readIntVecFromMDNode(VecMd, retval[Key]);
+      auto [It, Inserted] = retval.try_emplace(Key);
+      if (Inserted) {
+        readIntVecFromMDNode(VecMd, It->second);
         continue;
       }
     } else {
@@ -122,13 +123,7 @@ static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) {
   if (tmp.empty()) // no annotations for this gv
     return;
 
-  if (AC.Cache.find(m) != AC.Cache.end())
-    AC.Cache[m][gv] = std::move(tmp);
-  else {
-    global_val_annot_t tmp1;
-    tmp1[gv] = std::move(tmp);
-    AC.Cache[m] = std::move(tmp1);
-  }
+  AC.Cache[m][gv] = std::move(tmp);
 }
 
 static std::optional<unsigned> findOneNVVMAnnotation(const GlobalValue *gv,

``````````

</details>


https://github.com/llvm/llvm-project/pull/112117


More information about the llvm-commits mailing list