[llvm] [LegacyPM] Print banner with newline when filter-print-funcs is given. (PR #153699)

Tyler Lanphear via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 15:09:13 PDT 2025


https://github.com/tylanphear created https://github.com/llvm/llvm-project/pull/153699

When using the legacy PM, if `-filter-print-funcs` is given with `-print-after-all`, the banner is printed without a newline for the first function printed, e.g:

```
*** IR Dump After Function Integration/Inlining (inline) ***; Function attrs:
define @foo() {
...
```

instead of the correct output:

```
*** IR Dump After Function Integration/Inlining (inline) ***
; Function attrs:
define @foo() {
...
```

This patch fixes the behavior by changing `PrintBannerOnce()` to emit a newline after the banner unconditionally.

>From 077d1b531dd8bf42466c81f418b607eb7627927b Mon Sep 17 00:00:00 2001
From: Tyler Lanphear <tylanphear at gmail.com>
Date: Thu, 14 Aug 2025 14:35:02 -0700
Subject: [PATCH] [LegacyPM] Print banner with newline when filter-print-funcs
 is given.

When using the legacy PM, if `-filter-print-funcs` is given with `-print-after-all`, the banner
is printed without a newline for the first function printed, e.g:

```
*** IR Dump After Function Integration/Inlining (inline) ***; Function attrs:
define @foo() {
...
```

instead of the correct output:

```
*** IR Dump After Function Integration/Inlining (inline) ***
; Function attrs:
define @foo() {
...
```

This patch fixes the behavior by changing `PrintBannerOnce()` to emit a
newline after the banner unconditionally.
---
 llvm/lib/Analysis/CallGraphSCCPass.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index de64fdb9548e6..91370f6dad002 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -678,14 +678,13 @@ namespace {
       auto PrintBannerOnce = [&]() {
         if (BannerPrinted)
           return;
-        OS << Banner;
+        OS << Banner << "\n";
         BannerPrinted = true;
       };
 
       bool NeedModule = llvm::forcePrintModuleIR();
       if (isFunctionInPrintList("*") && NeedModule) {
         PrintBannerOnce();
-        OS << "\n";
         SCC.getCallGraph().getModule().print(OS, nullptr);
         return false;
       }
@@ -701,12 +700,11 @@ namespace {
           }
         } else if (isFunctionInPrintList("*")) {
           PrintBannerOnce();
-          OS << "\nPrinting <null> Function\n";
+          OS << "Printing <null> Function\n";
         }
       }
       if (NeedModule && FoundFunction) {
         PrintBannerOnce();
-        OS << "\n";
         SCC.getCallGraph().getModule().print(OS, nullptr);
       }
       return false;



More information about the llvm-commits mailing list