Skip to content

Commit 38736d9

Browse files
committed
[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.
1 parent 236fa50 commit 38736d9

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,11 +3067,15 @@ struct DOTGraphTraits<const CallsiteContextGraph<DerivedCCG, FuncTy, CallTy> *>
30673067
GraphType) {
30683068
auto &Edge = *(ChildIter.getCurrent());
30693069
auto Color = getColor(Edge->AllocTypes);
3070-
return (Twine("tooltip=\"") + getContextIds(Edge->ContextIds) + "\"" +
3071-
// fillcolor is the arrow head and color is the line
3072-
Twine(",fillcolor=\"") + Color + "\"" + Twine(",color=\"") + Color +
3073-
"\"")
3074-
.str();
3070+
std::string AttributeString =
3071+
(Twine("tooltip=\"") + getContextIds(Edge->ContextIds) + "\"" +
3072+
// fillcolor is the arrow head and color is the line
3073+
Twine(",fillcolor=\"") + Color + "\"" + Twine(",color=\"") + Color +
3074+
"\"")
3075+
.str();
3076+
if (Edge->IsBackedge)
3077+
AttributeString += ",style=\"dotted\"";
3078+
return AttributeString;
30753079
}
30763080

30773081
// Since the NodeOwners list includes nodes that are no longer connected to

llvm/test/ThinLTO/X86/memprof-recursive.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,20 @@
5252
; RUN: -r=%t.o,main,plx \
5353
; RUN: -r=%t.o,_Znam, \
5454
; RUN: -memprof-verify-ccg -memprof-verify-nodes -stats \
55+
; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
5556
; RUN: -pass-remarks=memprof-context-disambiguation \
5657
; RUN: -o %t.out 2>&1 | FileCheck %s \
5758
; RUN: --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS \
5859
; RUN: --check-prefix=CLONE-RECUR-CALLSITES
5960

61+
;; Check that the backedge was correctly detected and emitted to the dot file
62+
;; as a dotted edge.
63+
; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
64+
; DOT-DAG: Node[[B:0x[a-f0-9]+]] {{.*}}_Z1Bi -\> _Z1Ci
65+
; DOT-DAG: Node[[C:0x[a-f0-9]+]] {{.*}}_Z1Ci -\> _Z1Bi
66+
; DOT-DAG: Node[[B]] -> Node[[C]]{{.*}}style="solid"
67+
; DOT-DAG: Node[[C]] -> Node[[B]]{{.*}}style="dotted"
68+
6069
;; Skipping recursive contexts should prevent spurious call to cloned version of
6170
;; B from the context starting at memprof_recursive.cc:19:13, which is actually
6271
;; recursive (until that support is added).

llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,20 @@
6464
;; Check the default behavior (clone recursive callsites).
6565
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
6666
; RUN: -memprof-verify-ccg -memprof-verify-nodes -stats \
67+
; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
6768
; RUN: -pass-remarks=memprof-context-disambiguation \
6869
; RUN: %s -S 2>&1 | FileCheck %s \
6970
; RUN: --check-prefix=ALL --check-prefix=ALLOW-RECUR-CALLSITES --check-prefix=ALLOW-RECUR-CONTEXTS \
7071
; RUN: --check-prefix=CLONE-RECUR-CALLSITES
7172

73+
;; Check that the backedge was correctly detected and emitted to the dot file
74+
;; as a dotted edge.
75+
; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOT
76+
; DOT-DAG: Node[[B:0x[a-f0-9]+]] {{.*}}_Z1Bi -\> _Z1Ci
77+
; DOT-DAG: Node[[C:0x[a-f0-9]+]] {{.*}}_Z1Ci -\> _Z1Bi
78+
; DOT-DAG: Node[[B]] -> Node[[C]]{{.*}}style="solid"
79+
; DOT-DAG: Node[[C]] -> Node[[B]]{{.*}}style="dotted"
80+
7281
;; Skipping recursive contexts should prevent spurious call to cloned version of
7382
;; B from the context starting at memprof_recursive.cc:19:13, which is actually
7483
;; recursive (until that support is added).

0 commit comments

Comments
 (0)