From: Xinliang David Li Date: Wed, 25 Jul 2018 17:22:12 +0000 (+0000) Subject: Add an option to specify the name of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8544cc867df0c8fcd291db03f3ac36902176a1b4;p=llvm Add an option to specify the name of an function whose CFG is to be viewed/printed. Differential Revision: https://reviews.llvm.org/D49447 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337940 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFGPrinter.cpp b/lib/Analysis/CFGPrinter.cpp index fb261755e5d..fc25cef8ddc 100644 --- a/lib/Analysis/CFGPrinter.cpp +++ b/lib/Analysis/CFGPrinter.cpp @@ -22,6 +22,11 @@ #include "llvm/Support/FileSystem.h" using namespace llvm; +static cl::opt CFGFuncName( + "cfg-func-name", cl::Hidden, + cl::desc("The name of a function (or its substring)" + " whose CFG is viewed/printed.")); + namespace { struct CFGViewerLegacyPass : public FunctionPass { static char ID; // Pass identifcation, replacement for typeid @@ -83,6 +88,8 @@ PreservedAnalyses CFGOnlyViewerPass::run(Function &F, } static void writeCFGToDotFile(Function &F, bool CFGOnly = false) { + if (!CFGFuncName.empty() && !F.getName().contains(CFGFuncName)) + return; std::string Filename = ("cfg." + F.getName() + ".dot").str(); errs() << "Writing '" << Filename << "'..."; @@ -162,6 +169,8 @@ PreservedAnalyses CFGOnlyPrinterPass::run(Function &F, /// being a 'dot' and 'gv' program in your path. /// void Function::viewCFG() const { + if (!CFGFuncName.empty() && !getName().contains(CFGFuncName)) + return; ViewGraph(this, "cfg" + getName()); } @@ -171,6 +180,8 @@ void Function::viewCFG() const { /// this can make the graph smaller. /// void Function::viewCFGOnly() const { + if (!CFGFuncName.empty() && !getName().contains(CFGFuncName)) + return; ViewGraph(this, "cfg" + getName(), true); }