Index: lib/Analysis/LoopInfo.cpp =================================================================== --- lib/Analysis/LoopInfo.cpp +++ lib/Analysis/LoopInfo.cpp @@ -731,6 +731,18 @@ } 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(); Index: test/Other/loop-pass-printer.ll =================================================================== --- test/Other/loop-pass-printer.ll +++ 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