2005-01-11 00:08:40 +01:00
|
|
|
//===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===//
|
2005-04-22 00:36:52 +02:00
|
|
|
//
|
2005-01-11 00:08:40 +01:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 00:36:52 +02:00
|
|
|
//
|
2005-01-11 00:08:40 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the SelectionDAG::viewGraph method.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-06 18:22:58 +01:00
|
|
|
#include "ScheduleDAGSDNodes.h"
|
2005-08-26 19:15:30 +02:00
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Function.h"
|
2006-03-05 10:38:03 +01:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2005-01-11 00:08:40 +01:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2006-09-12 23:00:35 +02:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2005-01-11 00:08:40 +01:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2008-07-04 00:53:42 +02:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2008-07-17 23:12:16 +02:00
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2009-01-13 01:35:13 +01:00
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2008-02-10 19:45:23 +01:00
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2005-08-19 23:21:16 +02:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-10-27 19:17:03 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2005-01-11 00:08:40 +01:00
|
|
|
#include "llvm/Support/GraphWriter.h"
|
2008-08-24 00:53:13 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-10-27 19:17:03 +01:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2005-01-11 01:34:33 +01:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2005-07-16 00:48:31 +02:00
|
|
|
#include "llvm/Config/config.h"
|
2005-01-11 00:08:40 +01:00
|
|
|
#include <fstream>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2005-01-11 00:26:00 +01:00
|
|
|
namespace llvm {
|
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits {
|
2008-07-21 23:06:55 +02:00
|
|
|
static bool hasEdgeDestLabels() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned numEdgeDestLabels(const void *Node) {
|
|
|
|
return ((const SDNode *) Node)->getNumValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string getEdgeDestLabel(const void *Node, unsigned i) {
|
|
|
|
return ((const SDNode *) Node)->getValueType(i).getMVTString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// edgeTargetsEdgeSource - This method returns true if this outgoing edge
|
|
|
|
/// should actually target another edge source, not a node. If this method is
|
|
|
|
/// implemented, getEdgeTarget should be implemented.
|
|
|
|
template<typename EdgeIter>
|
|
|
|
static bool edgeTargetsEdgeSource(const void *Node, EdgeIter I) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getEdgeTarget - If edgeTargetsEdgeSource returns true, this method is
|
|
|
|
/// called to determine which outgoing edge of Node is the target of this
|
|
|
|
/// edge.
|
|
|
|
template<typename EdgeIter>
|
|
|
|
static EdgeIter getEdgeTarget(const void *Node, EdgeIter I) {
|
|
|
|
SDNode *TargetNode = *I;
|
|
|
|
SDNodeIterator NI = SDNodeIterator::begin(TargetNode);
|
2008-08-27 00:36:50 +02:00
|
|
|
std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo());
|
2008-07-21 23:06:55 +02:00
|
|
|
return NI;
|
|
|
|
}
|
|
|
|
|
2005-01-11 00:26:00 +01:00
|
|
|
static std::string getGraphName(const SelectionDAG *G) {
|
|
|
|
return G->getMachineFunction().getFunction()->getName();
|
|
|
|
}
|
2005-01-11 01:34:33 +01:00
|
|
|
|
|
|
|
static bool renderGraphFromBottomUp() {
|
|
|
|
return true;
|
2005-01-11 00:26:00 +01:00
|
|
|
}
|
2005-10-01 02:17:07 +02:00
|
|
|
|
|
|
|
static bool hasNodeAddressLabel(const SDNode *Node,
|
|
|
|
const SelectionDAG *Graph) {
|
|
|
|
return true;
|
|
|
|
}
|
2006-10-20 20:06:09 +02:00
|
|
|
|
|
|
|
/// If you want to override the dot attributes printed for a particular
|
|
|
|
/// edge, override this method.
|
|
|
|
template<typename EdgeIter>
|
|
|
|
static std::string getEdgeAttributes(const void *Node, EdgeIter EI) {
|
2008-07-27 23:46:04 +02:00
|
|
|
SDValue Op = EI.getNode()->getOperand(EI.getOperand());
|
2008-06-06 14:08:01 +02:00
|
|
|
MVT VT = Op.getValueType();
|
2006-10-20 20:06:09 +02:00
|
|
|
if (VT == MVT::Flag)
|
|
|
|
return "color=red,style=bold";
|
|
|
|
else if (VT == MVT::Other)
|
2007-06-18 17:30:16 +02:00
|
|
|
return "color=blue,style=dashed";
|
2006-10-20 20:06:09 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2005-01-11 00:26:00 +01:00
|
|
|
|
2005-01-11 01:34:33 +01:00
|
|
|
static std::string getNodeLabel(const SDNode *Node,
|
|
|
|
const SelectionDAG *Graph);
|
2006-10-02 14:26:53 +02:00
|
|
|
static std::string getNodeAttributes(const SDNode *N,
|
|
|
|
const SelectionDAG *Graph) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
const std::string &Attrs = Graph->getGraphAttrs(N);
|
|
|
|
if (!Attrs.empty()) {
|
|
|
|
if (Attrs.find("shape=") == std::string::npos)
|
|
|
|
return std::string("shape=Mrecord,") + Attrs;
|
|
|
|
else
|
|
|
|
return Attrs;
|
|
|
|
}
|
|
|
|
#endif
|
2005-01-11 00:26:00 +01:00
|
|
|
return "shape=Mrecord";
|
|
|
|
}
|
2005-01-11 00:52:04 +01:00
|
|
|
|
|
|
|
static void addCustomGraphFeatures(SelectionDAG *G,
|
|
|
|
GraphWriter<SelectionDAG*> &GW) {
|
|
|
|
GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
|
2008-08-28 23:40:38 +02:00
|
|
|
if (G->getRoot().getNode())
|
|
|
|
GW.emitEdge(0, -1, G->getRoot().getNode(), G->getRoot().getResNo(),
|
2008-07-22 19:52:59 +02:00
|
|
|
"color=blue,style=dashed");
|
2005-01-11 00:52:04 +01:00
|
|
|
}
|
2005-01-11 00:26:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2005-01-11 01:34:33 +01:00
|
|
|
std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
|
|
|
|
const SelectionDAG *G) {
|
2005-08-16 20:31:23 +02:00
|
|
|
std::string Op = Node->getOperationName(G);
|
2005-01-11 23:21:04 +01:00
|
|
|
|
2005-01-11 01:34:33 +01:00
|
|
|
if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) {
|
2008-09-12 18:56:44 +02:00
|
|
|
Op += ": " + utostr(CSDN->getZExtValue());
|
2005-01-11 01:34:33 +01:00
|
|
|
} else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(Node)) {
|
2007-08-31 06:03:46 +02:00
|
|
|
Op += ": " + ftostr(CSDN->getValueAPF());
|
2005-04-22 00:36:52 +02:00
|
|
|
} else if (const GlobalAddressSDNode *GADN =
|
2005-01-11 01:34:33 +01:00
|
|
|
dyn_cast<GlobalAddressSDNode>(Node)) {
|
|
|
|
Op += ": " + GADN->getGlobal()->getName();
|
2008-10-18 20:22:42 +02:00
|
|
|
if (int64_t Offset = GADN->getOffset()) {
|
2008-09-21 20:38:31 +02:00
|
|
|
if (Offset > 0)
|
|
|
|
Op += "+" + itostr(Offset);
|
|
|
|
else
|
|
|
|
Op += itostr(Offset);
|
|
|
|
}
|
2005-04-22 06:01:18 +02:00
|
|
|
} else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) {
|
2005-01-11 01:34:33 +01:00
|
|
|
Op += " " + itostr(FIDN->getIndex());
|
2006-11-01 05:48:30 +01:00
|
|
|
} else if (const JumpTableSDNode *JTDN = dyn_cast<JumpTableSDNode>(Node)) {
|
|
|
|
Op += " " + itostr(JTDN->getIndex());
|
2005-01-11 01:34:33 +01:00
|
|
|
} else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){
|
2006-09-12 23:00:35 +02:00
|
|
|
if (CP->isMachineConstantPoolEntry()) {
|
2008-08-24 00:53:13 +02:00
|
|
|
Op += '<';
|
|
|
|
{
|
|
|
|
raw_string_ostream OSS(Op);
|
|
|
|
OSS << *CP->getMachineCPVal();
|
|
|
|
}
|
|
|
|
Op += '>';
|
2006-09-12 23:00:35 +02:00
|
|
|
} else {
|
|
|
|
if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal()))
|
2007-08-31 06:03:46 +02:00
|
|
|
Op += "<" + ftostr(CFP->getValueAPF()) + ">";
|
2006-09-12 23:00:35 +02:00
|
|
|
else if (ConstantInt *CI = dyn_cast<ConstantInt>(CP->getConstVal()))
|
|
|
|
Op += "<" + utostr(CI->getZExtValue()) + ">";
|
|
|
|
else {
|
2008-08-24 00:53:13 +02:00
|
|
|
Op += '<';
|
|
|
|
{
|
|
|
|
raw_string_ostream OSS(Op);
|
|
|
|
WriteAsOperand(OSS, CP->getConstVal(), false);
|
|
|
|
}
|
|
|
|
Op += '>';
|
2006-09-12 23:00:35 +02:00
|
|
|
}
|
2006-03-05 10:38:03 +01:00
|
|
|
}
|
2009-03-13 08:51:59 +01:00
|
|
|
Op += " A=" + itostr(CP->getAlignment());
|
2005-04-22 06:01:18 +02:00
|
|
|
} else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) {
|
2005-01-11 01:34:33 +01:00
|
|
|
Op = "BB: ";
|
|
|
|
const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
|
|
|
|
if (LBB)
|
|
|
|
Op += LBB->getName();
|
|
|
|
//Op += " " + (const void*)BBDN->getBasicBlock();
|
2005-08-16 23:55:35 +02:00
|
|
|
} else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(Node)) {
|
2006-10-20 20:06:09 +02:00
|
|
|
if (G && R->getReg() != 0 &&
|
2008-02-10 19:45:23 +01:00
|
|
|
TargetRegisterInfo::isPhysicalRegister(R->getReg())) {
|
2008-02-26 22:11:01 +01:00
|
|
|
Op = Op + " " +
|
2008-02-27 07:33:05 +01:00
|
|
|
G->getTarget().getRegisterInfo()->getName(R->getReg());
|
2005-08-19 23:21:16 +02:00
|
|
|
} else {
|
|
|
|
Op += " #" + utostr(R->getReg());
|
|
|
|
}
|
2008-06-30 22:59:49 +02:00
|
|
|
} else if (const DbgStopPointSDNode *D = dyn_cast<DbgStopPointSDNode>(Node)) {
|
2009-01-13 01:35:13 +01:00
|
|
|
DICompileUnit CU(cast<GlobalVariable>(D->getCompileUnit()));
|
2009-03-13 05:39:26 +01:00
|
|
|
std::string FN;
|
|
|
|
Op += ": " + CU.getFilename(FN);
|
2008-06-30 22:59:49 +02:00
|
|
|
Op += ":" + utostr(D->getLine());
|
|
|
|
if (D->getColumn() != 0)
|
|
|
|
Op += ":" + utostr(D->getColumn());
|
2008-07-01 02:05:16 +02:00
|
|
|
} else if (const LabelSDNode *L = dyn_cast<LabelSDNode>(Node)) {
|
|
|
|
Op += ": LabelID=" + utostr(L->getLabelID());
|
2008-09-13 03:54:27 +02:00
|
|
|
} else if (const CallSDNode *C = dyn_cast<CallSDNode>(Node)) {
|
|
|
|
Op += ": CallingConv=" + utostr(C->getCallingConv());
|
|
|
|
if (C->isVarArg())
|
|
|
|
Op += ", isVarArg";
|
|
|
|
if (C->isTailCall())
|
|
|
|
Op += ", isTailCall";
|
2008-09-16 23:48:12 +02:00
|
|
|
} else if (const ExternalSymbolSDNode *ES =
|
|
|
|
dyn_cast<ExternalSymbolSDNode>(Node)) {
|
|
|
|
Op += "'" + std::string(ES->getSymbol()) + "'";
|
2005-05-09 06:08:27 +02:00
|
|
|
} else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(Node)) {
|
|
|
|
if (M->getValue())
|
2008-02-06 23:27:42 +01:00
|
|
|
Op += "<" + M->getValue()->getName() + ">";
|
2005-05-09 06:08:27 +02:00
|
|
|
else
|
2008-02-06 23:27:42 +01:00
|
|
|
Op += "<null>";
|
|
|
|
} else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(Node)) {
|
2008-07-17 23:12:16 +02:00
|
|
|
const Value *V = M->MO.getValue();
|
|
|
|
Op += '<';
|
|
|
|
if (!V) {
|
|
|
|
Op += "(unknown)";
|
2008-12-15 18:28:10 +01:00
|
|
|
} else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
|
2008-07-17 23:12:16 +02:00
|
|
|
// PseudoSourceValues don't have names, so use their print method.
|
2008-12-15 18:28:10 +01:00
|
|
|
raw_string_ostream OSS(Op);
|
|
|
|
PSV->print(OSS);
|
2008-07-14 19:51:24 +02:00
|
|
|
} else {
|
2008-07-17 23:12:16 +02:00
|
|
|
Op += V->getName();
|
2008-07-14 19:51:24 +02:00
|
|
|
}
|
2008-07-17 23:12:16 +02:00
|
|
|
Op += '+' + itostr(M->MO.getOffset()) + '>';
|
2008-03-21 10:14:45 +01:00
|
|
|
} else if (const ARG_FLAGSSDNode *N = dyn_cast<ARG_FLAGSSDNode>(Node)) {
|
|
|
|
Op = Op + " AF=" + N->getArgFlags().getArgFlagsString();
|
2005-08-18 05:31:02 +02:00
|
|
|
} else if (const VTSDNode *N = dyn_cast<VTSDNode>(Node)) {
|
2008-06-06 14:08:01 +02:00
|
|
|
Op = Op + " VT=" + N->getVT().getMVTString();
|
2006-10-10 22:11:26 +02:00
|
|
|
} else if (const LoadSDNode *LD = dyn_cast<LoadSDNode>(Node)) {
|
|
|
|
bool doExt = true;
|
|
|
|
switch (LD->getExtensionType()) {
|
|
|
|
default: doExt = false; break;
|
|
|
|
case ISD::EXTLOAD:
|
|
|
|
Op = Op + "<anyext ";
|
|
|
|
break;
|
|
|
|
case ISD::SEXTLOAD:
|
|
|
|
Op = Op + " <sext ";
|
|
|
|
break;
|
|
|
|
case ISD::ZEXTLOAD:
|
|
|
|
Op = Op + " <zext ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (doExt)
|
2008-06-06 14:08:01 +02:00
|
|
|
Op += LD->getMemoryVT().getMVTString() + ">";
|
2008-01-25 07:40:45 +01:00
|
|
|
if (LD->isVolatile())
|
|
|
|
Op += "<V>";
|
2006-11-09 19:44:21 +01:00
|
|
|
Op += LD->getIndexedModeName(LD->getAddressingMode());
|
2008-01-25 07:40:45 +01:00
|
|
|
if (LD->getAlignment() > 1)
|
|
|
|
Op += " A=" + utostr(LD->getAlignment());
|
2006-10-17 23:18:26 +02:00
|
|
|
} else if (const StoreSDNode *ST = dyn_cast<StoreSDNode>(Node)) {
|
|
|
|
if (ST->isTruncatingStore())
|
2008-06-06 14:08:01 +02:00
|
|
|
Op += "<trunc " + ST->getMemoryVT().getMVTString() + ">";
|
2008-01-25 07:40:45 +01:00
|
|
|
if (ST->isVolatile())
|
|
|
|
Op += "<V>";
|
2006-11-09 19:44:21 +01:00
|
|
|
Op += ST->getIndexedModeName(ST->getAddressingMode());
|
2008-01-25 07:40:45 +01:00
|
|
|
if (ST->getAlignment() > 1)
|
|
|
|
Op += " A=" + utostr(ST->getAlignment());
|
2005-01-11 01:34:33 +01:00
|
|
|
}
|
2007-10-15 07:32:43 +02:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
Op += " Id=" + itostr(Node->getNodeId());
|
|
|
|
#endif
|
2005-11-29 07:21:05 +01:00
|
|
|
|
2005-01-11 01:34:33 +01:00
|
|
|
return Op;
|
|
|
|
}
|
2005-04-22 00:36:52 +02:00
|
|
|
|
2005-01-11 01:34:33 +01:00
|
|
|
|
2005-01-11 00:08:40 +01:00
|
|
|
/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
|
|
|
|
/// rendered using 'dot'.
|
|
|
|
///
|
2008-07-21 22:00:07 +02:00
|
|
|
void SelectionDAG::viewGraph(const std::string &Title) {
|
2005-07-14 07:17:43 +02:00
|
|
|
// This code is only for debugging!
|
2005-07-14 07:33:13 +02:00
|
|
|
#ifndef NDEBUG
|
2008-07-21 22:00:07 +02:00
|
|
|
ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(),
|
|
|
|
Title);
|
2006-06-27 18:49:46 +02:00
|
|
|
#else
|
2006-12-07 21:04:42 +01:00
|
|
|
cerr << "SelectionDAG::viewGraph is only available in debug builds on "
|
|
|
|
<< "systems with Graphviz or gv!\n";
|
2006-06-27 18:49:46 +02:00
|
|
|
#endif // NDEBUG
|
2005-01-11 00:08:40 +01:00
|
|
|
}
|
2006-10-02 14:26:53 +02:00
|
|
|
|
2008-07-30 20:48:53 +02:00
|
|
|
// 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() {
|
|
|
|
viewGraph("");
|
|
|
|
}
|
2006-10-02 14:26:53 +02:00
|
|
|
|
|
|
|
/// clearGraphAttrs - Clear all previously defined node graph attributes.
|
|
|
|
/// Intended to be used from a debugging tool (eg. gdb).
|
|
|
|
void SelectionDAG::clearGraphAttrs() {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
NodeGraphAttrs.clear();
|
|
|
|
#else
|
2006-12-07 21:04:42 +01:00
|
|
|
cerr << "SelectionDAG::clearGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 14:26:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
|
|
|
|
///
|
|
|
|
void SelectionDAG::setGraphAttrs(const SDNode *N, const char *Attrs) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
NodeGraphAttrs[N] = Attrs;
|
|
|
|
#else
|
2006-12-07 21:04:42 +01:00
|
|
|
cerr << "SelectionDAG::setGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 14:26:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
|
|
|
|
/// Used from getNodeAttributes.
|
|
|
|
const std::string SelectionDAG::getGraphAttrs(const SDNode *N) const {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
std::map<const SDNode *, std::string>::const_iterator I =
|
|
|
|
NodeGraphAttrs.find(N);
|
|
|
|
|
|
|
|
if (I != NodeGraphAttrs.end())
|
|
|
|
return I->second;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
#else
|
2006-12-07 21:04:42 +01:00
|
|
|
cerr << "SelectionDAG::getGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 14:26:53 +02:00
|
|
|
return std::string("");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setGraphColor - Convenience for setting node color attribute.
|
|
|
|
///
|
|
|
|
void SelectionDAG::setGraphColor(const SDNode *N, const char *Color) {
|
|
|
|
#ifndef NDEBUG
|
|
|
|
NodeGraphAttrs[N] = std::string("color=") + Color;
|
|
|
|
#else
|
2006-12-07 21:04:42 +01:00
|
|
|
cerr << "SelectionDAG::setGraphColor is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 14:26:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-10-27 19:17:03 +01:00
|
|
|
/// 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
|
2008-10-27 23:43:07 +01:00
|
|
|
if (strcmp(Color, "red") == 0) {
|
2008-10-27 19:17:03 +01:00
|
|
|
setSubgraphColorHelper(N, "blue", visited, 0, printed);
|
|
|
|
}
|
2008-10-27 23:43:07 +01:00
|
|
|
else if (strcmp(Color, "yellow") == 0) {
|
2008-10-27 19:17:03 +01:00
|
|
|
setSubgraphColorHelper(N, "green", visited, 0, printed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
cerr << "SelectionDAG::setSubgraphColor is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
|
2008-11-19 23:09:45 +01:00
|
|
|
std::string s;
|
|
|
|
raw_string_ostream O(s);
|
|
|
|
O << "SU(" << SU->NodeNum << "): ";
|
|
|
|
if (SU->getNode()) {
|
|
|
|
SmallVector<SDNode *, 4> FlaggedNodes;
|
|
|
|
for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode())
|
|
|
|
FlaggedNodes.push_back(N);
|
|
|
|
while (!FlaggedNodes.empty()) {
|
|
|
|
O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(), DAG);
|
|
|
|
FlaggedNodes.pop_back();
|
|
|
|
if (!FlaggedNodes.empty())
|
|
|
|
O << "\n ";
|
2008-11-14 00:24:17 +01:00
|
|
|
}
|
2008-11-14 01:28:56 +01:00
|
|
|
} else {
|
2008-11-19 23:09:45 +01:00
|
|
|
O << "CROSS RC COPY";
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
2008-11-19 23:09:45 +01:00
|
|
|
return O.str();
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|
|
|
|
|
2008-11-20 00:18:57 +01:00
|
|
|
void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const {
|
|
|
|
if (DAG) {
|
|
|
|
// Draw a special "GraphRoot" node to indicate the root of the graph.
|
|
|
|
GW.emitSimpleNode(0, "plaintext=circle", "GraphRoot");
|
|
|
|
const SDNode *N = DAG->getRoot().getNode();
|
|
|
|
if (N && N->getNodeId() != -1)
|
|
|
|
GW.emitEdge(0, -1, &SUnits[N->getNodeId()], -1,
|
|
|
|
"color=blue,style=dashed");
|
|
|
|
}
|
2007-08-28 22:32:58 +02:00
|
|
|
}
|