Skip to content

[ctx_prof] Simplify ingestContext (NFC) #109902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

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

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].
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Sep 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 25, 2024

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

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

@kazutakahirata kazutakahirata merged commit 915fe84 into llvm:main Sep 25, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_ctxprof_try_emplace branch September 25, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants