From 7d1cd3f21d68179f4ebf4ee18fb7a0ddca9c5a37 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 19 Nov 2008 22:09:45 +0000 Subject: [PATCH] Move the code for printing a graph node label for an SUnit into a virtual method of SelectionDAG. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59667 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/ScheduleDAG.h | 4 ++ lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 2 +- .../SelectionDAG/SelectionDAGPrinter.cpp | 43 +++++++++---------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/llvm/CodeGen/ScheduleDAG.h b/include/llvm/CodeGen/ScheduleDAG.h index 8172a15fb4d..49dabe67580 100644 --- a/include/llvm/CodeGen/ScheduleDAG.h +++ b/include/llvm/CodeGen/ScheduleDAG.h @@ -396,6 +396,10 @@ namespace llvm { /// virtual void Schedule() = 0; + /// getGraphpNodeLabel - Return a label for an SUnit node in a Graphviz or similar + /// graph visualization. + virtual std::string getGraphNodeLabel(const SUnit *SU) const; + private: /// EmitSubregNode - Generate machine code for subreg nodes. /// diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index b63c3c1cf10..c2e21752385 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -468,7 +468,7 @@ void SUnit::print(raw_ostream &O, const ScheduleDAG *G) const { FlaggedNodes.push_back(N); while (!FlaggedNodes.empty()) { O << " "; - FlaggedNodes.back()->dump(G->DAG); + FlaggedNodes.back()->print(O, G->DAG); O << "\n"; FlaggedNodes.pop_back(); } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 758b8f263b3..d7481085dfd 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -444,31 +444,28 @@ namespace llvm { std::string DOTGraphTraits::getNodeLabel(const SUnit *SU, const ScheduleDAG *G) { - std::string Op; - - if (G->DAG) { - if (!SU->getNode()) - Op = ""; - else { - SmallVector FlaggedNodes; - for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) - FlaggedNodes.push_back(N); - while (!FlaggedNodes.empty()) { - Op += DOTGraphTraits::getNodeLabel(FlaggedNodes.back(), - G->DAG) + "\n"; - FlaggedNodes.pop_back(); - } - } - } else { - std::string s; - raw_string_ostream oss(s); - SU->getInstr()->print(oss); - Op += oss.str(); - } - - return Op; + return G->getGraphNodeLabel(SU); } +std::string ScheduleDAG::getGraphNodeLabel(const SUnit *SU) const { + std::string s; + raw_string_ostream O(s); + O << "SU(" << SU->NodeNum << "): "; + if (SU->getNode()) { + SmallVector FlaggedNodes; + for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode()) + FlaggedNodes.push_back(N); + while (!FlaggedNodes.empty()) { + O << DOTGraphTraits::getNodeLabel(FlaggedNodes.back(), DAG); + FlaggedNodes.pop_back(); + if (!FlaggedNodes.empty()) + O << "\n "; + } + } else { + O << "CROSS RC COPY"; + } + return O.str(); +} /// viewGraph - Pop up a ghostview window with the reachable parts of the DAG /// rendered using 'dot'.