Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/SelectionDAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,9 @@ class SelectionDAG {

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

#if LLVM_ENABLE_ABI_BREAKING_CHECKS
Expand Down
29 changes: 18 additions & 11 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,21 @@ static cl::opt<bool>
ViewISelDAGs("view-isel-dags", cl::Hidden,
cl::desc("Pop up a window to show isel dags as they are selected"));
static cl::opt<bool>
ViewSchedDAGs("view-sched-dags", cl::Hidden,
cl::desc("Pop up a window to show sched dags as they are processed"));
WriteDAGsToFile("write-dags-to-file", cl::Hidden,
cl::desc("Write dags as they are selected to DOT files "
"instead of opening viewer"));
static cl::opt<bool> ViewSchedDAGs(
"view-sched-dags", cl::Hidden,
cl::desc("Pop up a window to show sched dags as they are processed"));
static cl::opt<bool>
ViewSUnitDAGs("view-sunit-dags", cl::Hidden,
cl::desc("Pop up a window to show SUnit dags after they are processed"));
#else
static const bool ViewDAGCombine1 = false, ViewLegalizeTypesDAGs = false,
ViewDAGCombineLT = false, ViewLegalizeDAGs = false,
ViewDAGCombine2 = false, ViewISelDAGs = false,
ViewSchedDAGs = false, ViewSUnitDAGs = false;
WriteDAGsToFile = false, ViewSchedDAGs = false,
ViewSUnitDAGs = false;
#endif

#ifndef NDEBUG
Expand Down Expand Up @@ -945,7 +950,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
#endif

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

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

bool Changed;
{
Expand All @@ -991,7 +996,8 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {

if (Changed) {
if (ViewDAGCombineLT && MatchFilterBB)
CurDAG->viewGraph("dag-combine-lt input for " + BlockName);
CurDAG->viewGraph("dag-combine-lt input for " + BlockName,
WriteDAGsToFile);

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

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

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

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

{
NamedRegionTimer T("legalize", "DAG Legalization", GroupName,
Expand All @@ -1085,7 +1092,7 @@ void SelectionDAGISel::CodeGenAndEmitDAG() {
#endif

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

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

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

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

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

// Schedule machine code.
ScheduleDAGSDNodes *Scheduler = CreateScheduler();
Expand Down
17 changes: 17 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ void SelectionDAG::viewGraph(const std::string &Title) {
#endif // NDEBUG
}

/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
/// rendered using 'dot' if not writing to file. Otherwise, just write it out.
///
void SelectionDAG::viewGraph(const std::string &Title, const bool WriteFile) {
// This code is only for debugging!
#ifndef NDEBUG
std::string GraphName = "dag." + getMachineFunction().getName().str();
if (WriteFile)
WriteGraph(this, Twine(GraphName), false, Title);
else
ViewGraph(this, Twine(GraphName), false, Title);
#else
errs() << "SelectionDAG::viewGraph is only available in debug builds on "
<< "systems with Graphviz or gv!\n";
#endif // NDEBUG
}

// This overload is defined out-of-line here instead of just using a
// default parameter because this is easiest for gdb to call.
void SelectionDAG::viewGraph() {
Expand Down