Skip to content

[MemProf] Display backedges with dotted line in dot graphs #128235

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

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions llvm/test/ThinLTO/X86/memprof-recursive.ll
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@
; 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[[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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,19 @@
;; 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[[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).
Expand Down