[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-30 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

In D90159#2466599 , @MaskRay wrote:

> Should this have some tests? Even if guarded by `REQUIRES:` if some feature 
> is needed.

Test coverage for the DDG functionality has been added under LIT and unittests. 
I've opened https://reviews.llvm.org/D93949 to add a test and verify the 
formatting of the dot file produced when using `-dot-ddg`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Should this have some tests? Even if guarded by `REQUIRES:` if some feature is 
needed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-16 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

In D90159#2454905 , @bmahjour wrote:

> In D90159#2453805 , @Meinersbur 
> wrote:
>
>> Can I help fixing the Windows build problem?
>
> I think I have a fix (please see the updated patch), but don't have access to 
> a windows machine to verify. Would you be able to try building with MSVC and 
> let me know if it passes?

I'll try to recommit and watch the windows buildbots.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-15 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour updated this revision to Diff 311897.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  llvm/include/llvm/Analysis/CFGPrinter.h
  llvm/include/llvm/Analysis/DDG.h
  llvm/include/llvm/Analysis/DDGPrinter.h
  llvm/include/llvm/Support/DOTGraphTraits.h
  llvm/include/llvm/Support/GraphWriter.h
  llvm/lib/Analysis/CFGPrinter.cpp
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/CallPrinter.cpp
  llvm/lib/Analysis/DDGPrinter.cpp
  llvm/lib/CodeGen/MachineScheduler.cpp
  llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def

Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -384,6 +384,7 @@
 #define LOOP_PASS(NAME, CREATE_PASS)
 #endif
 LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass())
+LOOP_PASS("dot-ddg", DDGDotPrinterPass())
 LOOP_PASS("invalidate", InvalidateAllAnalysesPass())
 LOOP_PASS("licm", LICMPass())
 LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/DDG.h"
+#include "llvm/Analysis/DDGPrinter.h"
 #include "llvm/Analysis/Delinearization.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
Index: llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
===
--- llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
+++ llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
@@ -35,7 +35,7 @@
   return true;
 }
 
-static bool isNodeHidden(const SUnit *Node) {
+static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
   return (Node->NumPreds > 10 || Node->NumSuccs > 10);
 }
 
Index: llvm/lib/CodeGen/MachineScheduler.cpp
===
--- llvm/lib/CodeGen/MachineScheduler.cpp
+++ llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3836,7 +3836,7 @@
 return true;
   }
 
