From: Fedor Sergeev Date: Fri, 1 Dec 2017 18:33:58 +0000 (+0000) Subject: IR printing improvement for loop passes - handle -print-module-scope X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5608259c999fb77c5d6093895696f4daebe6b8cd;p=llvm IR printing improvement for loop passes - handle -print-module-scope Summary: Adding support for -print-module-scope similar to how it is being done for function passes. This option causes loop-pass printer to emit a whole-module IR instead of just a loop itself. Reviewers: sanjoy, silvas, weimingz Reviewed By: sanjoy Subscribers: apilipenko, skatkov, llvm-commits Differential Revision: https://reviews.llvm.org/D40247 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319566 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp index dce66fd3d96..9e54d60779a 100644 --- a/lib/Analysis/LoopInfo.cpp +++ b/lib/Analysis/LoopInfo.cpp @@ -731,6 +731,18 @@ PreservedAnalyses LoopPrinterPass::run(Function &F, } void llvm::printLoop(Loop &L, raw_ostream &OS, const std::string &Banner) { + + if (forcePrintModuleIR()) { + // handling -print-module-scope + OS << Banner << " (loop: "; + L.getHeader()->printAsOperand(OS, false); + OS << ")\n"; + + // printing whole module + OS << *L.getHeader()->getModule(); + return; + } + OS << Banner; auto *PreHeader = L.getLoopPreheader(); diff --git a/test/Other/loop-pass-printer.ll b/test/Other/loop-pass-printer.ll index e5ad8bdb1f9..bedcf164ace 100644 --- a/test/Other/loop-pass-printer.ll +++ b/test/Other/loop-pass-printer.ll @@ -7,7 +7,9 @@ ; RUN: opt < %s 2>&1 -disable-output \ ; RUN: -loop-unroll -print-after=loop-unroll -filter-print-funcs=bar \ ; RUN: | FileCheck %s -check-prefix=BAR -; +; RUN: opt < %s 2>&1 -disable-output \ +; RUN: -loop-unroll -print-after=loop-unroll -filter-print-funcs=foo -print-module-scope \ +; RUN: | FileCheck %s -check-prefix=FOO-MODULE ; DEL: IR Dump Before ; DEL-SAME: dead loops @@ -35,9 +37,17 @@ ; BAR-NEXT: loop: ; BAR: ; Exit blocks ; BAR: end: -; BAR-NOT: IR Dump Before +; BAR-NOT: IR Dump ; BAR-NOT: ; Loop +; FOO-MODULE: IR Dump After +; FOO-MODULE-SAME: Unroll +; FOO-MODULE-SAME: loop: %loop +; FOO-MODULE-NEXT: ModuleID = +; FOO-MODULE: define void @foo +; FOO-MODULE: define void @bar +; FOO-MODULE-NOT: IR Dump + define void @foo(){ %idx = alloca i32, align 4 store i32 0, i32* %idx, align 4