From 7254d3c51c12ada02b1d75c5bfe22a7fdd87a120 Mon Sep 17 00:00:00 2001 From: Fedor Sergeev Date: Mon, 3 Dec 2018 14:48:15 +0000 Subject: [PATCH] Fixing -print-module-scope for legacy SCC passes It appears that print-module-scope was not implemented for legacy SCC passes. Fixed to print a whole module instead of just current SCC. Reviewed By: mkazantsev Differential Revision: https://reviews.llvm.org/D54793 llvm-svn: 348144 --- llvm/lib/Analysis/CallGraphSCCPass.cpp | 25 +++++++++++++++++++++---- llvm/test/Other/scc-pass-printer.ll | 7 +++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp index 80d0427..0aed57a 100644 --- a/llvm/lib/Analysis/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp @@ -633,23 +633,40 @@ namespace { bool runOnSCC(CallGraphSCC &SCC) override { bool BannerPrinted = false; - auto PrintBannerOnce = [&] () { + auto PrintBannerOnce = [&]() { if (BannerPrinted) return; OS << Banner; BannerPrinted = true; - }; + }; + + bool NeedModule = llvm::forcePrintModuleIR(); + if (isFunctionInPrintList("*") && NeedModule) { + PrintBannerOnce(); + OS << "\n"; + SCC.getCallGraph().getModule().print(OS, nullptr); + return false; + } + bool FoundFunction = false; for (CallGraphNode *CGN : SCC) { if (Function *F = CGN->getFunction()) { if (!F->isDeclaration() && isFunctionInPrintList(F->getName())) { - PrintBannerOnce(); - F->print(OS); + FoundFunction = true; + if (!NeedModule) { + PrintBannerOnce(); + F->print(OS); + } } } else if (isFunctionInPrintList("*")) { PrintBannerOnce(); OS << "\nPrinting Function\n"; } } + if (NeedModule && FoundFunction) { + PrintBannerOnce(); + OS << "\n"; + SCC.getCallGraph().getModule().print(OS, nullptr); + } return false; } diff --git a/llvm/test/Other/scc-pass-printer.ll b/llvm/test/Other/scc-pass-printer.ll index 9d86bf0..9e12a28 100644 --- a/llvm/test/Other/scc-pass-printer.ll +++ b/llvm/test/Other/scc-pass-printer.ll @@ -18,6 +18,8 @@ ; INL: IR Dump After ; INL-MOD: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .bar, foo}} +; INL-MOD-NEXT: ModuleID = +; INL-MOD-NEXT: source_filename = ; INL-MOD: define void @tester() ; INL-MOD-NEXT: call void @foo() ; INL-MOD: define void @foo() @@ -25,6 +27,8 @@ ; INL-MOD: define void @bar() ; INL-MOD-NEXT: call void @foo() ; INL-MOD: IR Dump After {{Function Integration/Inlining|InlinerPass .*scc: .tester}} +; INL-MOD-NEXT: ModuleID = +; INL-MOD-NEXT: source_filename = ; INL-MOD: define void @tester() ; INL-MOD-NEXT: call void @foo() ; INL-MOD: define void @foo() @@ -32,6 +36,9 @@ ; INL-MOD: define void @bar() ; INL-MOD-NEXT: call void @foo() ; INL-MOD: IR Dump After +; INL-MOD-NEXT: ModuleID = +; INL-MOD-NEXT: source_filename = +; INL-MOD-NOT: Printing Function define void @tester() noinline { call void @foo() -- 2.7.4