[llvm] [BOLT] Add dump-dot-func option for selective function CFG dumping (PR #153007)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 06:17:41 PDT 2025


https://github.com/yafet-a updated https://github.com/llvm/llvm-project/pull/153007

>From 2a2216f7ae07080d823d136c801cfca99a232b07 Mon Sep 17 00:00:00 2001
From: Yafet Beyene <ybeyene at nvidia.com>
Date: Fri, 8 Aug 2025 09:01:41 -0700
Subject: [PATCH 1/5] [BOLT] dump-dot-func option added to bolt

---
 bolt/include/bolt/Utils/CommandLineOpts.h |  9 +++++++
 bolt/lib/Rewrite/BinaryPassManager.cpp    |  3 ++-
 bolt/lib/Rewrite/RewriteInstance.cpp      | 31 ++++++++++++++++++++++-
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/bolt/include/bolt/Utils/CommandLineOpts.h b/bolt/include/bolt/Utils/CommandLineOpts.h
index a75b6bf720ec4..859d6f3bf6774 100644
--- a/bolt/include/bolt/Utils/CommandLineOpts.h
+++ b/bolt/include/bolt/Utils/CommandLineOpts.h
@@ -15,6 +15,12 @@
 
 #include "llvm/Support/CommandLine.h"
 
+namespace llvm {
+namespace bolt {
+class BinaryFunction;
+}
+} // namespace llvm
+
 namespace opts {
 
 enum HeatmapModeKind {
@@ -100,6 +106,9 @@ extern llvm::cl::opt<unsigned> Verbosity;
 /// Return true if we should process all functions in the binary.
 bool processAllFunctions();
 
+/// Return true if we should dump dot graphs for the given function.
+bool shouldDumpDot(const llvm::bolt::BinaryFunction &Function);
+
 enum GadgetScannerKind { GS_PACRET, GS_PAUTH, GS_ALL };
 
 extern llvm::cl::bits<GadgetScannerKind> GadgetScannersToRun;
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp
index 996d2e972599d..0ddb73f828878 100644
--- a/bolt/lib/Rewrite/BinaryPassManager.cpp
+++ b/bolt/lib/Rewrite/BinaryPassManager.cpp
@@ -52,6 +52,7 @@ namespace opts {
 extern cl::opt<bool> PrintAll;
 extern cl::opt<bool> PrintDynoStats;
 extern cl::opt<bool> DumpDotAll;
+extern bool shouldDumpDot(const bolt::BinaryFunction &Function);
 extern cl::opt<std::string> AsmDump;
 extern cl::opt<bolt::PLTCall::OptType> PLT;
 extern cl::opt<bolt::IdenticalCodeFolding::ICFLevel, false,
@@ -340,7 +341,7 @@ Error BinaryFunctionPassManager::runPasses() {
 
       Function.print(BC.outs(), Message);
 
-      if (opts::DumpDotAll)
+      if (opts::shouldDumpDot(Function))
         Function.dumpGraphForPass(PassIdName);
     }
   }
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index fe4a23cc01382..69dcc8ce08a5b 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -114,6 +114,35 @@ cl::opt<bool> DumpDotAll(
              "enable '-print-loops' for color-coded blocks"),
     cl::Hidden, cl::cat(BoltCategory));
 
+cl::list<std::string> DumpDotFunc(
+    "dump-dot-func", cl::CommaSeparated,
+    cl::desc(
+        "dump function CFGs to graphviz format for specified functions only;"
+        "takes function name patterns (regex supported)"),
+    cl::value_desc("func1,func2,func3,..."), cl::Hidden, cl::cat(BoltCategory));
+
+bool shouldDumpDot(const bolt::BinaryFunction &Function) {
+  // If dump-dot-all is enabled, dump all functions
+  if (DumpDotAll)
+    return !Function.isIgnored();
+
+  // If no specific functions specified in dump-dot-func, don't dump any
+  if (DumpDotFunc.empty())
+    return false;
+
+  if (Function.isIgnored())
+    return false;
+
+  // Check if function matches any of the specified patterns
+  for (const std::string &Name : DumpDotFunc) {
+    if (Function.hasNameRegex(Name)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 static cl::list<std::string>
 ForceFunctionNames("funcs",
   cl::CommaSeparated,
@@ -3570,7 +3599,7 @@ void RewriteInstance::postProcessFunctions() {
     if (opts::PrintAll || opts::PrintCFG)
       Function.print(BC->outs(), "after building cfg");
 
-    if (opts::DumpDotAll)
+    if (opts::shouldDumpDot(Function))
       Function.dumpGraphForPass("00_build-cfg");
 
     if (opts::PrintLoopInfo) {

>From fc1996ae472cf0b3cfb51c0805500f08c893946c Mon Sep 17 00:00:00 2001
From: Yafet Beyene <ybeyene at nvidia.com>
Date: Mon, 11 Aug 2025 06:56:45 -0700
Subject: [PATCH 2/5] [BOLT] Added dump-dot-func tests

---
 bolt/docs/CommandLineArgumentReference.md |  5 +++
 bolt/test/Inputs/multi-func.c             | 24 +++++++++++++
 bolt/test/dump-dot-func.test              | 43 +++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 bolt/test/Inputs/multi-func.c
 create mode 100644 bolt/test/dump-dot-func.test

diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md
index f3881c9a640a9..de54184ff8db1 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -138,6 +138,11 @@
   Dump function CFGs to graphviz format after each stage;enable '-print-loops'
   for color-coded blocks
 
+- `--dump-dot-func=<func1,func2,func3...>`
+
+  Dump function CFGs to graphviz format for specified functions only;
+  takes function name patterns (regex supported)
+
 - `--dump-linux-exceptions`
 
   Dump Linux kernel exception table
diff --git a/bolt/test/Inputs/multi-func.c b/bolt/test/Inputs/multi-func.c
new file mode 100644
index 0000000000000..622cc285570e0
--- /dev/null
+++ b/bolt/test/Inputs/multi-func.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+
+// Multiple functions to test selective dumping
+int add(int a, int b) { return a + b; }
+
+int multiply(int a, int b) { return a * b; }
+
+int main_helper() {
+  printf("Helper function\n");
+  return 42;
+}
+
+int main_secondary() { return add(5, 3); }
+
+void other_function() { printf("Other function\n"); }
+
+int main() {
+  int result = add(10, 20);
+  result = multiply(result, 2);
+  main_helper();
+  main_secondary();
+  other_function();
+  return result;
+}
\ No newline at end of file
diff --git a/bolt/test/dump-dot-func.test b/bolt/test/dump-dot-func.test
new file mode 100644
index 0000000000000..3b62130ef1f6d
--- /dev/null
+++ b/bolt/test/dump-dot-func.test
@@ -0,0 +1,43 @@
+# Test the --dump-dot-func option with multiple functions
+
+RUN: %clang %p/Inputs/multi-func.c -o %t.exe -Wl,-q
+
+# Test 1: --dump-dot-func with specific function name
+RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=add --print-only=add -v=1 2>&1 | FileCheck %s --check-prefix=ADD
+RUN: ls add-*.dot | wc -l | FileCheck %s --check-prefix=COUNT-ONE
+
+# Test 2: --dump-dot-func with regex pattern (main.*)
+RUN: llvm-bolt %t.exe -o %t.bolt2 --dump-dot-func="main.*" --print-only=main,main_helper,main_secondary -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-REGEX
+
+# Test 3: --dump-dot-func with multiple specific functions
+RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=add,multiply --print-only=add,multiply -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
+
+# Test 4: No option specified should create no dot files
+RUN: llvm-bolt %t.exe -o %t.bolt4 --print-only=main 2>&1 | FileCheck %s --check-prefix=NONE
+
+# Test 5: --dump-dot-func with non-existent function
+RUN: llvm-bolt %t.exe -o %t.bolt5 --dump-dot-func=nonexistent --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=NONEXISTENT
+
+# Test 6: Backward compatibility - --dump-dot-all should still work
+RUN: llvm-bolt %t.exe -o %t.bolt6 --dump-dot-all --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=ALL
+
+# Check that specific functions are dumped
+ADD: BOLT-INFO: dumping CFG to add-00_build-cfg.dot
+
+MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main_helper-00_build-cfg.dot
+MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main_secondary-00_build-cfg.dot
+
+MULTI-DAG: BOLT-INFO: dumping CFG to add-00_build-cfg.dot
+MULTI-DAG: BOLT-INFO: dumping CFG to multiply-00_build-cfg.dot
+
+# Should be no dumping messages when no option is specified
+NONE-NOT: BOLT-INFO: dumping CFG
+
+# Should be no dumping messages for non-existent function
+NONEXISTENT-NOT: BOLT-INFO: dumping CFG
+
+ALL: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+
+# Count checks
+COUNT-ONE: 1
\ No newline at end of file

>From 1ff4dba214357871d4cdf44a919ab975fba0c6e5 Mon Sep 17 00:00:00 2001
From: Yafet Beyene <ybeyene at nvidia.com>
Date: Wed, 13 Aug 2025 02:51:13 -0700
Subject: [PATCH 3/5] [BOLT] Updated tests to use cpp input to enable verifying
 passing in mangled names work

---
 .../Inputs/{multi-func.c => multi-func.cpp}   |  8 ++---
 bolt/test/dump-dot-func.test                  | 34 ++++++++++++-------
 2 files changed, 26 insertions(+), 16 deletions(-)
 rename bolt/test/Inputs/{multi-func.c => multi-func.cpp} (72%)

diff --git a/bolt/test/Inputs/multi-func.c b/bolt/test/Inputs/multi-func.cpp
similarity index 72%
rename from bolt/test/Inputs/multi-func.c
rename to bolt/test/Inputs/multi-func.cpp
index 622cc285570e0..61c968fc27f98 100644
--- a/bolt/test/Inputs/multi-func.c
+++ b/bolt/test/Inputs/multi-func.cpp
@@ -1,4 +1,4 @@
-#include <stdio.h>
+#include <iostream>
 
 // Multiple functions to test selective dumping
 int add(int a, int b) { return a + b; }
@@ -6,13 +6,13 @@ int add(int a, int b) { return a + b; }
 int multiply(int a, int b) { return a * b; }
 
 int main_helper() {
-  printf("Helper function\n");
+  std::cout << "Helper function" << std::endl;
   return 42;
 }
 
 int main_secondary() { return add(5, 3); }
 
-void other_function() { printf("Other function\n"); }
+void other_function() { std::cout << "Other function" << std::endl; }
 
 int main() {
   int result = add(10, 20);
@@ -21,4 +21,4 @@ int main() {
   main_secondary();
   other_function();
   return result;
-}
\ No newline at end of file
+}
diff --git a/bolt/test/dump-dot-func.test b/bolt/test/dump-dot-func.test
index 3b62130ef1f6d..88d56c438638d 100644
--- a/bolt/test/dump-dot-func.test
+++ b/bolt/test/dump-dot-func.test
@@ -1,16 +1,17 @@
-# Test the --dump-dot-func option with multiple functions
+# Test the --dump-dot-func option with multiple functions 
+# (includes tests for both mangled/unmangled names)
 
-RUN: %clang %p/Inputs/multi-func.c -o %t.exe -Wl,-q
+RUN: %clang++ %p/Inputs/multi-func.cpp -o %t.exe -Wl,-q
 
-# Test 1: --dump-dot-func with specific function name
-RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=add --print-only=add -v=1 2>&1 | FileCheck %s --check-prefix=ADD
-RUN: ls add-*.dot | wc -l | FileCheck %s --check-prefix=COUNT-ONE
+# Test 1: --dump-dot-func with specific function name (mangled)
+RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=_Z3addii --print-only=_Z3addii -v=1 2>&1 | FileCheck %s --check-prefix=ADD
+RUN: ls _Z3addii-*.dot | wc -l | FileCheck %s --check-prefix=COUNT-ONE
 
 # Test 2: --dump-dot-func with regex pattern (main.*)
 RUN: llvm-bolt %t.exe -o %t.bolt2 --dump-dot-func="main.*" --print-only=main,main_helper,main_secondary -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-REGEX
 
-# Test 3: --dump-dot-func with multiple specific functions
-RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=add,multiply --print-only=add,multiply -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
+# Test 3: --dump-dot-func with multiple specific functions (mangled names)
+RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=_Z3addii,_Z8multiplyii --print-only=_Z3addii,_Z8multiplyii -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
 
 # Test 4: No option specified should create no dot files
 RUN: llvm-bolt %t.exe -o %t.bolt4 --print-only=main 2>&1 | FileCheck %s --check-prefix=NONE
@@ -21,15 +22,19 @@ RUN: llvm-bolt %t.exe -o %t.bolt5 --dump-dot-func=nonexistent --print-only=main
 # Test 6: Backward compatibility - --dump-dot-all should still work
 RUN: llvm-bolt %t.exe -o %t.bolt6 --dump-dot-all --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=ALL
 
+# Test 7: Test with helper function (mangled name)
+RUN: llvm-bolt %t.exe -o %t.bolt7 --dump-dot-func=_Z11main_helperv --print-only=_Z11main_helperv -v=1 2>&1 | FileCheck %s --check-prefix=HELPER
+
+# Test 8: Test with unmangled function name (main function)
+RUN: llvm-bolt %t.exe -o %t.bolt8 --dump-dot-func=main --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-UNMANGLED
+
 # Check that specific functions are dumped
-ADD: BOLT-INFO: dumping CFG to add-00_build-cfg.dot
+ADD: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
 
 MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
-MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main_helper-00_build-cfg.dot
-MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main_secondary-00_build-cfg.dot
 
-MULTI-DAG: BOLT-INFO: dumping CFG to add-00_build-cfg.dot
-MULTI-DAG: BOLT-INFO: dumping CFG to multiply-00_build-cfg.dot
+MULTI-DAG: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
+MULTI-DAG: BOLT-INFO: dumping CFG to _Z8multiplyii-00_build-cfg.dot
 
 # Should be no dumping messages when no option is specified
 NONE-NOT: BOLT-INFO: dumping CFG
@@ -39,5 +44,10 @@ NONEXISTENT-NOT: BOLT-INFO: dumping CFG
 
 ALL: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
 
+HELPER: BOLT-INFO: dumping CFG to _Z11main_helperv-00_build-cfg.dot
+
+# Test that unmangled function names still work
+MAIN-UNMANGLED: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+
 # Count checks
 COUNT-ONE: 1
\ No newline at end of file

>From da220c5be62282abdd5adb3a947a083e52d7d7f4 Mon Sep 17 00:00:00 2001
From: Yafet Beyene <ybeyene at nvidia.com>
Date: Wed, 13 Aug 2025 07:44:44 -0700
Subject: [PATCH 4/5] [BOLT] Updated tests to use test -f and no longer use
 print-only

---
 bolt/docs/CommandLineArgumentReference.md |  3 +-
 bolt/test/dump-dot-func.test              | 56 +++++++++++++++--------
 2 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/bolt/docs/CommandLineArgumentReference.md b/bolt/docs/CommandLineArgumentReference.md
index de54184ff8db1..d65cf39e16b29 100644
--- a/bolt/docs/CommandLineArgumentReference.md
+++ b/bolt/docs/CommandLineArgumentReference.md
@@ -141,7 +141,8 @@
 - `--dump-dot-func=<func1,func2,func3...>`
 
   Dump function CFGs to graphviz format for specified functions only;
-  takes function name patterns (regex supported)
+  takes function name patterns (regex supported). Note: C++ function names
+  must be passed using their mangled names
 
 - `--dump-linux-exceptions`
 
diff --git a/bolt/test/dump-dot-func.test b/bolt/test/dump-dot-func.test
index 88d56c438638d..5592af92c6798 100644
--- a/bolt/test/dump-dot-func.test
+++ b/bolt/test/dump-dot-func.test
@@ -1,32 +1,55 @@
 # Test the --dump-dot-func option with multiple functions 
-# (includes tests for both mangled/unmangled names)
+# (includes tests for both mangled/unmangled names)
 
 RUN: %clang++ %p/Inputs/multi-func.cpp -o %t.exe -Wl,-q
 
 # Test 1: --dump-dot-func with specific function name (mangled)
-RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=_Z3addii --print-only=_Z3addii -v=1 2>&1 | FileCheck %s --check-prefix=ADD
-RUN: ls _Z3addii-*.dot | wc -l | FileCheck %s --check-prefix=COUNT-ONE
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=_Z3addii -v=1 2>&1 | FileCheck %s --check-prefix=ADD
+RUN: test -f _Z3addii-00_build-cfg.dot
+RUN: test ! -f main-00_build-cfg.dot
+RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 2: --dump-dot-func with regex pattern (main.*)
-RUN: llvm-bolt %t.exe -o %t.bolt2 --dump-dot-func="main.*" --print-only=main,main_helper,main_secondary -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-REGEX
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt2 --dump-dot-func="main.*" -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-REGEX
+RUN: test -f main-00_build-cfg.dot
+RUN: test ! -f _Z3addii-00_build-cfg.dot
+RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 3: --dump-dot-func with multiple specific functions (mangled names)
-RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=_Z3addii,_Z8multiplyii --print-only=_Z3addii,_Z8multiplyii -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=_Z3addii,_Z8multiplyii -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
+RUN: test -f _Z3addii-00_build-cfg.dot
+RUN: test -f _Z8multiplyii-00_build-cfg.dot
+RUN: test ! -f main-00_build-cfg.dot
+RUN: test ! -f _Z11main_helperv-00_build-cfg.dot
 
 # Test 4: No option specified should create no dot files
-RUN: llvm-bolt %t.exe -o %t.bolt4 --print-only=main 2>&1 | FileCheck %s --check-prefix=NONE
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt4 2>&1 | FileCheck %s --check-prefix=NONE
+RUN: test ! -f _Z3addii-00_build-cfg.dot
+RUN: test ! -f main-00_build-cfg.dot
+RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 5: --dump-dot-func with non-existent function
-RUN: llvm-bolt %t.exe -o %t.bolt5 --dump-dot-func=nonexistent --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=NONEXISTENT
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt5 --dump-dot-func=nonexistent -v=1 2>&1 | FileCheck %s --check-prefix=NONEXISTENT
+RUN: test ! -f nonexistent-00_build-cfg.dot
+RUN: test ! -f _Z3addii-00_build-cfg.dot
+RUN: test ! -f main-00_build-cfg.dot
 
 # Test 6: Backward compatibility - --dump-dot-all should still work
-RUN: llvm-bolt %t.exe -o %t.bolt6 --dump-dot-all --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=ALL
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt6 --dump-dot-all -v=1 2>&1 | FileCheck %s --check-prefix=ALL
+RUN: test -f main-00_build-cfg.dot
 
-# Test 7: Test with helper function (mangled name)
-RUN: llvm-bolt %t.exe -o %t.bolt7 --dump-dot-func=_Z11main_helperv --print-only=_Z11main_helperv -v=1 2>&1 | FileCheck %s --check-prefix=HELPER
-
-# Test 8: Test with unmangled function name (main function)
-RUN: llvm-bolt %t.exe -o %t.bolt8 --dump-dot-func=main --print-only=main -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-UNMANGLED
+# Test 7: Test with unmangled function name (main function)
+RUN: rm -f *.dot
+RUN: llvm-bolt %t.exe -o %t.bolt7 --dump-dot-func=main -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-UNMANGLED
+RUN: test -f main-00_build-cfg.dot
+RUN: test ! -f _Z3addii-00_build-cfg.dot
+RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Check that specific functions are dumped
 ADD: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
@@ -44,10 +67,5 @@ NONEXISTENT-NOT: BOLT-INFO: dumping CFG
 
 ALL: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
 
-HELPER: BOLT-INFO: dumping CFG to _Z11main_helperv-00_build-cfg.dot
-
 # Test that unmangled function names still work
-MAIN-UNMANGLED: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
-
-# Count checks
-COUNT-ONE: 1
\ No newline at end of file
+MAIN-UNMANGLED: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
\ No newline at end of file

>From ec23c37eda0d4638f43f2f68d1e92bc6c4cb4374 Mon Sep 17 00:00:00 2001
From: Yafet Beyene <ybeyene at nvidia.com>
Date: Thu, 14 Aug 2025 03:50:52 -0700
Subject: [PATCH 5/5] [BOLT] Updated Tests to use simple pattern matching

---
 bolt/test/dump-dot-func.test | 39 +++++++++---------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/bolt/test/dump-dot-func.test b/bolt/test/dump-dot-func.test
index 5592af92c6798..510713dde6167 100644
--- a/bolt/test/dump-dot-func.test
+++ b/bolt/test/dump-dot-func.test
@@ -4,60 +4,40 @@
 RUN: %clang++ %p/Inputs/multi-func.cpp -o %t.exe -Wl,-q
 
 # Test 1: --dump-dot-func with specific function name (mangled)
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt1 --dump-dot-func=_Z3addii -v=1 2>&1 | FileCheck %s --check-prefix=ADD
-RUN: test -f _Z3addii-00_build-cfg.dot
-RUN: test ! -f main-00_build-cfg.dot
-RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 2: --dump-dot-func with regex pattern (main.*)
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt2 --dump-dot-func="main.*" -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-REGEX
-RUN: test -f main-00_build-cfg.dot
-RUN: test ! -f _Z3addii-00_build-cfg.dot
-RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 3: --dump-dot-func with multiple specific functions (mangled names)
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt3 --dump-dot-func=_Z3addii,_Z8multiplyii -v=1 2>&1 | FileCheck %s --check-prefix=MULTI
-RUN: test -f _Z3addii-00_build-cfg.dot
-RUN: test -f _Z8multiplyii-00_build-cfg.dot
-RUN: test ! -f main-00_build-cfg.dot
-RUN: test ! -f _Z11main_helperv-00_build-cfg.dot
 
 # Test 4: No option specified should create no dot files
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt4 2>&1 | FileCheck %s --check-prefix=NONE
-RUN: test ! -f _Z3addii-00_build-cfg.dot
-RUN: test ! -f main-00_build-cfg.dot
-RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Test 5: --dump-dot-func with non-existent function
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt5 --dump-dot-func=nonexistent -v=1 2>&1 | FileCheck %s --check-prefix=NONEXISTENT
-RUN: test ! -f nonexistent-00_build-cfg.dot
-RUN: test ! -f _Z3addii-00_build-cfg.dot
-RUN: test ! -f main-00_build-cfg.dot
 
 # Test 6: Backward compatibility - --dump-dot-all should still work
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt6 --dump-dot-all -v=1 2>&1 | FileCheck %s --check-prefix=ALL
-RUN: test -f main-00_build-cfg.dot
 
 # Test 7: Test with unmangled function name (main function)
-RUN: rm -f *.dot
 RUN: llvm-bolt %t.exe -o %t.bolt7 --dump-dot-func=main -v=1 2>&1 | FileCheck %s --check-prefix=MAIN-UNMANGLED
-RUN: test -f main-00_build-cfg.dot
-RUN: test ! -f _Z3addii-00_build-cfg.dot
-RUN: test ! -f _Z8multiplyii-00_build-cfg.dot
 
 # Check that specific functions are dumped
 ADD: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
+ADD-NOT: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+ADD-NOT: BOLT-INFO: dumping CFG to _Z8multiplyii-00_build-cfg.dot
+ADD-NOT: BOLT-INFO: dumping CFG to _Z11main_helperv-00_build-cfg.dot
 
 MAIN-REGEX-DAG: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+MAIN-REGEX-NOT: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
+MAIN-REGEX-NOT: BOLT-INFO: dumping CFG to _Z8multiplyii-00_build-cfg.dot
 
 MULTI-DAG: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
 MULTI-DAG: BOLT-INFO: dumping CFG to _Z8multiplyii-00_build-cfg.dot
+MULTI-NOT: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+MULTI-NOT: BOLT-INFO: dumping CFG to _Z11main_helperv-00_build-cfg.dot
 
 # Should be no dumping messages when no option is specified
 NONE-NOT: BOLT-INFO: dumping CFG
@@ -67,5 +47,6 @@ NONEXISTENT-NOT: BOLT-INFO: dumping CFG
 
 ALL: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
 
-# Test that unmangled function names still work
-MAIN-UNMANGLED: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
\ No newline at end of file
+MAIN-UNMANGLED: BOLT-INFO: dumping CFG to main-00_build-cfg.dot
+MAIN-UNMANGLED-NOT: BOLT-INFO: dumping CFG to _Z3addii-00_build-cfg.dot
+MAIN-UNMANGLED-NOT: BOLT-INFO: dumping CFG to _Z8multiplyii-00_build-cfg.dot
\ No newline at end of file



More information about the llvm-commits mailing list