-  static bool isNodeHidden(const SUnit *Node) {
+  static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
 if (ViewMISchedCutoff == 0)
   return false;
 return (Node->Preds.size() > ViewMISchedCutoff
Index: llvm/lib/Analysis/DDGPrinter.cpp
===
--- /dev/null
+++ llvm/lib/Analysis/DDGPrinter.cpp
@@ -0,0 +1,150 @@
+//===- DDGPrinter.cpp - DOT printer for the data dependence graph --==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+//
+// This file defines the `-dot-ddg` analysis pass, which emits DDG in DOT format
+// in a file named `ddg..dot` for each loop  in a function.
+//===--===//
+
+#include "llvm/Analysis/DDGPrinter.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/GraphWriter.h"
+
+using namespace llvm;
+
+static cl::opt DotOnly("dot-ddg-only", cl::init(false), cl::Hidden,
+ cl::ZeroOrMore, cl::desc("simple ddg dot graph"));
+static cl::opt DDGDotFilenamePrefix(
+"dot-ddg-filename-prefix", cl::init("ddg"), cl::Hidden,
+cl::desc("The prefix used for the DDG dot file names."));
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly = false);
+
+//======//
+// Implementation of DDG DOT Printer for a loop
+//======//
+PreservedAnalyses DDGDotPrinterPass::run(Loop , LoopAnalysisManager ,
+ LoopStandardAnalysisResults ,
+ LPMUpdater ) {
+  writeDDGToDotFile(*AM.getResult(L, AR), DotOnly);
+  return PreservedAnalyses::all();
+}
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly) {
+  std::string Filename =
+  Twine(DDGDotFilenamePrefix + "." + G.getName() + ".dot").str();
+  errs() << "Writing '" << Filename << "'...";
+
+  std::error_code EC;
+  raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
+
+  if (!EC)
+// We only provide the constant verson of the DOTGraphTrait specialization,
+// hence the conversion to const pointer
+WriteGraph(File, (const 

[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-15 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added a comment.

In D90159#2453805 , @Meinersbur wrote:

> Can I help fixing the Windows build problem?

I think I have a fix (please see the updated patch), but don't have access to a 
windows machine to verify. Would you be able to try building with MSVC and let 
me know if it passes?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-14 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur added a comment.

Can I help fixing the Windows build problem?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-14 Thread Bardia Mahjour via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfd4a10732c8b: [DDG] Data Dependence Graph - DOT printer 
(authored by bmahjour).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  llvm/include/llvm/Analysis/CFGPrinter.h
  llvm/include/llvm/Analysis/DDG.h
  llvm/include/llvm/Analysis/DDGPrinter.h
  llvm/include/llvm/Support/DOTGraphTraits.h
  llvm/include/llvm/Support/GraphWriter.h
  llvm/lib/Analysis/CFGPrinter.cpp
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/CallPrinter.cpp
  llvm/lib/Analysis/DDGPrinter.cpp
  llvm/lib/CodeGen/MachineScheduler.cpp
  llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def

Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -384,6 +384,7 @@
 #define LOOP_PASS(NAME, CREATE_PASS)
 #endif
 LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass())
+LOOP_PASS("dot-ddg", DDGDotPrinterPass())
 LOOP_PASS("invalidate", InvalidateAllAnalysesPass())
 LOOP_PASS("licm", LICMPass())
 LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/DDG.h"
+#include "llvm/Analysis/DDGPrinter.h"
 #include "llvm/Analysis/Delinearization.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
Index: llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
===
--- llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
+++ llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
@@ -35,7 +35,7 @@
   return true;
 }
 
-static bool isNodeHidden(const SUnit *Node) {
+static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
   return (Node->NumPreds > 10 || Node->NumSuccs > 10);
 }
 
Index: llvm/lib/CodeGen/MachineScheduler.cpp
===
--- llvm/lib/CodeGen/MachineScheduler.cpp
+++ llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3836,7 +3836,7 @@
 return true;
   }
 
-  static bool isNodeHidden(const SUnit *Node) {
+  static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
 if (ViewMISchedCutoff == 0)
   return false;
 return (Node->Preds.size() > ViewMISchedCutoff
Index: llvm/lib/Analysis/DDGPrinter.cpp
===
--- /dev/null
+++ llvm/lib/Analysis/DDGPrinter.cpp
@@ -0,0 +1,150 @@
+//===- DDGPrinter.cpp - DOT printer for the data dependence graph --==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+//
+// This file defines the `-dot-ddg` analysis pass, which emits DDG in DOT format
+// in a file named `ddg..dot` for each loop  in a function.
+//===--===//
+
+#include "llvm/Analysis/DDGPrinter.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/GraphWriter.h"
+
+using namespace llvm;
+
+static cl::opt DotOnly("dot-ddg-only", cl::init(false), cl::Hidden,
+ cl::ZeroOrMore, cl::desc("simple ddg dot graph"));
+static cl::opt DDGDotFilenamePrefix(
+"dot-ddg-filename-prefix", cl::init("ddg"), cl::Hidden,
+cl::desc("The prefix used for the DDG dot file names."));
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly = false);
+
+//======//
+// Implementation of DDG DOT Printer for a loop
+//======//
+PreservedAnalyses DDGDotPrinterPass::run(Loop , LoopAnalysisManager ,
+ LoopStandardAnalysisResults ,
+ LPMUpdater ) {
+  writeDDGToDotFile(*AM.getResult(L, AR), DotOnly);
+  return PreservedAnalyses::all();
+}
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly) {
+  std::string Filename =
+  Twine(DDGDotFilenamePrefix + "." + G.getName() + ".dot").str();
+  errs() << "Writing '" << Filename << "'...";
+
+  std::error_code EC;
+  raw_fd_ostream File(Filename, EC, 

[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-14 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur accepted this revision.
Meinersbur added a comment.

Thanks. Still LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-14 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour updated this revision to Diff 311678.
bmahjour added a comment.

fix formatting and use interleaveComma instead of interleave.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  llvm/include/llvm/Analysis/CFGPrinter.h
  llvm/include/llvm/Analysis/DDG.h
  llvm/include/llvm/Analysis/DDGPrinter.h
  llvm/include/llvm/Support/DOTGraphTraits.h
  llvm/include/llvm/Support/GraphWriter.h
  llvm/lib/Analysis/CFGPrinter.cpp
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/CallPrinter.cpp
  llvm/lib/Analysis/DDGPrinter.cpp
  llvm/lib/CodeGen/MachineScheduler.cpp
  llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def

Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -384,6 +384,7 @@
 #define LOOP_PASS(NAME, CREATE_PASS)
 #endif
 LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass())
+LOOP_PASS("dot-ddg", DDGDotPrinterPass())
 LOOP_PASS("invalidate", InvalidateAllAnalysesPass())
 LOOP_PASS("licm", LICMPass())
 LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/DDG.h"
+#include "llvm/Analysis/DDGPrinter.h"
 #include "llvm/Analysis/Delinearization.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
Index: llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
===
--- llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
+++ llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
@@ -35,7 +35,7 @@
   return true;
 }
 
-static bool isNodeHidden(const SUnit *Node) {
+static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
   return (Node->NumPreds > 10 || Node->NumSuccs > 10);
 }
 
Index: llvm/lib/CodeGen/MachineScheduler.cpp
===
--- llvm/lib/CodeGen/MachineScheduler.cpp
+++ llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3836,7 +3836,7 @@
 return true;
   }
 
-  static bool isNodeHidden(const SUnit *Node) {
+  static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
 if (ViewMISchedCutoff == 0)
   return false;
 return (Node->Preds.size() > ViewMISchedCutoff
Index: llvm/lib/Analysis/DDGPrinter.cpp
===
--- /dev/null
+++ llvm/lib/Analysis/DDGPrinter.cpp
@@ -0,0 +1,150 @@
+//===- DDGPrinter.cpp - DOT printer for the data dependence graph --==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+//
+// This file defines the `-dot-ddg` analysis pass, which emits DDG in DOT format
+// in a file named `ddg..dot` for each loop  in a function.
+//===--===//
+
+#include "llvm/Analysis/DDGPrinter.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/GraphWriter.h"
+
+using namespace llvm;
+
+static cl::opt DotOnly("dot-ddg-only", cl::init(false), cl::Hidden,
+ cl::ZeroOrMore, cl::desc("simple ddg dot graph"));
+static cl::opt DDGDotFilenamePrefix(
+"dot-ddg-filename-prefix", cl::init("ddg"), cl::Hidden,
+cl::desc("The prefix used for the DDG dot file names."));
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly = false);
+
+//======//
+// Implementation of DDG DOT Printer for a loop
+//======//
+PreservedAnalyses DDGDotPrinterPass::run(Loop , LoopAnalysisManager ,
+ LoopStandardAnalysisResults ,
+ LPMUpdater ) {
+  writeDDGToDotFile(*AM.getResult(L, AR), DotOnly);
+  return PreservedAnalyses::all();
+}
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly) {
+  std::string Filename =
+  Twine(DDGDotFilenamePrefix + "." + G.getName() + ".dot").str();
+  errs() << "Writing '" << Filename << "'...";
+
+  std::error_code EC;
+  raw_fd_ostream File(Filename, EC, sys::fs::F_Text);
+
+  if (!EC)
+// We only provide the constant verson of the DOTGraphTrait 

[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-09 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur accepted this revision.
Meinersbur added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM.




Comment at: llvm/include/llvm/Analysis/DDG.h:489
+  },
+  [&] { OS << ", "; });
+  return OS.str();

`llvm::interleaveComma` does that without an additional lambda.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-09 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour added inline comments.



Comment at: llvm/include/llvm/Analysis/DDG.h:480
+return OS.str();
+  unsigned count = 0;
+  for (auto  : Deps) {

Meinersbur wrote:
> [suggestion] Instead of count, you can use `llvm::enumerate`. I think it's 
> nicer to check at for "not the first" at the beginning instead of the last 
> element at the end.
> 
> There also is an `interleave` function in STLExtras.h for uses cases like 
> this.
Interesting! Thanks for pointing out those utilities! I'll use interleave.



Comment at: llvm/include/llvm/Analysis/DDGPrinter.h:45
+assert(G && "expected a valid pointer to the graph.");
+Graph = G;
+return "DDG for '" + std::string(G->getName()) + "'";

Meinersbur wrote:
> Why does a getter set a field value?
Good question :)

When printing pi-blocks we would like to show the member nodes being enclosed 
by the pi-node. However, since the member nodes are also part of the graph, 
they will get visited during the walk and get dumped into the resulting dot 
file. To solve this, I'm trying to hide the member nodes from the walk (via 
`isNodeHidden()`) when they get visited and then print them as part of printing 
the pi-block node. 

