diff options
author | Devang Patel <dpatel@apple.com> | 2007-06-28 23:09:25 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-06-28 23:09:25 +0000 |
commit | 28552da9c3c8bc9865b9cff4fe64dad9da7a57a3 (patch) | |
tree | a03f2f65c9055412be117878cc68a847e7399ca0 /tools/opt | |
parent | 8b42bcdd1ad6f3f908d062b189fbc2a6449fae83 (diff) | |
download | external_llvm-28552da9c3c8bc9865b9cff4fe64dad9da7a57a3.zip external_llvm-28552da9c3c8bc9865b9cff4fe64dad9da7a57a3.tar.gz external_llvm-28552da9c3c8bc9865b9cff4fe64dad9da7a57a3.tar.bz2 |
Fix PR 1526.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/opt')
-rw-r--r-- | tools/opt/opt.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 14e02d0..e6ff5ec 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<CallGraphNode *>&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<Pass>(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<FunctionPass*>(P)) Passes.add(new FunctionPassPrinter(PassInf)); + else if (dynamic_cast<CallGraphSCCPass*>(P)) + Passes.add(new CallGraphSCCPassPrinter(PassInf)); else Passes.add(new ModulePassPrinter(PassInf)); } |