2005-01-10 23:08:40 +00:00
|
|
|
//===-- SelectionDAGPrinter.cpp - Implement SelectionDAG::viewGraph() -----===//
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-10 23:08:40 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:36:52 +00:00
|
|
|
//
|
2005-01-10 23:08:40 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This implements the SelectionDAG::viewGraph method.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-06 17:22:58 +00:00
|
|
|
#include "ScheduleDAGSDNodes.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2006-09-12 21:00:35 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2005-01-10 23:08:40 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2008-07-03 22:53:42 +00:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
2017-06-06 11:49:48 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Constants.h"
|
2014-03-06 00:46:21 +00:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2008-10-27 18:17:03 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2005-01-10 23:08:40 +00:00
|
|
|
#include "llvm/Support/GraphWriter.h"
|
2008-08-23 22:53:13 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
2005-01-10 23:08:40 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-21 22:55:11 +00:00
|
|
|
#define DEBUG_TYPE "dag-printer"
|
|
|
|
|
2005-01-10 23:26:00 +00:00
|
|
|
namespace llvm {
|
|
|
|
template<>
|
|
|
|
struct DOTGraphTraits<SelectionDAG*> : public DefaultDOTGraphTraits {
|
2009-11-30 12:38:13 +00:00
|
|
|
|
2009-12-01 19:16:15 +00:00
|
|
|
explicit DOTGraphTraits(bool isSimple=false) :
|
|
|
|
DefaultDOTGraphTraits(isSimple) {}
|
2009-11-30 12:38:13 +00:00
|
|
|
|
2008-07-21 21:06:55 +00: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) {
|
2009-08-10 22:56:29 +00:00
|
|
|
return ((const SDNode *) Node)->getValueType(i).getEVTString();
|
2008-07-21 21:06:55 +00:00
|
|
|
}
|
|
|
|
|
2009-12-01 19:20:00 +00:00
|
|
|
template<typename EdgeIter>
|
|
|
|
static std::string getEdgeSourceLabel(const void *Node, EdgeIter I) {
|
2012-09-05 22:03:34 +00:00
|
|
|
return itostr(I - SDNodeIterator::begin((const SDNode *) Node));
|
2009-12-01 19:20:00 +00:00
|
|
|
}
|
|
|
|
|
2008-07-21 21:06:55 +00:00
|
|
|
/// edgeTargetsEdgeSource - This method returns true if this outgoing edge
|
2009-11-30 12:38:13 +00:00
|
|
|
/// should actually target another edge source, not a node. If this method
|
|
|
|
/// is implemented, getEdgeTarget should be implemented.
|
2008-07-21 21:06:55 +00:00
|
|
|
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-26 22:36:50 +00:00
|
|
|
std::advance(NI, I.getNode()->getOperand(I.getOperand()).getResNo());
|
2008-07-21 21:06:55 +00:00
|
|
|
return NI;
|
|
|
|
}
|
|
|
|
|
2005-01-10 23:26:00 +00:00
|
|
|
static std::string getGraphName(const SelectionDAG *G) {
|
2012-08-22 06:07:19 +00:00
|
|
|
return G->getMachineFunction().getName();
|
2005-01-10 23:26:00 +00:00
|
|
|
}
|
2005-01-11 00:34:33 +00:00
|
|
|
|
|
|
|
static bool renderGraphFromBottomUp() {
|
|
|
|
return true;
|
2005-01-10 23:26:00 +00:00
|
|
|
}
|
2009-12-01 19:16:15 +00:00
|
|
|
|
2015-10-27 23:09:03 +00:00
|
|
|
static std::string getNodeIdentifierLabel(const SDNode *Node,
|
|
|
|
const SelectionDAG *Graph) {
|
|
|
|
std::string R;
|
|
|
|
raw_string_ostream OS(R);
|
|
|
|
#ifndef NDEBUG
|
|
|
|
OS << 't' << Node->PersistentId;
|
|
|
|
#else
|
|
|
|
OS << static_cast<const void *>(Node);
|
|
|
|
#endif
|
|
|
|
return R;
|
2005-10-01 00:17:07 +00:00
|
|
|
}
|
2009-12-01 19:16:15 +00:00
|
|
|
|
2006-10-20 18:06:09 +00:00
|
|
|
/// If you want to override the dot attributes printed for a particular
|
|
|
|
/// edge, override this method.
|
|
|
|
template<typename EdgeIter>
|
2011-02-27 04:11:03 +00:00
|
|
|
static std::string getEdgeAttributes(const void *Node, EdgeIter EI,
|
|
|
|
const SelectionDAG *Graph) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op = EI.getNode()->getOperand(EI.getOperand());
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT VT = Op.getValueType();
|
2010-12-21 02:38:05 +00:00
|
|
|
if (VT == MVT::Glue)
|
2006-10-20 18:06:09 +00:00
|
|
|
return "color=red,style=bold";
|
2009-08-11 20:47:22 +00:00
|
|
|
else if (VT == MVT::Other)
|
2007-06-18 15:30:16 +00:00
|
|
|
return "color=blue,style=dashed";
|
2006-10-20 18:06:09 +00:00
|
|
|
return "";
|
|
|
|
}
|
2009-12-01 19:16:15 +00:00
|
|
|
|
2005-01-10 23:26:00 +00:00
|
|
|
|
2009-11-30 12:38:47 +00:00
|
|
|
static std::string getSimpleNodeLabel(const SDNode *Node,
|
|
|
|
const SelectionDAG *G) {
|
|
|
|
std::string Result = Node->getOperationName(G);
|
|
|
|
{
|
|
|
|
raw_string_ostream OS(Result);
|
|
|
|
Node->print_details(OS, G);
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
std::string getNodeLabel(const SDNode *Node, const SelectionDAG *Graph);
|
2006-10-02 12:26:53 +00: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-10 23:26:00 +00:00
|
|
|
return "shape=Mrecord";
|
|
|
|
}
|
2005-01-10 23:52:04 +00:00
|
|
|
|
|
|
|
static void addCustomGraphFeatures(SelectionDAG *G,
|
|
|
|
GraphWriter<SelectionDAG*> &GW) {
|
2014-04-14 00:51:57 +00:00
|
|
|
GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
|
2008-08-28 21:40:38 +00:00
|
|
|
if (G->getRoot().getNode())
|
2014-04-14 00:51:57 +00:00
|
|
|
GW.emitEdge(nullptr, -1, G->getRoot().getNode(), G->getRoot().getResNo(),
|
2008-07-22 17:52:59 +00:00
|
|
|
"color=blue,style=dashed");
|
2005-01-10 23:52:04 +00:00
|
|
|
}
|
2005-01-10 23:26:00 +00:00
|
|
|
};
|
2015-06-23 09:49:53 +00:00
|
|
|
}
|
2005-01-10 23:26:00 +00:00
|
|
|
|
2005-01-11 00:34:33 +00:00
|
|
|
std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
|
2009-11-30 12:38:47 +00:00
|
|
|
const SelectionDAG *G) {
|
2009-12-01 19:16:15 +00:00
|
|
|
return DOTGraphTraits<SelectionDAG*>::getSimpleNodeLabel(Node, G);
|
2005-01-11 00:34:33 +00:00
|
|
|
}
|
2005-04-21 22:36:52 +00:00
|
|
|
|
2005-01-11 00:34:33 +00:00
|
|
|
|
2005-01-10 23:08:40 +00:00
|
|
|
/// viewGraph - Pop up a ghostview window with the reachable parts of the DAG
|
|
|
|
/// rendered using 'dot'.
|
|
|
|
///
|
2008-07-21 20:00:07 +00:00
|
|
|
void SelectionDAG::viewGraph(const std::string &Title) {
|
2005-07-14 05:17:43 +00:00
|
|
|
// This code is only for debugging!
|
2005-07-14 05:33:13 +00:00
|
|
|
#ifndef NDEBUG
|
2012-08-22 06:07:19 +00:00
|
|
|
ViewGraph(this, "dag." + getMachineFunction().getName(),
|
2009-07-24 08:24:36 +00:00
|
|
|
false, Title);
|
2006-06-27 16:49:46 +00:00
|
|
|
#else
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::viewGraph is only available in debug builds on "
|
|
|
|
<< "systems with Graphviz or gv!\n";
|
2006-06-27 16:49:46 +00:00
|
|
|
#endif // NDEBUG
|
2005-01-10 23:08:40 +00:00
|
|
|
}
|
2006-10-02 12:26:53 +00:00
|
|
|
|
2008-07-30 18:48:53 +00: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 12:26:53 +00: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
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::clearGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 12:26:53 +00: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
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::setGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 12:26:53 +00: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);
|
2009-12-01 19:16:15 +00:00
|
|
|
|
2006-10-02 12:26:53 +00:00
|
|
|
if (I != NodeGraphAttrs.end())
|
|
|
|
return I->second;
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
#else
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::getGraphAttrs is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2010-08-04 01:39:08 +00:00
|
|
|
return std::string();
|
2006-10-02 12:26:53 +00:00
|
|
|
#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
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::setGraphColor is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2006-10-02 12:26:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-10-27 18:17:03 +00: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;
|
2010-01-05 01:24:45 +00:00
|
|
|
DEBUG(dbgs() << "setSubgraphColor hit max level\n");
|
2008-10-27 18:17:03 +00:00
|
|
|
}
|
|
|
|
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
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2008-10-27 18:17:03 +00:00
|
|
|
#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 22:43:07 +00:00
|
|
|
if (strcmp(Color, "red") == 0) {
|
2008-10-27 18:17:03 +00:00
|
|
|
setSubgraphColorHelper(N, "blue", visited, 0, printed);
|
2009-12-01 19:16:15 +00:00
|
|
|
} else if (strcmp(Color, "yellow") == 0) {
|
2008-10-27 18:17:03 +00:00
|
|
|
setSubgraphColorHelper(N, "green", visited, 0, printed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2009-08-23 08:50:52 +00:00
|
|
|
errs() << "SelectionDAG::setSubgraphColor is only available in debug builds"
|
|
|
|
<< " on systems with Graphviz or gv!\n";
|
2008-10-27 18:17:03 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-11-19 23:18:57 +00:00
|
|
|
std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
|
2014-06-26 22:52:05 +00:00
|
|
|
std::string s;
|
|
|
|
raw_string_ostream O(s);
|
2008-11-19 22:09:45 +00:00
|
|
|
O << "SU(" << SU->NodeNum << "): ";
|
|
|
|
if (SU->getNode()) {
|
2010-12-23 17:24:32 +00:00
|
|
|
SmallVector<SDNode *, 4> GluedNodes;
|
|
|
|
for (SDNode *N = SU->getNode(); N; N = N->getGluedNode())
|
|
|
|
GluedNodes.push_back(N);
|
|
|
|
while (!GluedNodes.empty()) {
|
2009-11-30 12:38:47 +00:00
|
|
|
O << DOTGraphTraits<SelectionDAG*>
|
2010-12-23 17:24:32 +00:00
|
|
|
::getSimpleNodeLabel(GluedNodes.back(), DAG);
|
|
|
|
GluedNodes.pop_back();
|
|
|
|
if (!GluedNodes.empty())
|
2008-11-19 22:09:45 +00:00
|
|
|
O << "\n ";
|
2008-11-13 23:24:17 +00:00
|
|
|
}
|
2008-11-14 00:28:56 +00:00
|
|
|
} else {
|
2008-11-19 22:09:45 +00:00
|
|
|
O << "CROSS RC COPY";
|
2007-08-28 20:32:58 +00:00
|
|
|
}
|
2008-11-19 22:09:45 +00:00
|
|
|
return O.str();
|
2007-08-28 20:32:58 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 23:18:57 +00:00
|
|
|
void ScheduleDAGSDNodes::getCustomGraphFeatures(GraphWriter<ScheduleDAG*> &GW) const {
|
|
|
|
if (DAG) {
|
|
|
|
// Draw a special "GraphRoot" node to indicate the root of the graph.
|
2014-04-14 00:51:57 +00:00
|
|
|
GW.emitSimpleNode(nullptr, "plaintext=circle", "GraphRoot");
|
2008-11-19 23:18:57 +00:00
|
|
|
const SDNode *N = DAG->getRoot().getNode();
|
|
|
|
if (N && N->getNodeId() != -1)
|
2014-04-14 00:51:57 +00:00
|
|
|
GW.emitEdge(nullptr, -1, &SUnits[N->getNodeId()], -1,
|
2008-11-19 23:18:57 +00:00
|
|
|
"color=blue,style=dashed");
|
|
|
|
}
|
2007-08-28 20:32:58 +00:00
|
|
|
}
|