Skip to content

Conversation

@teresajohnson
Copy link
Contributor

Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.

Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.
@llvmbot llvmbot added LTO Link time optimization (regular/full LTO or ThinLTO) llvm:transforms labels Feb 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-lto

Author: Teresa Johnson (teresajohnson)

Changes

Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.


Full diff: https://github.com/llvm/llvm-project/pull/128235.diff

3 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp (+9-5)
  • (modified) llvm/test/ThinLTO/X86/memprof-recursive.ll (+9)
  • (modified) llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll (+9)
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).

@llvmbot
Copy link
Member

llvmbot commented Feb 21, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Teresa Johnson (teresajohnson)

Changes

Add checking of this behavior in the postbuild dot graphs, facilitated
by PR128226 which marked these edges at the end of the graph building.


Full diff: https://github.com/llvm/llvm-project/pull/128235.diff

3 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp (+9-5)
  • (modified) llvm/test/ThinLTO/X86/memprof-recursive.ll (+9)
  • (modified) llvm/test/Transforms/MemProfContextDisambiguation/recursive.ll (+9)
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).

@teresajohnson teresajohnson merged commit 92e02ad into llvm:main Feb 21, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:transforms LTO Link time optimization (regular/full LTO or ThinLTO)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants