[llvm] [ctx_prof] Simplify ingestContext (NFC) (PR #109902)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 21:20:23 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

try_emplace can default-construct the value, so:

  try_emplace(CSId, CallTargetMapTy())
  try_emplace(CSId)

are equivalent to each other.  We can further simplify the function
using the fact that Map.try_emplace(Key).first->second is the same as
Map[Key].


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


1 Files Affected:

- (modified) llvm/include/llvm/ProfileData/PGOCtxProfReader.h (+1-2) 


``````````diff
diff --git a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
index beda07d7b8286c..a00c21ddc7d7a1 100644
--- a/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
+++ b/llvm/include/llvm/ProfileData/PGOCtxProfReader.h
@@ -68,8 +68,7 @@ class PGOCtxProfContext final {
   CallsiteMapTy &callsites() { return Callsites; }
 
   void ingestContext(uint32_t CSId, PGOCtxProfContext &&Other) {
-    auto [Iter, _] = callsites().try_emplace(CSId, CallTargetMapTy());
-    Iter->second.emplace(Other.guid(), std::move(Other));
+    callsites()[CSId].emplace(Other.guid(), std::move(Other));
   }
 
   void ingestAllContexts(uint32_t CSId, CallTargetMapTy &&Other) {

``````````

</details>


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


More information about the llvm-commits mailing list