[llvm] [LoopInfo][NewPM] Print function name in LoopPrinterPass (PR #76527)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 11:12:27 PST 2023


https://github.com/bjope created https://github.com/llvm/llvm-project/pull/76527

The legacy pass manager printed the function name when printing loop info (via -analyze option). Like this:

Printing analysis 'Natural Loop Information' for function 'func': Loop at depth 1 containing: ...
    Loop at depth 2 containing: ...

Make sure we print that first line including the function name also when using the new pass manager version of LoopPrinterPass.

This was requested in
  https://discourse.llvm.org/t/need-usage-help-w-new-pass-manager-for-opt-analysis-natural-loop-information/75874/7

>From c75646f50ab03befafa71386ccc948e6b0d26ffb Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson <bjorn.a.pettersson at ericsson.com>
Date: Thu, 28 Dec 2023 20:06:40 +0100
Subject: [PATCH] [LoopInfo][NewPM] Print function name in LoopPrinterPass

The legacy pass manager printed the function name when printing
loop info (via -analyze option). Like this:

Printing analysis 'Natural Loop Information' for function 'func':
Loop at depth 1 containing: ...
    Loop at depth 2 containing: ...

Make sure we print that first line including the function name
also when using the new pass manager version of LoopPrinterPass.

This was requested in
  https://discourse.llvm.org/t/need-usage-help-w-new-pass-manager-for-opt-analysis-natural-loop-information/75874/7
---
 llvm/lib/Analysis/LoopInfo.cpp                           | 2 ++
 llvm/test/Analysis/LoopInfo/annotated-parallel-simple.ll | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 87ddfe3e92ae9a..e847d8afa7048f 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -969,6 +969,8 @@ LoopInfo LoopAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
 
 PreservedAnalyses LoopPrinterPass::run(Function &F,
                                        FunctionAnalysisManager &AM) {
+  OS << "Printing analysis 'Natural Loop Information' for function '"
+     << F.getName() << "':\n";
   AM.getResult<LoopAnalysis>(F).print(OS);
   return PreservedAnalyses::all();
 }
diff --git a/llvm/test/Analysis/LoopInfo/annotated-parallel-simple.ll b/llvm/test/Analysis/LoopInfo/annotated-parallel-simple.ll
index d96ff492c53a76..39d2ba8c16c589 100644
--- a/llvm/test/Analysis/LoopInfo/annotated-parallel-simple.ll
+++ b/llvm/test/Analysis/LoopInfo/annotated-parallel-simple.ll
@@ -33,5 +33,5 @@ for.end:
 !7 = distinct !{!7, !9} ; LoopID
 !9 = !{!"llvm.loop.parallel_accesses", !6}
 
-
-; CHECK: Parallel Loop
+; CHECK: Printing analysis 'Natural Loop Information' for function 'func':
+; CHECK: Parallel Loop at depth 1 containing:



More information about the llvm-commits mailing list