Skip to content

Commit

Permalink
[CFG Printer] Add support for writing the dot files with a custom
Browse files Browse the repository at this point in the history
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).

llvm-svn: 344014
  • Loading branch information
chandlerc committed Oct 9, 2018
1 parent f96e618 commit d46f580
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions llvm/lib/Analysis/CFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -90,7 +95,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();
std::string Filename =
(CFGDotFilenamePrefix + "." + F.getName() + ".dot").str();
errs() << "Writing '" << Filename << "'...";

std::error_code EC;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Other/cfg-printer-branch-weights.ll
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit d46f580

Please sign in to comment.