The problem I encountered was that, `isNodeHidden()` only takes a graph node as 
a parameter, but for me to know whether a node belongs to a pi-block I need to 
get access to the graph that contains the nodes. To get around this, I'm 
caching a pointer to the graph when the `getGraphName` gets called and use it 
when `isNodeHidden` is invokedyikes!

A cleaner solution (and one that may have other uses in the future) is to make 
`isNodeHidden()` take a graph object as argument (similar to `getNodeLabel()`, 
and `getGraphName()`). I'll update the patch to include that change.



Comment at: llvm/lib/Analysis/DDGPrinter.cpp:109
+  if (isa(Node))
+for (auto *II : static_cast(Node)->getInstructions())
+  OS << *II << "\n";

Meinersbur wrote:
> Does this const_cast exist to add const qualifier?
No. The static_cast is used because the `getInstructions()` is a member 
function of `SimpleDDGNode` but not `DDGNode`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D90159: [DDG] Data Dependence Graph - DOT printer

2020-12-09 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour updated this revision to Diff 310607.
bmahjour marked 5 inline comments as done.
bmahjour added a comment.
Herald added subscribers: cfe-commits, dexonsmith, ecnelises, martong, 
javed.absar, MatzeB.
Herald added a project: clang.

Thanks for the review @Meinersbur and sorry for taking so long to address your 
comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90159/new/

