[llvm] r344014 - [CFG Printer] Add support for writing the dot files with a custom

Chandler Carruth via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 8 21:30:23 PDT 2018


Author: chandlerc
Date: Mon Oct  8 21:30:23 2018
New Revision: 344014

URL: http://llvm.org/viewvc/llvm-project?rev=344014&view=rev
Log:
[CFG Printer] Add support for writing the dot files with a custom
prefix.

Use this to direct these files to a specific location in the test suite
so that we don't write files out to random directories (or fail if the
working directory isn't writable).

Modified:
    llvm/trunk/lib/Analysis/CFGPrinter.cpp
    llvm/trunk/test/Other/cfg-printer-branch-weights.ll

Modified: llvm/trunk/lib/Analysis/CFGPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFGPrinter.cpp?rev=344014&r1=344013&r2=344014&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFGPrinter.cpp (original)
+++ llvm/trunk/lib/Analysis/CFGPrinter.cpp Mon Oct  8 21:30:23 2018
@@ -7,9 +7,10 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines a '-dot-cfg' analysis pass, which emits the
-// cfg.<fnname>.dot file for each function in the program, with a graph of the
-// CFG for that function.
+// This file defines a `-dot-cfg` analysis pass, which emits the
+// `<prefix>.<fnname>.dot` file for each function in the program, with a graph
+// of the CFG for that function. The default value for `<prefix>` is `cfg` but
+// can be customized as needed.
 //
 // The other main feature of this file is that it implements the
 // Function::viewCFG method, which is useful for debugging passes which operate
@@ -27,6 +28,10 @@ static cl::opt<std::string> CFGFuncName(
     cl::desc("The name of a function (or its substring)"
              " whose CFG is viewed/printed."));
 
+static cl::opt<std::string> CFGDotFilenamePrefix(
+    "cfg-dot-filename-prefix", cl::Hidden,
+    cl::desc("The prefix used for the CFG dot file names."));
+
 namespace {
   struct CFGViewerLegacyPass : public FunctionPass {
     static char ID; // Pass identifcation, replacement for typeid
@@ -90,7 +95,8 @@ PreservedAnalyses CFGOnlyViewerPass::run
 static void writeCFGToDotFile(Function &F, bool CFGOnly = false) {
   if (!CFGFuncName.empty() && !F.getName().contains(CFGFuncName))
      return;
-  std::string Filename = ("cfg." + F.getName() + ".dot").str();
+  std::string Filename =
+      (CFGDotFilenamePrefix + "." + F.getName() + ".dot").str();
   errs() << "Writing '" << Filename << "'...";
 
   std::error_code EC;

Modified: llvm/trunk/test/Other/cfg-printer-branch-weights.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/cfg-printer-branch-weights.ll?rev=344014&r1=344013&r2=344014&view=diff
==============================================================================
--- llvm/trunk/test/Other/cfg-printer-branch-weights.ll (original)
+++ llvm/trunk/test/Other/cfg-printer-branch-weights.ll Mon Oct  8 21:30:23 2018
@@ -1,5 +1,5 @@
-;RUN: opt < %s -analyze -dot-cfg 2>/dev/null
-;RUN: FileCheck %s -input-file=cfg.f.dot
+;RUN: opt < %s -analyze -dot-cfg -cfg-dot-filename-prefix=%t 2>/dev/null
+;RUN: FileCheck %s -input-file=%t.f.dot
 
 define void @f(i32) {
 entry:




More information about the llvm-commits mailing list