Add setSubgraphColor to color an entire portion of a SelectionDAG. This

will be used to support debug features in TableGen.

llvm-svn: 58257
This commit is contained in:
David Greene 2008-10-27 18:17:03 +00:00
parent e8f05397ca
commit 5015610892
2 changed files with 68 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#define LLVM_CODEGEN_SELECTIONDAG_H
#include "llvm/ADT/ilist.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
@ -102,6 +103,12 @@ class SelectionDAG {
/// VerifyNode - Sanity check the given node. Aborts if it is invalid.
void VerifyNode(SDNode *N);
/// setGraphColorHelper - Implementation of setSubgraphColor.
/// Return whether we had to truncate the search.
///
bool setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
int level, bool &printed);
public:
SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli);
~SelectionDAG();
@ -147,6 +154,10 @@ public:
///
void setGraphColor(const SDNode *N, const char *Color);
/// setGraphColor - Convenience for setting subgraph color attribute.
///
void setSubgraphColor(SDNode *N, const char *Color);
typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }

View File

@ -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 {