Code got moved from the lib/Assembly/Writer/IntervalWriter.cpp file to
[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/Interval.h"
10 #include "llvm/Analysis/Dominators.h"
11 #include <iterator>
12 #include <algorithm>
13
14 void cfg::WriteToOutput(const Interval *I, ostream &o) {
15   o << "-------------------------------------------------------------\n"
16        << "Interval Contents:\n";
17   
18   // Print out all of the basic blocks in the interval...
19   copy(I->Nodes.begin(), I->Nodes.end(), 
20        ostream_iterator<BasicBlock*>(o, "\n"));
21
22   o << "Interval Predecessors:\n";
23   copy(I->Predecessors.begin(), I->Predecessors.end(), 
24        ostream_iterator<BasicBlock*>(o, "\n"));
25   
26   o << "Interval Successors:\n";
27   copy(I->Successors.begin(), I->Successors.end(), 
28        ostream_iterator<BasicBlock*>(o, "\n"));
29 }
30
31 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
32   copy(BBs.begin(), BBs.end(), ostream_iterator<const BasicBlock*>(o, "\n"));
33   return o;
34 }
35
36 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
37   for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
38     o << "=============================--------------------------------\n"
39       << "\nDominator Set For Basic Block\n" << I->first
40       << "-------------------------------\n" << I->second << endl;
41   }
42 }
43
44
45 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
46   for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
47        I != E; ++I) {
48     o << "=============================--------------------------------\n"
49       << "\nImmediate Dominator For Basic Block\n" << I->first
50       << "is: \n" << I->second << endl;
51   }
52 }
53
54
55 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
56   return o << Node->getNode() << "\n------------------------------------------\n";
57            
58 }
59
60 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
61                          unsigned Lev) {
62   o << "Level #" << Lev << ":  " << N;
63   for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end(); 
64        I != E; ++I) {
65     PrintDomTree(*I, o, Lev+1);
66   }
67 }
68
69 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
70   o << "=============================--------------------------------\n"
71     << "Inorder Dominator Tree:\n";
72   PrintDomTree(DT[DT.getRoot()], o, 1);
73 }
74
75 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
76   for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
77        I != E; ++I) {
78     o << "=============================--------------------------------\n"
79       << "\nDominance Frontier For Basic Block\n" << I->first
80       << "is: \n" << I->second << endl;
81   }
82 }
83