[llvm] [llvm-profdata] Optimize memory usage in sample profile merge (PR #202888)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 01:25:29 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/tools/llvm-profdata/llvm-profdata.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp
index dd0262338..81a1cbc09 100644
--- a/llvm/tools/llvm-profdata/llvm-profdata.cpp
+++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp
@@ -14,7 +14,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/StringSaver.h"
 #include "llvm/HTTP/HTTPClient.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/Object/Binary.h"
@@ -41,6 +40,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Regex.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/ThreadPool.h"
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -1595,15 +1595,16 @@ static void handleExtBinaryWriter(sampleprof::SampleProfileWriter &Writer,
 
 /// Make a deep copy of the given function samples, interning all FunctionIds
 /// and context frames into a shared pool using the provided \p Remap function.
-static sampleprof::FunctionSamples
-internFunctionSamples(const sampleprof::FunctionSamples &Samples,
-                      function_ref<sampleprof::FunctionId(sampleprof::FunctionId)> Remap,
-                      std::list<sampleprof::SampleContextFrameVector> &CtxFrameStorage) {
+static sampleprof::FunctionSamples internFunctionSamples(
+    const sampleprof::FunctionSamples &Samples,
+    function_ref<sampleprof::FunctionId(sampleprof::FunctionId)> Remap,
+    std::list<sampleprof::SampleContextFrameVector> &CtxFrameStorage) {
   sampleprof::FunctionSamples Result;
   Result.setFunctionHash(Samples.getFunctionHash());
 
   if (Samples.getContext().hasContext()) {
-    sampleprof::SampleContextFrames OldFrames = Samples.getContext().getContextFrames();
+    sampleprof::SampleContextFrames OldFrames =
+        Samples.getContext().getContextFrames();
     CtxFrameStorage.emplace_back();
     sampleprof::SampleContextFrameVector &NewFrames = CtxFrameStorage.back();
     NewFrames.reserve(OldFrames.size());
@@ -1705,9 +1706,9 @@ static void mergeSampleProfile(const WeightedFileVector &Inputs,
       sampleprof_error Result = sampleprof_error::success;
       FunctionSamples Interned =
           internFunctionSamples(I->second, InternFunctionId, CtxFrameStorage);
-      FunctionSamples Remapped =
-          Remapper ? remapSamples(Interned, *Remapper, Result)
-                   : FunctionSamples();
+      FunctionSamples Remapped = Remapper
+                                     ? remapSamples(Interned, *Remapper, Result)
+                                     : FunctionSamples();
       FunctionSamples &Samples = Remapper ? Remapped : Interned;
       SampleContext FContext = Samples.getContext();
       mergeSampleProfErrors(Result,

``````````

</details>


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


More information about the llvm-commits mailing list