Index: lib/Analysis/IPA/CallGraphSCCPass.cpp =================================================================== --- lib/Analysis/IPA/CallGraphSCCPass.cpp +++ lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -31,11 +31,12 @@ #define DEBUG_TYPE "cgscc-passmgr" -static cl::opt -MaxIterations("max-cg-scc-iterations", cl::ReallyHidden, cl::init(4)); +static cl::opt MaxIterations("max-cg-scc-iterations", + cl::ReallyHidden, cl::init(4)); STATISTIC(MaxSCCIterations, "Maximum CGSCCPassMgr iterations on one SCC"); +extern llvm::cl::opt DumpFunction; //===----------------------------------------------------------------------===// // CGPassManager // @@ -597,7 +598,7 @@ class PrintCallGraphPass : public CallGraphSCCPass { std::string Banner; raw_ostream &Out; // raw_ostream to print on. - + public: static char ID; PrintCallGraphPass(const std::string &B, raw_ostream &o) @@ -608,17 +609,25 @@ } bool runOnSCC(CallGraphSCC &SCC) override { - Out << Banner; + bool PrintedBanner = false; + for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) { - if ((*I)->getFunction()) - (*I)->getFunction()->print(Out); - else + if ((*I)->getFunction()) { + if (DumpFunction.empty() || + DumpFunction.data() == (*I)->getFunction()->getName()) { + if (!PrintedBanner) { + PrintedBanner = true; + Out << Banner; + } + (*I)->getFunction()->print(Out); + } + } else Out << "\nPrinting Function\n"; } return false; } }; - + } // end anonymous namespace. char PrintCallGraphPass::ID = 0; Index: lib/Analysis/LoopPass.cpp =================================================================== --- lib/Analysis/LoopPass.cpp +++ lib/Analysis/LoopPass.cpp @@ -22,6 +22,8 @@ #define DEBUG_TYPE "loop-pass-manager" +extern llvm::cl::opt DumpFunction; + namespace { /// PrintLoopPass - Print a Function corresponding to a Loop. @@ -41,13 +43,20 @@ } bool runOnLoop(Loop *L, LPPassManager &) override { - Out << Banner; + bool PrintedBanner = false; for (Loop::block_iterator b = L->block_begin(), be = L->block_end(); b != be; ++b) { - if (*b) - (*b)->print(Out); - else + if (*b) { + if (DumpFunction.empty() || + DumpFunction.data() == (*b)->getParent()->getName()) { + if (!PrintedBanner) { + PrintedBanner = true; + Out << Banner; + } + (*b)->print(Out); + } + } else Out << "Printing block"; } return false; Index: lib/CodeGen/MachineFunction.cpp =================================================================== --- lib/CodeGen/MachineFunction.cpp +++ lib/CodeGen/MachineFunction.cpp @@ -30,6 +30,7 @@ #include "llvm/IR/Function.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/raw_ostream.h" @@ -38,6 +39,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetSubtargetInfo.h" using namespace llvm; +extern llvm::cl::opt MDumpFunction; #define DEBUG_TYPE "codegen" @@ -336,6 +338,8 @@ void MachineFunction::print(raw_ostream &OS, SlotIndexes *Indexes) const { OS << "# Machine code for function " << getName() << ": "; + if (!MDumpFunction.empty() && MDumpFunction.data() != getName()) + return; if (RegInfo) { OS << (RegInfo->isSSA() ? "SSA" : "Post SSA"); if (!RegInfo->tracksLiveness()) Index: lib/CodeGen/MachineFunctionPrinterPass.cpp =================================================================== --- lib/CodeGen/MachineFunctionPrinterPass.cpp +++ lib/CodeGen/MachineFunctionPrinterPass.cpp @@ -15,10 +15,14 @@ #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/SlotIndexes.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; +cl::opt MDumpFunction("mdump-function", cl::init(""), + cl::value_desc("function names"), + cl::desc("Dump IR for the function only")); namespace { /// MachineFunctionPrinterPass - This is a pass to dump the IR of a @@ -42,8 +46,10 @@ } bool runOnMachineFunction(MachineFunction &MF) override { - OS << "# " << Banner << ":\n"; - MF.print(OS, getAnalysisIfAvailable()); + if (MDumpFunction.empty() || MDumpFunction.data() == MF.getName()) { + OS << "# " << Banner << ":\n"; + MF.print(OS, getAnalysisIfAvailable()); + } return false; } }; Index: lib/IR/IRPrintingPasses.cpp =================================================================== --- lib/IR/IRPrintingPasses.cpp +++ lib/IR/IRPrintingPasses.cpp @@ -12,14 +12,20 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/IRPrintingPasses.h" +//#include "llvm/IR/IRPrintOptions.h" #include "llvm/IR/Function.h" #include "llvm/IR/Module.h" #include "llvm/IR/PassManager.h" #include "llvm/Pass.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; +cl::opt DumpFunction("dump-function", cl::init(""), + cl::value_desc("function names"), + cl::desc("Dump IR for the function only")); + PrintModulePass::PrintModulePass() : OS(dbgs()) {} PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner) : OS(OS), Banner(Banner) {} @@ -50,7 +56,8 @@ : ModulePass(ID), P(OS, Banner) {} bool runOnModule(Module &M) override { - P.run(&M); + if (DumpFunction.empty()) + P.run(&M); return false; } @@ -70,7 +77,8 @@ // This pass just prints a banner followed by the function as it's processed. bool runOnFunction(Function &F) override { - P.run(&F); + if (DumpFunction.empty() || DumpFunction.data() == F.getName()) + P.run(&F); return false; } @@ -90,7 +98,9 @@ : BasicBlockPass(ID), Out(Out), Banner(Banner) {} bool runOnBasicBlock(BasicBlock &BB) override { - Out << Banner << BB; + if (DumpFunction.empty() || + DumpFunction.data() == BB.getParent()->getName()) + Out << Banner << BB; return false; }