[llvm] [MemProf] Add option to print function GUIDs during matching (PR #170946)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 5 18:27:30 PST 2025
https://github.com/teresajohnson updated https://github.com/llvm/llvm-project/pull/170946
>From 7f0631862325b81f13b2d9de03cf6a8468406a3a Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Fri, 5 Dec 2025 14:36:57 -0800
Subject: [PATCH 1/2] [MemProf] Add option to print function GUIDs during
matching
For debugging, add -memprof-function-guids option that will cause
memprof matching to emit the computed function GUID for every function
definition in the module to stderr. This is helpful because the profile
only contains the function GUID and not the names.
---
llvm/lib/Transforms/Instrumentation/MemProfUse.cpp | 8 ++++++++
.../PGOProfile/memprof-dump-matched-alloc-site.ll | 9 ++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
index b72d41a748857..5592f190a7e55 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
@@ -62,6 +62,11 @@ static cl::opt<bool>
"context in this module's profiles"),
cl::Hidden, cl::init(false));
+static cl::opt<bool>
+ PrintFunctionGuids("memprof-function-guids",
+ cl::desc("Print function GUIDs computed for matching"),
+ cl::Hidden, cl::init(false));
+
static cl::opt<bool>
SalvageStaleProfile("memprof-salvage-stale-profile",
cl::desc("Salvage stale MemProf profile"),
@@ -562,6 +567,9 @@ static void readMemprof(Module &M, Function &F,
// linkage function.
auto FuncName = F.getName();
auto FuncGUID = Function::getGUIDAssumingExternalLinkage(FuncName);
+ if (PrintFunctionGuids)
+ errs() << "MemProf: Function GUID " << FuncGUID << " is " << FuncName
+ << "\n";
std::optional<memprof::MemProfRecord> MemProfRec;
auto Err = MemProfReader->getMemProfRecord(FuncGUID).moveInto(MemProfRec);
if (Err) {
diff --git a/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll b/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
index 2dcaa9d492869..b6afcf6de922e 100644
--- a/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
+++ b/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
@@ -26,7 +26,7 @@
; REQUIRES: x86_64-linux
; RUN: split-file %s %t
; RUN: llvm-profdata merge %t/memprof-dump-matched-alloc-site.yaml -o %t/memprof-dump-matched-alloc-site.memprofdata
-; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -S 2>&1 | FileCheck %s
+; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -memprof-function-guids -S 2>&1 | FileCheck %s
;--- memprof-dump-matched-alloc-site.yaml
---
@@ -77,6 +77,13 @@ HeapProfileRecords:
# Kept empty here because this section is irrelevant for this test.
...
;--- memprof-dump-matched-alloc-site.ll
+
+;; From -memprof-function-guids
+; CHECK: MemProf: Function GUID 4708092051066754107 is _Z2f1v
+; CHECK: MemProf: Function GUID 14255129117669598641 is _Z2f2v
+; CHECK: MemProf: Function GUID 2771528421763978342 is _Z2f3v
+
+;; From -memprof-print-match-info
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 1 frames
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 2 frames
; CHECK: MemProf notcold context with id 5736731103568718490 has total profiled size 3 is matched with 3 frames
>From 76a5ff17d47f011eef5e250f4b741c97100dd8d7 Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Fri, 5 Dec 2025 18:25:53 -0800
Subject: [PATCH 2/2] Change option name to -memprof-print-function-guids
---
llvm/lib/Transforms/Instrumentation/MemProfUse.cpp | 2 +-
.../Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
index 5592f190a7e55..e1cba940218a6 100644
--- a/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemProfUse.cpp
@@ -63,7 +63,7 @@ static cl::opt<bool>
cl::Hidden, cl::init(false));
static cl::opt<bool>
- PrintFunctionGuids("memprof-function-guids",
+ PrintFunctionGuids("memprof-print-function-guids",
cl::desc("Print function GUIDs computed for matching"),
cl::Hidden, cl::init(false));
diff --git a/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll b/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
index b6afcf6de922e..16c2ad3160d1f 100644
--- a/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
+++ b/llvm/test/Transforms/PGOProfile/memprof-dump-matched-alloc-site.ll
@@ -26,7 +26,7 @@
; REQUIRES: x86_64-linux
; RUN: split-file %s %t
; RUN: llvm-profdata merge %t/memprof-dump-matched-alloc-site.yaml -o %t/memprof-dump-matched-alloc-site.memprofdata
-; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -memprof-function-guids -S 2>&1 | FileCheck %s
+; RUN: opt < %t/memprof-dump-matched-alloc-site.ll -passes='memprof-use<profile-filename=%t/memprof-dump-matched-alloc-site.memprofdata>' -memprof-print-match-info -memprof-print-function-guids -S 2>&1 | FileCheck %s
;--- memprof-dump-matched-alloc-site.yaml
---
@@ -78,7 +78,7 @@ HeapProfileRecords:
...
;--- memprof-dump-matched-alloc-site.ll
-;; From -memprof-function-guids
+;; From -memprof-print-function-guids
; CHECK: MemProf: Function GUID 4708092051066754107 is _Z2f1v
; CHECK: MemProf: Function GUID 14255129117669598641 is _Z2f2v
; CHECK: MemProf: Function GUID 2771528421763978342 is _Z2f3v
More information about the llvm-commits
mailing list