[PATCH] D49447: Add an option to specify function name when view/print CFG

David Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 13:17:56 PDT 2018


davidxl created this revision.
davidxl added a reviewer: eraman.

This is useful when a module contains large number of functions.


https://reviews.llvm.org/D49447

Files:
  lib/Analysis/CFGPrinter.cpp


Index: lib/Analysis/CFGPrinter.cpp
===================================================================
--- lib/Analysis/CFGPrinter.cpp
+++ lib/Analysis/CFGPrinter.cpp
@@ -22,6 +22,11 @@
 #include "llvm/Support/FileSystem.h"
 using namespace llvm;
 
+static cl::opt<std::string> CFGFuncName(
+    "cfg-func-name", cl::Hidden,
+    cl::desc("The option to specify the name (or a substring of)"
+             " of the function whose CFG is viewed/printed."));
+
 namespace {
   struct CFGViewerLegacyPass : public FunctionPass {
     static char ID; // Pass identifcation, replacement for typeid
@@ -83,6 +88,8 @@
 }
 
 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 @@
 /// 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 @@
 /// this can make the graph smaller.
 ///
 void Function::viewCFGOnly() const {
+  if (!CFGFuncName.empty() && !getName().contains(CFGFuncName))
+     return;
   ViewGraph(this, "cfg" + getName(), true);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49447.155953.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180717/c2b52cc1/attachment.bin>


More information about the llvm-commits mailing list