Skip to content

Commit b58b3e1

Browse files
[MemProf] Add dot graph dumping immediately after stack node update (#143025)
To aid in debugging, (optionally) dump the dot graph immediately after the stack update phase (which matches nodes to interior callsites) and before we cleanup mismatched callee edges (either via tail call fixup, indirect call fixup, or nulling otherwise).
1 parent 01b9828 commit b58b3e1

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,9 @@ ModuleCallsiteContextGraph::ModuleCallsiteContextGraph(
21832183

21842184
updateStackNodes();
21852185

2186+
if (ExportToDot)
2187+
exportToDot("poststackupdate");
2188+
21862189
handleCallsitesWithMultipleTargets();
21872190

21882191
markBackedges();
@@ -2285,6 +2288,9 @@ IndexCallsiteContextGraph::IndexCallsiteContextGraph(
22852288

22862289
updateStackNodes();
22872290

2291+
if (ExportToDot)
2292+
exportToDot("poststackupdate");
2293+
22882294
handleCallsitesWithMultipleTargets();
22892295

22902296
markBackedges();

llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids.ll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
; RUN: --check-prefix=STATS --check-prefix=REMARKS
6565

6666
; RUN: cat %t.ccg.prestackupdate.dot | FileCheck %s --check-prefix=DOTPRE
67+
;; There are no changes for this test case in between from immediately after
68+
;; the stack update through the end of graph finalization, so the
69+
;; corresponding dot graphs should be identical.
70+
; RUN: cat %t.ccg.poststackupdate.dot | FileCheck %s --check-prefix=DOTPOST
6771
; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOTPOST
6872
;; We should clone D once for the cold allocations via C.
6973
; RUN: cat %t.ccg.cloned.dot | FileCheck %s --check-prefix=DOTCLONED
@@ -313,8 +317,8 @@ attributes #6 = { builtin }
313317
; DOTPRE: }
314318

315319

316-
; DOTPOST:digraph "postbuild" {
317-
; DOTPOST: label="postbuild";
320+
; DOTPOST:digraph "post
321+
; DOTPOST: label="post
318322
; DOTPOST: Node[[D:0x[a-z0-9]+]] [shape=record,tooltip="N[[D]] ContextIds: 1 2 3 4",fillcolor="mediumorchid1",style="filled",label="{OrigId: Alloc0\n_Z1Dv -\> _Znam}"];
319323
; DOTPOST: Node[[F:0x[a-z0-9]+]] [shape=record,tooltip="N[[F]] ContextIds: 2",fillcolor="brown1",style="filled",label="{OrigId: 13543580133643026784\n_Z1Fv -\> _Z1Dv}"];
320324
; DOTPOST: Node[[F]] -> Node[[D]][tooltip="ContextIds: 2",fillcolor="brown1"

llvm/test/Transforms/MemProfContextDisambiguation/tailcall-nonunique.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66
; REQUIRES: asserts
77

88
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
9+
; RUN: -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
910
; RUN: -stats -debug %s -S 2>&1 | FileCheck %s --check-prefix=STATS \
1011
; RUN: --check-prefix=IR --check-prefix=DEBUG
1112

1213
; DEBUG: Not found through unique tail call chain: _Z3barv from main that actually called xyz (found multiple possible chains)
1314

15+
;; Graph fixup should have nulled the call in the node that could not be
16+
;; resolved via tail call fixup. That happens in between the initial
17+
;; stack update and the end of graph building.
18+
; RUN: cat %t.ccg.poststackupdate.dot | FileCheck %s --check-prefix=DOTPOSTSTACKUPDATE
19+
; DOTPOSTSTACKUPDATE: {OrigId: 15025054523792398438\nmain -\> xyz}
20+
; RUN: cat %t.ccg.postbuild.dot | FileCheck %s --check-prefix=DOTPOSTBUILD
21+
; DOTPOSTBUILD: {OrigId: 15025054523792398438\nnull call (external)}
22+
1423
;; Check that all calls in the IR are to the original functions, leading to a
1524
;; non-cold operator new call.
1625

0 commit comments

Comments
 (0)