Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

Note that the following are all equivalent to each other:

Map.insert({Key, Value()}).first->second
Map.try_emplace(Key).first->second
Map[Key]

Note that the following are all equivalent to each other:

  Map.insert({Key, Value()}).first->second
  Map.try_emplace(Key).first->second
  Map[Key]
@llvmbot llvmbot added the PGO Profile Guided Optimizations label Oct 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 7, 2024

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

Note that the following are all equivalent to each other:

Map.insert({Key, Value()}).first->second
Map.try_emplace(Key).first->second
Map[Key]


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

1 Files Affected:

  • (modified) llvm/lib/ProfileData/MemProfReader.cpp (+2-5)
diff --git a/llvm/lib/ProfileData/MemProfReader.cpp b/llvm/lib/ProfileData/MemProfReader.cpp
index 58622e5ed254ea..e3c85e179ac43b 100644
--- a/llvm/lib/ProfileData/MemProfReader.cpp
+++ b/llvm/lib/ProfileData/MemProfReader.cpp
@@ -529,9 +529,7 @@ Error RawMemProfReader::mapRawProfileToRecords() {
     // first non-inline frame.
     for (size_t I = 0; /*Break out using the condition below*/; I++) {
       const Frame &F = idToFrame(Callstack[I]);
-      auto Result =
-          FunctionProfileData.insert({F.Function, IndexedMemProfRecord()});
-      IndexedMemProfRecord &Record = Result.first->second;
+      IndexedMemProfRecord &Record = FunctionProfileData[F.Function];
       Record.AllocSites.emplace_back(Callstack, CSId, MIB);
 
       if (!F.IsInlineFrame)
@@ -543,8 +541,7 @@ Error RawMemProfReader::mapRawProfileToRecords() {
   for (const auto &[Id, Locs] : PerFunctionCallSites) {
     // Some functions may have only callsite data and no allocation data. Here
     // we insert a new entry for callsite data if we need to.
-    auto Result = FunctionProfileData.insert({Id, IndexedMemProfRecord()});
-    IndexedMemProfRecord &Record = Result.first->second;
+    IndexedMemProfRecord &Record = FunctionProfileData[Id];
     for (LocationPtr Loc : Locs) {
       CallStackId CSId = hashCallStack(*Loc);
       CSIdToCallStack.insert({CSId, *Loc});

@kazutakahirata kazutakahirata merged commit 02b9c97 into llvm:main Oct 7, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_operator_sq_br_MemProf branch October 7, 2024 16:00
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