From 28552da9c3c8bc9865b9cff4fe64dad9da7a57a3 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 28 Jun 2007 23:09:25 +0000 Subject: [PATCH] Fix PR 1526. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37780 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Other/2007-06-28-PassManager.ll | 5 ++++ tools/opt/opt.cpp | 34 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/Other/2007-06-28-PassManager.ll diff --git a/test/Other/2007-06-28-PassManager.ll b/test/Other/2007-06-28-PassManager.ll new file mode 100644 index 00000000000..b0d83d0a0c6 --- /dev/null +++ b/test/Other/2007-06-28-PassManager.ll @@ -0,0 +1,5 @@ +; RUN: llvm-as < %s | opt -analyze -inline -disable-output +; PR 1526 +define i32 @test1() { + ret i32 0; +} diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 14e02d0e467..e6ff5ec4a25 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -14,10 +14,12 @@ #include "llvm/Module.h" #include "llvm/PassManager.h" +#include "llvm/CallGraphSCCPass.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Assembly/PrintModulePass.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/LoopPass.h" +#include "llvm/Analysis/CallGraph.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Support/PassNameParser.h" @@ -94,6 +96,36 @@ AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization")); // ---------- Define Printers for module and function passes ------------ namespace { +struct CallGraphSCCPassPrinter : public CallGraphSCCPass { + static char ID; + const PassInfo *PassToPrint; + CallGraphSCCPassPrinter(const PassInfo *PI) : + CallGraphSCCPass((intptr_t)&ID), PassToPrint(PI) {} + + virtual bool runOnSCC(const std::vector&SCC) { + if (!Quiet) { + cout << "Printing analysis '" << PassToPrint->getPassName() << "':\n"; + + for (unsigned i = 0, e = SCC.size(); i != e; ++i) { + Function *F = SCC[i]->getFunction(); + if (F) + getAnalysisID(PassToPrint).print(cout, F->getParent()); + } + } + // Get and print pass... + return false; + } + + virtual const char *getPassName() const { return "'Pass' Printer"; } + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequiredID(PassToPrint); + AU.setPreservesAll(); + } +}; + +char CallGraphSCCPassPrinter::ID = 0; + struct ModulePassPrinter : public ModulePass { static char ID; const PassInfo *PassToPrint; @@ -342,6 +374,8 @@ int main(int argc, char **argv) { Passes.add(new BasicBlockPassPrinter(PassInf)); else if (dynamic_cast(P)) Passes.add(new FunctionPassPrinter(PassInf)); + else if (dynamic_cast(P)) + Passes.add(new CallGraphSCCPassPrinter(PassInf)); else Passes.add(new ModulePassPrinter(PassInf)); } -- 2.34.1