[llvm] [MemProf] Display backedges with dotted line in dot graphs (PR #128235)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 21 13:23:11 PST 2025
https://github.com/teresajohnson created https://github.com/llvm/llvm-project/pull/128235
Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.
>From 38736d96d0d16e2998f22b8267322b69d3aeda40 Mon Sep 17 00:00:00 2001
From: Teresa Johnson <tejohnson at google.com>
Date: Fri, 21 Feb 2025 13:07:24 -0800
Subject: [PATCH] [MemProf] Display backedges with dotted line in dot graphs
Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.
---
.../IPO/MemProfContextDisambiguation.cpp | 14 +++++++++-----
llvm/test/ThinLTO/X86/memprof-recursive.ll | 9 +++++++++
.../MemProfContextDisambiguation/recursive.ll | 9 +++++++++
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 705806b98f8da..85fb0b770f1ed 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -3067,11 +3067,15 @@ struct DOTGraphTraits<const CallsiteContextGraph<DerivedCCG, FuncTy, CallTy> *>
GraphType) {
auto &Edge = *(ChildIter.getCurrent());
auto Color = getColor(Edge->AllocTypes);
- return (Twine("tooltip=\"") + getContextIds(Edge->ContextIds) + "\"" +
- // fillcolor is the arrow head and color is the line
- Twine(",fillcolor=\"") + Color + "\"" + Twine(",color=\"") + Color +
- "\"")
- .str();
+ std::string AttributeString =
+ (Twine("tooltip=\"") + getContextIds(Edge->ContextIds) + "\"" +
+ // fillcolor is the arrow head and color is the line
+ Twine(",fillcolor=\"") + Color + "\"" + Twine(",color=\"") + Color +
+ "\"")
+ .str();
+ if (Edge->IsBackedge)
+ AttributeString += ",style=\"dotted\"";
+ return AttributeString;
}
// Since the NodeOwners list includes nodes that are no longer connected to
diff --git a/llvm/test/ThinLTO/X86/memprof-recursive.ll b/llvm/test/ThinLTO/X86/memprof-recursive.ll
index e1a9084b583b9..a39f9216e8ab4 100644
--- a/llvm/test/ThinLTO/X86/memprof-recursive.ll
+++ b/llvm/test/ThinLTO/X86/memprof-recursive.ll
@@ -52,11 +52,20 @@
; RUN: -r=%t.o,main,plx \
; RUN: -r=%t.o,_Znam, \
; RUN: -memprof-verify-ccg -memprof-verify-nodes -stats \
+; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
; RUN: -pass-remarks=memprof-context-disambiguation \
; RUN: -o %t.out 2>&1 | FileCheck %s \
; RUN: --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS \
; RUN: --check-prefix=CLONE-RECUR-CALLSITES
+;; Check that the backedge was correctly detected and emitted to the dot file
+;; as a dotted edge.
+; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
+; DOT-DAG: Node[[B:0x[a-f0-9]+]] {{.*}}_Z1Bi -\> _Z1Ci
+; DOT-DAG: Node[[C:0x[a-f0-9]+]] {{.*}}_Z1Ci -\> _Z1Bi
+; DOT-DAG: Node[[B]] -> Node[[C]]{{.*}}style="solid"
+; DOT-DAG: Node[[C]] -> Node[[B]]{{.*}}style="dotted"
+
;; Skipping recursive contexts should prevent spurious call to cloned version of
;; B from the context starting at memprof_recursive.cc:19:13, which is actually
;; recursive (until that support is added).
diff --git a/llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll b/llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll
index 1d09b1c1a0cb3..ed5c43ceaf375 100644
--- a/llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll
+++ b/llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll
@@ -64,11 +64,20 @@
;; Check the default behavior (clone recursive callsites).
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
; RUN: -memprof-verify-ccg -memprof-verify-nodes -stats \
+; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
; RUN: -pass-remarks=memprof-context-disambiguation \
; RUN: %s -S 2>&1 | FileCheck %s \
; RUN: --check-prefix=ALL --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS \
; RUN: --check-prefix=CLONE-RECUR-CALLSITES
+;; Check that the backedge was correctly detected and emitted to the dot file
+;; as a dotted edge.
+; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
+; DOT-DAG: Node[[B:0x[a-f0-9]+]] {{.*}}_Z1Bi -\> _Z1Ci
+; DOT-DAG: Node[[C:0x[a-f0-9]+]] {{.*}}_Z1Ci -\> _Z1Bi
+; DOT-DAG: Node[[B]] -> Node[[C]]{{.*}}style="solid"
+; DOT-DAG: Node[[C]] -> Node[[B]]{{.*}}style="dotted"
+
;; Skipping recursive contexts should prevent spurious call to cloned version of
;; B from the context starting at memprof_recursive.cc:19:13, which is actually
;; recursive (until that support is added).
More information about the llvm-commits
mailing list