forked from OSchip/llvm-project
Get rid of the global CFGOnly flag by threading a ShortNames parameters through the GraphViz rendering code.
Update other uses in the codebase for this change. llvm-svn: 74084
This commit is contained in:
parent
46be2e1557
commit
b70adf2b92
|
@ -51,7 +51,8 @@ struct DefaultDOTGraphTraits {
|
|||
/// getNodeLabel - Given a node and a pointer to the top level graph, return
|
||||
/// the label to print in the node.
|
||||
template<typename GraphType>
|
||||
static std::string getNodeLabel(const void *Node, const GraphType& Graph) {
|
||||
static std::string getNodeLabel(const void *Node,
|
||||
const GraphType& Graph, bool ShortNames) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ template<typename GraphType>
|
|||
class GraphWriter {
|
||||
std::ostream &O;
|
||||
const GraphType &G;
|
||||
bool ShortNames;
|
||||
|
||||
typedef DOTGraphTraits<GraphType> DOTTraits;
|
||||
typedef GraphTraits<GraphType> GTraits;
|
||||
|
@ -79,7 +80,8 @@ class GraphWriter {
|
|||
typedef typename GTraits::nodes_iterator node_iterator;
|
||||
typedef typename GTraits::ChildIteratorType child_iterator;
|
||||
public:
|
||||
GraphWriter(std::ostream &o, const GraphType &g) : O(o), G(g) {}
|
||||
GraphWriter(std::ostream &o, const GraphType &g, bool SN) :
|
||||
O(o), G(g), ShortNames(SN) {}
|
||||
|
||||
void writeHeader(const std::string &Name) {
|
||||
std::string GraphName = DOTTraits::getGraphName(G);
|
||||
|
@ -130,7 +132,7 @@ public:
|
|||
O << "label=\"{";
|
||||
|
||||
if (!DOTTraits::renderGraphFromBottomUp()) {
|
||||
O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
|
||||
O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames));
|
||||
|
||||
// If we should include the address of the node in the label, do so now.
|
||||
if (DOTTraits::hasNodeAddressLabel(Node, G))
|
||||
|
@ -156,7 +158,7 @@ public:
|
|||
}
|
||||
|
||||
if (DOTTraits::renderGraphFromBottomUp()) {
|
||||
O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G));
|
||||
O << DOT::EscapeString(DOTTraits::getNodeLabel(Node, G, ShortNames));
|
||||
|
||||
// If we should include the address of the node in the label, do so now.
|
||||
if (DOTTraits::hasNodeAddressLabel(Node, G))
|
||||
|
@ -250,10 +252,11 @@ public:
|
|||
|
||||
template<typename GraphType>
|
||||
std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
|
||||
bool ShortNames = false,
|
||||
const std::string &Name = "",
|
||||
const std::string &Title = "") {
|
||||
// Start the graph emission process...
|
||||
GraphWriter<GraphType> W(O, G);
|
||||
GraphWriter<GraphType> W(O, G, ShortNames);
|
||||
|
||||
// Output the header for the graph...
|
||||
W.writeHeader(Title);
|
||||
|
@ -272,6 +275,7 @@ std::ostream &WriteGraph(std::ostream &O, const GraphType &G,
|
|||
template<typename GraphType>
|
||||
sys::Path WriteGraph(const GraphType &G,
|
||||
const std::string& Name,
|
||||
bool ShortNames = false,
|
||||
const std::string& Title = "") {
|
||||
std::string ErrMsg;
|
||||
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
|
||||
|
@ -290,7 +294,7 @@ sys::Path WriteGraph(const GraphType &G,
|
|||
std::ofstream O(Filename.c_str());
|
||||
|
||||
if (O.good()) {
|
||||
WriteGraph(O, G, Name, Title);
|
||||
WriteGraph(O, G, ShortNames, Name, Title);
|
||||
cerr << " done. \n";
|
||||
|
||||
O.close();
|
||||
|
@ -308,8 +312,9 @@ sys::Path WriteGraph(const GraphType &G,
|
|||
template<typename GraphType>
|
||||
void ViewGraph(const GraphType& G,
|
||||
const std::string& Name,
|
||||
bool ShortNames = false,
|
||||
const std::string& Title = "") {
|
||||
sys::Path Filename = WriteGraph(G, Name, Title);
|
||||
sys::Path Filename = WriteGraph(G, Name, ShortNames, Title);
|
||||
|
||||
if (Filename.isEmpty()) {
|
||||
return;
|
||||
|
|
|
@ -31,12 +31,6 @@
|
|||
#include <fstream>
|
||||
using namespace llvm;
|
||||
|
||||
/// CFGOnly flag - This is used to control whether or not the CFG graph printer
|
||||
/// prints out the contents of basic blocks or not. This is acceptable because
|
||||
/// this code is only really used for debugging purposes.
|
||||
///
|
||||
static bool CFGOnly = false;
|
||||
|
||||
namespace llvm {
|
||||
template<>
|
||||
struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
|
||||
|
@ -45,12 +39,13 @@ struct DOTGraphTraits<const Function*> : public DefaultDOTGraphTraits {
|
|||
}
|
||||
|
||||
static std::string getNodeLabel(const BasicBlock *Node,
|
||||
const Function *Graph) {
|
||||
if (CFGOnly && !Node->getName().empty())
|
||||
const Function *Graph,
|
||||
bool ShortNames) {
|
||||
if (ShortNames && !Node->getName().empty())
|
||||
return Node->getName() + ":";
|
||||
|
||||
std::ostringstream Out;
|
||||
if (CFGOnly) {
|
||||
if (ShortNames) {
|
||||
WriteAsOperand(Out, Node, false);
|
||||
return Out.str();
|
||||
}
|
||||
|
@ -117,9 +112,7 @@ namespace {
|
|||
CFGOnlyViewer() : FunctionPass(&ID) {}
|
||||
|
||||
virtual bool runOnFunction(Function &F) {
|
||||
CFGOnly = true;
|
||||
F.viewCFG();
|
||||
CFGOnly = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -168,14 +161,20 @@ static RegisterPass<CFGPrinter>
|
|||
P1("dot-cfg", "Print CFG of function to 'dot' file", false, true);
|
||||
|
||||
namespace {
|
||||
struct VISIBILITY_HIDDEN CFGOnlyPrinter : public CFGPrinter {
|
||||
struct VISIBILITY_HIDDEN CFGOnlyPrinter : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
CFGOnlyPrinter() : CFGPrinter(&ID) {}
|
||||
CFGOnlyPrinter() : FunctionPass(&ID) {}
|
||||
explicit CFGOnlyPrinter(void *pid) : FunctionPass(pid) {}
|
||||
virtual bool runOnFunction(Function &F) {
|
||||
bool OldCFGOnly = CFGOnly;
|
||||
CFGOnly = true;
|
||||
CFGPrinter::runOnFunction(F);
|
||||
CFGOnly = OldCFGOnly;
|
||||
std::string Filename = "cfg." + F.getName() + ".dot";
|
||||
cerr << "Writing '" << Filename << "'...";
|
||||
std::ofstream File(Filename.c_str());
|
||||
|
||||
if (File.good())
|
||||
WriteGraph(File, (const Function*)&F, true);
|
||||
else
|
||||
cerr << " error opening file for writing!";
|
||||
cerr << "\n";
|
||||
return false;
|
||||
}
|
||||
void print(std::ostream &OS, const Module* = 0) const {}
|
||||
|
@ -206,9 +205,7 @@ void Function::viewCFG() const {
|
|||
/// his can make the graph smaller.
|
||||
///
|
||||
void Function::viewCFGOnly() const {
|
||||
CFGOnly = true;
|
||||
viewCFG();
|
||||
CFGOnly = false;
|
||||
ViewGraph(this, "cfg" + getName(), true);
|
||||
}
|
||||
|
||||
FunctionPass *llvm::createCFGPrinterPass () {
|
||||
|
|
|
@ -295,12 +295,6 @@ void MachineFunction::print(std::ostream &OS) const {
|
|||
OS << "\n# End machine code for " << Fn->getName () << "().\n\n";
|
||||
}
|
||||
|
||||
/// CFGOnly flag - This is used to control whether or not the CFG graph printer
|
||||
/// prints out the contents of basic blocks or not. This is acceptable because
|
||||
/// this code is only really used for debugging purposes.
|
||||
///
|
||||
static bool CFGOnly = false;
|
||||
|
||||
namespace llvm {
|
||||
template<>
|
||||
struct DOTGraphTraits<const MachineFunction*> : public DefaultDOTGraphTraits {
|
||||
|
@ -309,13 +303,14 @@ namespace llvm {
|
|||
}
|
||||
|
||||
static std::string getNodeLabel(const MachineBasicBlock *Node,
|
||||
const MachineFunction *Graph) {
|
||||
if (CFGOnly && Node->getBasicBlock() &&
|
||||
const MachineFunction *Graph,
|
||||
bool ShortNames) {
|
||||
if (ShortNames && Node->getBasicBlock() &&
|
||||
!Node->getBasicBlock()->getName().empty())
|
||||
return Node->getBasicBlock()->getName() + ":";
|
||||
|
||||
std::ostringstream Out;
|
||||
if (CFGOnly) {
|
||||
if (ShortNames) {
|
||||
Out << Node->getNumber() << ':';
|
||||
return Out.str();
|
||||
}
|
||||
|
@ -348,9 +343,12 @@ void MachineFunction::viewCFG() const
|
|||
|
||||
void MachineFunction::viewCFGOnly() const
|
||||
{
|
||||
CFGOnly = true;
|
||||
viewCFG();
|
||||
CFGOnly = false;
|
||||
#ifndef NDEBUG
|
||||
ViewGraph(this, "mf" + getFunction()->getName(), true);
|
||||
#else
|
||||
cerr << "SelectionDAG::viewGraph is only available in debug builds on "
|
||||
<< "systems with Graphviz or gv!\n";
|
||||
#endif // NDEBUG
|
||||
}
|
||||
|
||||
// The next two methods are used to construct and to retrieve
|
||||
|
|
|
@ -59,7 +59,8 @@ namespace llvm {
|
|||
|
||||
|
||||
static std::string getNodeLabel(const SUnit *Node,
|
||||
const ScheduleDAG *Graph);
|
||||
const ScheduleDAG *Graph,
|
||||
bool ShortNames);
|
||||
static std::string getNodeAttributes(const SUnit *N,
|
||||
const ScheduleDAG *Graph) {
|
||||
return "shape=Mrecord";
|
||||
|
@ -73,7 +74,8 @@ namespace llvm {
|
|||
}
|
||||
|
||||
std::string DOTGraphTraits<ScheduleDAG*>::getNodeLabel(const SUnit *SU,
|
||||
const ScheduleDAG *G) {
|
||||
const ScheduleDAG *G,
|
||||
bool ShortNames) {
|
||||
return G->getGraphNodeLabel(SU);
|
||||
}
|
||||
|
||||
|
@ -84,11 +86,11 @@ void ScheduleDAG::viewGraph() {
|
|||
// This code is only for debugging!
|
||||
#ifndef NDEBUG
|
||||
if (BB->getBasicBlock())
|
||||
ViewGraph(this, "dag." + MF.getFunction()->getName(),
|
||||
ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
|
||||
"Scheduling-Units Graph for " + MF.getFunction()->getName() + ':' +
|
||||
BB->getBasicBlock()->getName());
|
||||
else
|
||||
ViewGraph(this, "dag." + MF.getFunction()->getName(),
|
||||
ViewGraph(this, "dag." + MF.getFunction()->getName(), false,
|
||||
"Scheduling-Units Graph for " + MF.getFunction()->getName());
|
||||
#else
|
||||
cerr << "ScheduleDAG::viewGraph is only available in debug builds on "
|
||||
|
|
|
@ -94,7 +94,8 @@ namespace llvm {
|
|||
|
||||
|
||||
static std::string getNodeLabel(const SDNode *Node,
|
||||
const SelectionDAG *Graph);
|
||||
const SelectionDAG *Graph,
|
||||
bool ShortNames);
|
||||
static std::string getNodeAttributes(const SDNode *N,
|
||||
const SelectionDAG *Graph) {
|
||||
#ifndef NDEBUG
|
||||
|
@ -120,7 +121,8 @@ namespace llvm {
|
|||
}
|
||||
|
||||
std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
|
||||
const SelectionDAG *G) {
|
||||
const SelectionDAG *G,
|
||||
bool ShortNames) {
|
||||
std::string Op = Node->getOperationName(G);
|
||||
|
||||
if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(Node)) {
|
||||
|
@ -262,7 +264,7 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
|
|||
void SelectionDAG::viewGraph(const std::string &Title) {
|
||||
// This code is only for debugging!
|
||||
#ifndef NDEBUG
|
||||
ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(),
|
||||
ViewGraph(this, "dag." + getMachineFunction().getFunction()->getName(), false,
|
||||
Title);
|
||||
#else
|
||||
cerr << "SelectionDAG::viewGraph is only available in debug builds on "
|
||||
|
@ -393,7 +395,8 @@ std::string ScheduleDAGSDNodes::getGraphNodeLabel(const SUnit *SU) const {
|
|||
for (SDNode *N = SU->getNode(); N; N = N->getFlaggedNode())
|
||||
FlaggedNodes.push_back(N);
|
||||
while (!FlaggedNodes.empty()) {
|
||||
O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(), DAG);
|
||||
O << DOTGraphTraits<SelectionDAG*>::getNodeLabel(FlaggedNodes.back(),
|
||||
DAG, false);
|
||||
FlaggedNodes.pop_back();
|
||||
if (!FlaggedNodes.empty())
|
||||
O << "\n ";
|
||||
|
|
|
@ -477,7 +477,8 @@ namespace llvm {
|
|||
{
|
||||
|
||||
template<typename GraphType>
|
||||
static std::string getNodeLabel(const Node* N, const GraphType&)
|
||||
static std::string getNodeLabel(const Node* N, const GraphType&,
|
||||
bool ShortNames)
|
||||
{
|
||||
if (N->ToolPtr)
|
||||
if (N->ToolPtr->IsJoin())
|
||||
|
|
|
@ -49,7 +49,8 @@ namespace llvm {
|
|||
return "Call Graph";
|
||||
}
|
||||
|
||||
static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph) {
|
||||
static std::string getNodeLabel(CallGraphNode *Node, CallGraph *Graph,
|
||||
bool ShortNames) {
|
||||
if (Node->getFunction())
|
||||
return ((Value*)Node->getFunction())->getName();
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue