Index: include/llvm/Pass.h =================================================================== --- include/llvm/Pass.h +++ include/llvm/Pass.h @@ -369,6 +369,7 @@ /// @brief This is the storage for the -time-passes option. extern bool TimePassesIsEnabled; +extern bool isFunctionInPrintList(StringRef FunctionName); } // End llvm namespace // Include support files that contain important APIs commonly used by Passes, Index: lib/Analysis/CallGraphSCCPass.cpp =================================================================== --- lib/Analysis/CallGraphSCCPass.cpp +++ lib/Analysis/CallGraphSCCPass.cpp @@ -612,9 +612,10 @@ bool runOnSCC(CallGraphSCC &SCC) override { Out << Banner; for (CallGraphNode *CGN : SCC) { - if (CGN->getFunction()) - CGN->getFunction()->print(Out); - else + if (CGN->getFunction()) { + if (isFunctionInPrintList(CGN->getFunction()->getName())) + CGN->getFunction()->print(Out); + } else Out << "\nPrinting Function\n"; } return false; Index: lib/Analysis/LoopPass.cpp =================================================================== --- lib/Analysis/LoopPass.cpp +++ lib/Analysis/LoopPass.cpp @@ -42,7 +42,9 @@ } bool runOnLoop(Loop *L, LPPassManager &) override { - P.run(*L); + if (L->getHeader() && + isFunctionInPrintList(L->getHeader()->getParent()->getName())) + P.run(*L); return false; } }; Index: lib/CodeGen/MachineFunctionPrinterPass.cpp =================================================================== --- lib/CodeGen/MachineFunctionPrinterPass.cpp +++ lib/CodeGen/MachineFunctionPrinterPass.cpp @@ -31,7 +31,7 @@ const std::string Banner; MachineFunctionPrinterPass() : MachineFunctionPass(ID), OS(dbgs()) { } - MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) + MachineFunctionPrinterPass(raw_ostream &os, const std::string &banner) : MachineFunctionPass(ID), OS(os), Banner(banner) {} const char *getPassName() const override { return "MachineFunction Printer"; } @@ -42,8 +42,10 @@ } bool runOnMachineFunction(MachineFunction &MF) override { - OS << "# " << Banner << ":\n"; - MF.print(OS, getAnalysisIfAvailable()); + if (llvm::isFunctionInPrintList(MF.getName())) { + OS << "# " << Banner << ":\n"; + MF.print(OS, getAnalysisIfAvailable()); + } return false; } }; Index: lib/IR/IRPrintingPasses.cpp =================================================================== --- lib/IR/IRPrintingPasses.cpp +++ lib/IR/IRPrintingPasses.cpp @@ -27,8 +27,11 @@ ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {} PreservedAnalyses PrintModulePass::run(Module &M) { - OS << Banner; - M.print(OS, nullptr, ShouldPreserveUseListOrder); + if (llvm::isFunctionInPrintList("*")) { + OS << Banner << "\n"; + M.print(OS, nullptr, ShouldPreserveUseListOrder); + } else + OS << Banner << " (skipped printing)\n"; return PreservedAnalyses::all(); } @@ -37,7 +40,8 @@ : OS(OS), Banner(Banner) {} PreservedAnalyses PrintFunctionPass::run(Function &F) { - OS << Banner << static_cast(F); + if (isFunctionInPrintList(F.getName())) + OS << Banner << static_cast(F); return PreservedAnalyses::all(); } Index: lib/IR/LegacyPassManager.cpp =================================================================== --- lib/IR/LegacyPassManager.cpp +++ lib/IR/LegacyPassManager.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/raw_ostream.h" #include #include +#include using namespace llvm; using namespace llvm::legacy; @@ -83,6 +84,14 @@ llvm::cl::desc("Print IR after each pass"), cl::init(false)); +static cl::list + PrintFuncsList("print-funcs", cl::value_desc("function names"), + cl::desc("Print IR only for specified functions. Including " + "'*' prints module passes."), + cl::CommaSeparated); + +static std::set PrintFuncNames; + /// This is a helper to determine whether to print IR before or /// after a pass. @@ -109,6 +118,11 @@ return PrintAfterAll || ShouldPrintBeforeOrAfterPass(PI, PrintAfter); } +bool llvm::isFunctionInPrintList(StringRef FunctionName) { + if (PrintFuncNames.empty()) + return true; + return PrintFuncNames.count(FunctionName); +} /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// or higher is specified. bool PMDataManager::isPassDebuggingExecutionsOrMore() const { @@ -498,6 +512,7 @@ PMDM->setTopLevelManager(this); addPassManager(PMDM); activeStack.push(PMDM); + PrintFuncNames.insert(PrintFuncsList.begin(), PrintFuncsList.end()); } /// Set pass P as the last user of the given analysis passes.