https://reviews.llvm.org/D90159

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  llvm/include/llvm/Analysis/CFGPrinter.h
  llvm/include/llvm/Analysis/DDG.h
  llvm/include/llvm/Analysis/DDGPrinter.h
  llvm/include/llvm/Support/DOTGraphTraits.h
  llvm/include/llvm/Support/GraphWriter.h
  llvm/lib/Analysis/CFGPrinter.cpp
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/CallPrinter.cpp
  llvm/lib/Analysis/DDGPrinter.cpp
  llvm/lib/CodeGen/MachineScheduler.cpp
  llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def

Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -384,6 +384,7 @@
 #define LOOP_PASS(NAME, CREATE_PASS)
 #endif
 LOOP_PASS("canon-freeze", CanonicalizeFreezeInLoopsPass())
+LOOP_PASS("dot-ddg", DDGDotPrinterPass())
 LOOP_PASS("invalidate", InvalidateAllAnalysesPass())
 LOOP_PASS("licm", LICMPass())
 LOOP_PASS("loop-idiom", LoopIdiomRecognizePass())
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Analysis/DDG.h"
+#include "llvm/Analysis/DDGPrinter.h"
 #include "llvm/Analysis/Delinearization.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/DependenceAnalysis.h"
Index: llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
===
--- llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
+++ llvm/lib/CodeGen/ScheduleDAGPrinter.cpp
@@ -35,7 +35,7 @@
   return true;
 }
 
-static bool isNodeHidden(const SUnit *Node) {
+static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
   return (Node->NumPreds > 10 || Node->NumSuccs > 10);
 }
 
Index: llvm/lib/CodeGen/MachineScheduler.cpp
===
--- llvm/lib/CodeGen/MachineScheduler.cpp
+++ llvm/lib/CodeGen/MachineScheduler.cpp
@@ -3836,7 +3836,7 @@
 return true;
   }
 
-  static bool isNodeHidden(const SUnit *Node) {
+  static bool isNodeHidden(const SUnit *Node, const ScheduleDAG *G) {
 if (ViewMISchedCutoff == 0)
   return false;
 return (Node->Preds.size() > ViewMISchedCutoff
Index: llvm/lib/Analysis/DDGPrinter.cpp
===
--- /dev/null
+++ llvm/lib/Analysis/DDGPrinter.cpp
@@ -0,0 +1,150 @@
+//===- DDGPrinter.cpp - DOT printer for the data dependence graph --==//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+//
+// This file defines the `-dot-ddg` analysis pass, which emits DDG in DOT format
+// in a file named `ddg..dot` for each loop  in a function.
+//===--===//
+
+#include "llvm/Analysis/DDGPrinter.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/GraphWriter.h"
+
+using namespace llvm;
+
+static cl::opt DotOnly("dot-ddg-only", cl::init(false), cl::Hidden,
+ cl::ZeroOrMore, cl::desc("simple ddg dot graph"));
+static cl::opt DDGDotFilenamePrefix(
+"dot-ddg-filename-prefix", cl::init("ddg"), cl::Hidden,
+cl::desc("The prefix used for the DDG dot file names."));
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly = false);
+
+//======//
+// Implementation of DDG DOT Printer for a loop
+//======//
+PreservedAnalyses DDGDotPrinterPass::run(Loop , LoopAnalysisManager ,
+ LoopStandardAnalysisResults ,
+ LPMUpdater ) {
+  writeDDGToDotFile(*AM.getResult(L, AR), DotOnly);
+  return PreservedAnalyses::all();
+}
+
+static void writeDDGToDotFile(DataDependenceGraph , bool DOnly) {
+  std::string Filename =
+  Twine(DDGDotFilenamePrefix + "." + G.getName() + ".dot").str();
+  errs() << "Writing