Add #includes that were pruned from already #included files
[oota-llvm.git] / lib / Analysis / Writer.cpp
1 //===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
2 //
3 // This library file implements analysis result printing support for 
4 // llvm/Analysis/Writer.h
5 //
6 //===----------------------------------------------------------------------===//
7
8 #include "llvm/Analysis/Writer.h"
9 #include "llvm/Analysis/IntervalPartition.h"
10 #include "llvm/Analysis/Dominators.h"
11 #include "llvm/Analysis/LoopInfo.h"
12 #include "llvm/Analysis/InductionVariable.h"
13 #include "llvm/Assembly/Writer.h"
14 #include <iterator>
15 #include <algorithm>
16 #include <string>
17 using std::ostream;
18 using std::set;
19 using std::vector;
20 using std::string;
21
22 //===----------------------------------------------------------------------===//
23 //  Interval Printing Routines
24 //===----------------------------------------------------------------------===//
25
26 void cfg::WriteToOutput(const Interval *I, ostream &o) {
27   o << "-------------------------------------------------------------\n"
28        << "Interval Contents:\n";
29   
30   // Print out all of the basic blocks in the interval...
31   copy(I->Nodes.begin(), I->Nodes.end(), 
32        std::ostream_iterator<BasicBlock*>(o, "\n"));
33
34   o << "Interval Predecessors:\n";
35   copy(I->Predecessors.begin(), I->Predecessors.end(), 
36        std::ostream_iterator<BasicBlock*>(o, "\n"));
37   
38   o << "Interval Successors:\n";
39   copy(I->Successors.begin(), I->Successors.end(), 
40        std::ostream_iterator<BasicBlock*>(o, "\n"));
41 }
42
43 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
44   copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
45 }
46
47
48
49 //===----------------------------------------------------------------------===//
50 //  Dominator Printing Routines
51 //===----------------------------------------------------------------------===//
52
53 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
54   copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
55   return o;
56 }
57
58 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
59   for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
60     o << "=============================--------------------------------\n"
61       << "\nDominator Set For Basic Block\n" << I->first
62       << "-------------------------------\n" << I->second << "\n";
63   }
64 }
65
66
67 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
68   for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
69        I != E; ++I) {
70     o << "=============================--------------------------------\n"
71       << "\nImmediate Dominator For Basic Block\n" << I->first
72       << "is: \n" << I->second << "\n";
73   }
74 }
75
76
77 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
78   return o << Node->getNode() << "\n------------------------------------------\n";
79            
80 }
81
82 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
83                          unsigned Lev) {
84   o << "Level #" << Lev << ":  " << N;
85   for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end(); 
86        I != E; ++I) {
87     PrintDomTree(*I, o, Lev+1);
88   }
89 }
90
91 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
92   o << "=============================--------------------------------\n"
93     << "Inorder Dominator Tree:\n";
94   PrintDomTree(DT[DT.getRoot()], o, 1);
95 }
96
97 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
98   for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
99        I != E; ++I) {
100     o << "=============================--------------------------------\n"
101       << "\nDominance Frontier For Basic Block\n" << I->first
102       << "is: \n" << I->second << "\n";
103   }
104 }
105
106
107 //===----------------------------------------------------------------------===//
108 //  Loop Printing Routines
109 //===----------------------------------------------------------------------===//
110
111 void cfg::WriteToOutput(const Loop *L, ostream &o) {
112   o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
113
114   for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
115     if (i) o << ",";
116     WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
117   }
118   o << "\n";
119
120   copy(L->getSubLoops().begin(), L->getSubLoops().end(),
121        std::ostream_iterator<const Loop*>(o, "\n"));
122 }
123
124 void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
125   copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
126        std::ostream_iterator<const Loop*>(o, "\n"));
127 }
128
129
130
131 //===----------------------------------------------------------------------===//
132 //  Induction Variable Printing Routines
133 //===----------------------------------------------------------------------===//
134
135 void WriteToOutput(const InductionVariable &IV, ostream &o) {
136   switch (IV.InductionType) {
137   case InductionVariable::Cannonical:   o << "Cannonical ";   break;
138   case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
139   case InductionVariable::Linear:       o << "Linear ";       break;
140   case InductionVariable::Unknown:      o << "Unrecognized "; break;
141   }
142   o << "Induction Variable";
143   if (IV.Phi) {
144     WriteAsOperand(o, (const Value*)IV.Phi);
145     o << ":\n" << (const Value*)IV.Phi;
146   } else {
147     o << "\n";
148   }
149   if (IV.InductionType == InductionVariable::Unknown) return;
150
151   o << "  Start ="; WriteAsOperand(o, IV.Start);
152   o << "  Step =" ; WriteAsOperand(o, IV.Step);
153   o << "\n";
154 }