Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[ProfileData] Use DenseMap::try_emplace (NFC) #140394

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

Conversation

kazutakahirata
Copy link
Contributor

We can simplify the code with structured binding and try_emplace.
Note that try_emplace default-constructs the value if omitted.

FWIW, structured binding, a C++17 feature, wasn't available in our
codebase at the time the code was written.

We can simplify the code with structured binding and try_emplace.
Note that try_emplace default-constructs the value if omitted.

FWIW, structured binding, a C++17 feature, wasn't available in our
codebase at the time the code was written.
@kazutakahirata kazutakahirata requested review from arsenm and shiltian May 17, 2025 18:46
@llvmbot llvmbot added the PGO Profile Guided Optimizations label May 17, 2025
@llvmbot
Copy link
Member

llvmbot commented May 17, 2025

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

We can simplify the code with structured binding and try_emplace.
Note that try_emplace default-constructs the value if omitted.

FWIW, structured binding, a C++17 feature, wasn't available in our
codebase at the time the code was written.


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

1 Files Affected:

  • (modified) llvm/lib/ProfileData/InstrProfWriter.cpp (+2-8)
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 9dc1a0d0b4678..39451c3d64870 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -178,10 +178,7 @@ void InstrProfWriter::overlapRecord(NamedInstrProfRecord &&Other,
     return;
   }
   auto &ProfileDataMap = It->second;
-  bool NewFunc;
-  ProfilingData::iterator Where;
-  std::tie(Where, NewFunc) =
-      ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
+  auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
   if (NewFunc) {
     Overlap.addOneMismatch(FuncLevelOverlap.Test);
     return;
@@ -200,10 +197,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
                                 function_ref<void(Error)> Warn) {
   auto &ProfileDataMap = FunctionData[Name];
 
-  bool NewFunc;
-  ProfilingData::iterator Where;
-  std::tie(Where, NewFunc) =
-      ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
+  auto [Where, NewFunc] = ProfileDataMap.try_emplace(Hash);
   InstrProfRecord &Dest = Where->second;
 
   auto MapWarn = [&](instrprof_error E) {

@kazutakahirata kazutakahirata merged commit 2e2a792 into llvm:main May 17, 2025
13 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_DenseMap_try_emplace_llvm_ProfWriter branch May 17, 2025 20: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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.