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

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 21:19:47 PDT 2024


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

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].


>From 1fecce3356a165d6fd239a3e8970aea8d173f83d Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 24 Sep 2024 21:01:58 -0700
Subject: [PATCH] [ctx_prof] Simplify ingestContext (NFC)

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].
---
 llvm/include/llvm/ProfileData/PGOCtxProfReader.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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) {



More information about the llvm-commits mailing list