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

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 15:48:47 PST 2024


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

>From b9f47ea15106fea01626e1d5e779f79bcb9ecbbb 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 such a first line including the function name
also when using the new pass manager version of LoopPrinterPass.

The format of the string is changed slightly, so now we say:

Loop info for function 'func':
Loop at depth 1 containing: ...
    Loop at depth 2 containing: ...

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

diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 87ddfe3e92ae9a..59c96a3371e87a 100644
--- a/llvm/lib/Analysis/LoopInfo.cpp
+++ b/llvm/lib/Analysis/LoopInfo.cpp
@@ -969,7 +969,9 @@ LoopInfo LoopAnalysis::run(Function &F, FunctionAnalysisManager &AM) {
 
 PreservedAnalyses LoopPrinterPass::run(Function &F,
                                        FunctionAnalysisManager &AM) {
-  AM.getResult<LoopAnalysis>(F).print(OS);
+  auto &LI = AM.getResult<LoopAnalysis>(F);
+  OS << "Loop info for function '" << F.getName() << "':\n";
+  LI.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..24ed59c49ccc24 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: Loop info for function 'func':
+; CHECK: Parallel Loop at depth 1 containing:



More information about the llvm-commits mailing list