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