blob: 1e873bfa5264111f61eaca47e71cd5414ced1584 [file] [log] [blame]
Chris Lattner3d980492001-07-03 05:36:34 +00001//===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
Chris Lattnerda956802001-06-21 05:27:22 +00002//
Chris Lattner3d980492001-07-03 05:36:34 +00003// This library file implements analysis result printing support for
4// llvm/Analysis/Writer.h
Chris Lattnerda956802001-06-21 05:27:22 +00005//
6//===----------------------------------------------------------------------===//
7
Chris Lattner3d980492001-07-03 05:36:34 +00008#include "llvm/Analysis/Writer.h"
Chris Lattnere6850232001-07-03 15:28:35 +00009#include "llvm/Analysis/IntervalPartition.h"
Chris Lattner3d980492001-07-03 05:36:34 +000010#include "llvm/Analysis/Dominators.h"
Chris Lattnera2eb2592001-11-26 18:53:29 +000011#include "llvm/Analysis/LoopInfo.h"
12#include "llvm/Analysis/InductionVariable.h"
Chris Lattnerda956802001-06-21 05:27:22 +000013#include <iterator>
14#include <algorithm>
Chris Lattner697954c2002-01-20 22:54:45 +000015using std::ostream;
16using std::set;
17using std::vector;
18using std::string;
Chris Lattnerda956802001-06-21 05:27:22 +000019
Chris Lattnere6850232001-07-03 15:28:35 +000020//===----------------------------------------------------------------------===//
21// Interval Printing Routines
22//===----------------------------------------------------------------------===//
23
Chris Lattnerda956802001-06-21 05:27:22 +000024void cfg::WriteToOutput(const Interval *I, ostream &o) {
25 o << "-------------------------------------------------------------\n"
26 << "Interval Contents:\n";
27
28 // Print out all of the basic blocks in the interval...
29 copy(I->Nodes.begin(), I->Nodes.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000030 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000031
32 o << "Interval Predecessors:\n";
33 copy(I->Predecessors.begin(), I->Predecessors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000034 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000035
36 o << "Interval Successors:\n";
37 copy(I->Successors.begin(), I->Successors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000038 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000039}
Chris Lattner347bfda2001-07-02 05:46:47 +000040
Chris Lattnere6850232001-07-03 15:28:35 +000041void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
Chris Lattner697954c2002-01-20 22:54:45 +000042 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
Chris Lattnere6850232001-07-03 15:28:35 +000043}
44
45
46
47//===----------------------------------------------------------------------===//
48// Dominator Printing Routines
49//===----------------------------------------------------------------------===//
50
Chris Lattner347bfda2001-07-02 05:46:47 +000051ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
Chris Lattner697954c2002-01-20 22:54:45 +000052 copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
Chris Lattner347bfda2001-07-02 05:46:47 +000053 return o;
54}
55
56void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
57 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
58 o << "=============================--------------------------------\n"
59 << "\nDominator Set For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000060 << "-------------------------------\n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000061 }
62}
63
64
65void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
66 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
67 I != E; ++I) {
68 o << "=============================--------------------------------\n"
69 << "\nImmediate Dominator For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000070 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000071 }
72}
73
74
Chris Lattner3d980492001-07-03 05:36:34 +000075static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
76 return o << Node->getNode() << "\n------------------------------------------\n";
77
78}
Chris Lattner347bfda2001-07-02 05:46:47 +000079
Chris Lattner3d980492001-07-03 05:36:34 +000080static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
81 unsigned Lev) {
82 o << "Level #" << Lev << ": " << N;
83 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
84 I != E; ++I) {
85 PrintDomTree(*I, o, Lev+1);
86 }
87}
88
89void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
90 o << "=============================--------------------------------\n"
91 << "Inorder Dominator Tree:\n";
92 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +000093}
94
95void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
96 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
97 I != E; ++I) {
98 o << "=============================--------------------------------\n"
99 << "\nDominance Frontier For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +0000100 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +0000101 }
102}
103
Chris Lattnera2eb2592001-11-26 18:53:29 +0000104
105//===----------------------------------------------------------------------===//
106// Loop Printing Routines
107//===----------------------------------------------------------------------===//
108
109void cfg::WriteToOutput(const Loop *L, ostream &o) {
110 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
111
112 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
113 if (i) o << ",";
114 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
115 }
Chris Lattner697954c2002-01-20 22:54:45 +0000116 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000117
118 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000119 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000120}
121
122void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
123 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000124 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000125}
126
127
128
129//===----------------------------------------------------------------------===//
130// Induction Variable Printing Routines
131//===----------------------------------------------------------------------===//
132
133void WriteToOutput(const InductionVariable &IV, ostream &o) {
134 switch (IV.InductionType) {
135 case InductionVariable::Cannonical: o << "Cannonical "; break;
136 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
137 case InductionVariable::Linear: o << "Linear "; break;
138 case InductionVariable::Unknown: o << "Unrecognized "; break;
139 }
140 o << "Induction Variable";
141 if (IV.Phi) {
142 WriteAsOperand(o, (const Value*)IV.Phi);
143 o << ":\n" << (const Value*)IV.Phi;
144 } else {
Chris Lattner697954c2002-01-20 22:54:45 +0000145 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000146 }
147 if (IV.InductionType == InductionVariable::Unknown) return;
148
149 o << " Start ="; WriteAsOperand(o, IV.Start);
150 o << " Step =" ; WriteAsOperand(o, IV.Step);
Chris Lattner697954c2002-01-20 22:54:45 +0000151 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000152}