summaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2008-10-27 18:17:03 +0000
committerDavid Greene <greened@obbligato.org>2008-10-27 18:17:03 +0000
commitc5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449a (patch)
tree45f7145328c07e7051092cd9008271aeb060e864 /lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
parent13e781ebe7a39e008dd5e5de78983e095e8a1d02 (diff)
downloadllvm-c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449a.tar.gz
llvm-c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449a.tar.bz2
llvm-c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449a.tar.xz
Add setSubgraphColor to color an entire portion of a SelectionDAG. This
will be used to support debug features in TableGen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58257 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
index f188374412..6decc00f40 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
@@ -22,8 +22,10 @@
#include "llvm/CodeGen/PseudoSourceValue.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/GraphWriter.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include <fstream>
@@ -326,6 +328,61 @@ void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) {
#endif
}
+/// setSubgraphColorHelper - Implement setSubgraphColor. Return
+/// whether we truncated the search.
+///
+bool SelectionDAG::setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
+ int level, bool &printed) {
+ bool hit_limit = false;
+
+#ifndef NDEBUG
+ if (level >= 20) {
+ if (!printed) {
+ printed = true;
+ DOUT << "setSubgraphColor hit max level\n";
+ }
+ return true;
+ }
+
+ unsigned oldSize = visited.size();
+ visited.insert(N);
+ if (visited.size() != oldSize) {
+ setGraphColor(N, Color);
+ for(SDNodeIterator i = SDNodeIterator::begin(N), iend = SDNodeIterator::end(N);
+ i != iend;
+ ++i) {
+ hit_limit = setSubgraphColorHelper(*i, Color, visited, level+1, printed) || hit_limit;
+ }
+ }
+#else
+ cerr << "SelectionDAG::setSubgraphColor is only available in debug builds"
+ << " on systems with Graphviz or gv!\n";
+#endif
+ return hit_limit;
+}
+
+/// setSubgraphColor - Convenience for setting subgraph color attribute.
+///
+void SelectionDAG::setSubgraphColor(SDNode *N, const char *Color) {
+#ifndef NDEBUG
+ DenseSet<SDNode *> visited;
+ bool printed = false;
+ if (setSubgraphColorHelper(N, Color, visited, 0, printed)) {
+ // Visually mark that we hit the limit
+ if (Color == "red" ) {
+ setSubgraphColorHelper(N, "blue", visited, 0, printed);
+ }
+ else if (Color == "yellow" ) {
+ setSubgraphColorHelper(N, "green", visited, 0, printed);
+ }
+ }
+
+#else
+ cerr << "SelectionDAG::setSubgraphColor is only available in debug builds"
+ << " on systems with Graphviz or gv!\n";
+#endif
+}
+
namespace llvm {
template<>
struct DOTGraphTraits<ScheduleDAG*> : public DefaultDOTGraphTraits {