Skip to content

Commit baaa051

Browse files
committed
[SelectionDAG] add a cli option that will only write DAG vizualization to file instead of opening the viewer
1 parent 9bfbff2 commit baaa051

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ class SelectionDAG {
530530

531531
/// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
532532
LLVM_ABI void viewGraph(const std::string &Title);
533+
/// Pop up a GraphViz/gv window with the DAG rendered using 'dot', or write
534+
/// the file out instead.
535+
LLVM_ABI void viewGraph(const std::string &Title, const bool WriteFile);
533536
LLVM_ABI void viewGraph();
534537

535538
#if LLVM_ENABLE_ABI_BREAKING_CHECKS

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,21 @@ static cl::opt<bool>
175175
ViewISelDAGs("view-isel-dags", cl::Hidden,
176176
cl::desc("Pop up a window to show isel dags as they are selected"));
177177
static cl::opt<bool>
178-
ViewSchedDAGs("view-sched-dags", cl::Hidden,
179-
cl::desc("Pop up a window to show sched dags as they are processed"));
178+
WriteDAGsToFile("write-dags-to-file", cl::Hidden,
179+
cl::desc("Write dags as they are selected to DOT files "
180+
"instead of opening viewer"));
181+
static cl::opt<bool> ViewSchedDAGs(
182+
"view-sched-dags", cl::Hidden,
183+
cl::desc("Pop up a window to show sched dags as they are processed"));
180184
static cl::opt<bool>
181185
ViewSUnitDAGs("view-sunit-dags", cl::Hidden,
182186
cl::desc("Pop up a window to show SUnit dags after they are processed"));
183187
#else
184188
static const bool ViewDAGCombine1 = false, ViewLegalizeTypesDAGs = false,
185189
ViewDAGCombineLT = false, ViewLegalizeDAGs = false,
186190
ViewDAGCombine2 = false, ViewISelDAGs = false,
187-
ViewSchedDAGs = false, ViewSUnitDAGs = false;
191+
WriteDAGsToFile = false, ViewSchedDAGs = false,
192+
ViewSUnitDAGs = false;
188193
#endif
189194

190195
#ifndef NDEBUG
@@ -945,7 +950,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
945950
#endif
946951

947952
if (ViewDAGCombine1 && MatchFilterBB)
948-
CurDAG->viewGraph("dag-combine1 input for " + BlockName);
953+
CurDAG->viewGraph("dag-combine1 input for " + BlockName, WriteDAGsToFile);
949954

950955
// Run the DAG combiner in pre-legalize mode.
951956
{
@@ -967,7 +972,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
967972
// Second step, hack on the DAG until it only uses operations and types that
968973
// the target supports.
969974
if (ViewLegalizeTypesDAGs && MatchFilterBB)
970-
CurDAG->viewGraph("legalize-types input for " + BlockName);
975+
CurDAG->viewGraph("legalize-types input for " + BlockName, WriteDAGsToFile);
971976

972977
bool Changed;
973978
{
@@ -991,7 +996,8 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
991996

992997
if (Changed) {
993998
if (ViewDAGCombineLT && MatchFilterBB)
994-
CurDAG->viewGraph("dag-combine-lt input for " + BlockName);
999+
CurDAG->viewGraph("dag-combine-lt input for " + BlockName,
1000+
WriteDAGsToFile);
9951001

9961002
// Run the DAG combiner in post-type-legalize mode.
9971003
{
@@ -1045,7 +1051,8 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
10451051
#endif
10461052

10471053
if (ViewDAGCombineLT && MatchFilterBB)
1048-
CurDAG->viewGraph("dag-combine-lv input for " + BlockName);
1054+
CurDAG->viewGraph("dag-combine-lv input for " + BlockName,
1055+
WriteDAGsToFile);
10491056

10501057
// Run the DAG combiner in post-type-legalize mode.
10511058
{
@@ -1066,7 +1073,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
10661073
}
10671074

10681075
if (ViewLegalizeDAGs && MatchFilterBB)
1069-
CurDAG->viewGraph("legalize input for " + BlockName);
1076+
CurDAG->viewGraph("legalize input for " + BlockName, WriteDAGsToFile);
10701077

10711078
{
10721079
NamedRegionTimer T("legalize", "DAG Legalization", GroupName,
@@ -1085,7 +1092,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
10851092
#endif
10861093

10871094
if (ViewDAGCombine2 && MatchFilterBB)
1088-
CurDAG->viewGraph("dag-combine2 input for " + BlockName);
1095+
CurDAG->viewGraph("dag-combine2 input for " + BlockName, WriteDAGsToFile);
10891096

10901097
// Run the DAG combiner in post-legalize mode.
10911098
{
@@ -1108,7 +1115,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
11081115
ComputeLiveOutVRegInfo();
11091116

11101117
if (ViewISelDAGs && MatchFilterBB)
1111-
CurDAG->viewGraph("isel input for " + BlockName);
1118+
CurDAG->viewGraph("isel input for " + BlockName, WriteDAGsToFile);
11121119

11131120
// Third, instruction select all of the operations to machine code, adding the
11141121
// code to the MachineBasicBlock.
@@ -1124,7 +1131,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
11241131
CurDAG->dump(DumpSortedDAG));
11251132

11261133
if (ViewSchedDAGs && MatchFilterBB)
1127-
CurDAG->viewGraph("scheduler input for " + BlockName);
1134+
CurDAG->viewGraph("scheduler input for " + BlockName, WriteDAGsToFile);
11281135

11291136
// Schedule machine code.
11301137
ScheduleDAGSDNodes *Scheduler = CreateScheduler();

llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ void SelectionDAG::viewGraph(const std::string &Title) {
154154
#endif // NDEBUG
155155
}
156156

157+
/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
158+
/// rendered using 'dot' if not writing to file. Otherwise, just write it out.
159+
///
160+
void SelectionDAG::viewGraph(const std::string &Title, const bool WriteFile) {
161+
// This code is only for debugging!
162+
#ifndef NDEBUG
163+
std::string GraphName = "dag." + getMachineFunction().getName().str();
164+
if (WriteFile)
165+
WriteGraph(this, Twine(GraphName), false, Title);
166+
else
167+
ViewGraph(this, Twine(GraphName), false, Title);
168+
#else
169+
errs() << "SelectionDAG::viewGraph is only available in debug builds on "
170+
<< "systems with Graphviz or gv!\n";
171+
#endif // NDEBUG
172+
}
173+
157174
// This overload is defined out-of-line here instead of just using a
158175
// default parameter because this is easiest for gdb to call.
159176
void SelectionDAG::viewGraph() {

0 commit comments

Comments
 (0)