blob: 3d9134f0dc418b896a5ef579fbcb0571abab0b4c [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>
15
Chris Lattnere6850232001-07-03 15:28:35 +000016//===----------------------------------------------------------------------===//
17// Interval Printing Routines
18//===----------------------------------------------------------------------===//
19
Chris Lattnerda956802001-06-21 05:27:22 +000020void cfg::WriteToOutput(const Interval *I, ostream &o) {
21 o << "-------------------------------------------------------------\n"
22 << "Interval Contents:\n";
23
24 // Print out all of the basic blocks in the interval...
25 copy(I->Nodes.begin(), I->Nodes.end(),
26 ostream_iterator<BasicBlock*>(o, "\n"));
27
28 o << "Interval Predecessors:\n";
29 copy(I->Predecessors.begin(), I->Predecessors.end(),
30 ostream_iterator<BasicBlock*>(o, "\n"));
31
32 o << "Interval Successors:\n";
33 copy(I->Successors.begin(), I->Successors.end(),
34 ostream_iterator<BasicBlock*>(o, "\n"));
35}
Chris Lattner347bfda2001-07-02 05:46:47 +000036
Chris Lattnere6850232001-07-03 15:28:35 +000037void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
38 copy(IP.begin(), IP.end(), ostream_iterator<const Interval *>(o, "\n"));
39}
40
41
42
43//===----------------------------------------------------------------------===//
44// Dominator Printing Routines
45//===----------------------------------------------------------------------===//
46
Chris Lattner347bfda2001-07-02 05:46:47 +000047ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
48 copy(BBs.begin(), BBs.end(), ostream_iterator<const BasicBlock*>(o, "\n"));
49 return o;
50}
51
52void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
53 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
54 o << "=============================--------------------------------\n"
55 << "\nDominator Set For Basic Block\n" << I->first
56 << "-------------------------------\n" << I->second << endl;
57 }
58}
59
60
61void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
62 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
63 I != E; ++I) {
64 o << "=============================--------------------------------\n"
65 << "\nImmediate Dominator For Basic Block\n" << I->first
66 << "is: \n" << I->second << endl;
67 }
68}
69
70
Chris Lattner3d980492001-07-03 05:36:34 +000071static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
72 return o << Node->getNode() << "\n------------------------------------------\n";
73
74}
Chris Lattner347bfda2001-07-02 05:46:47 +000075
Chris Lattner3d980492001-07-03 05:36:34 +000076static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
77 unsigned Lev) {
78 o << "Level #" << Lev << ": " << N;
79 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
80 I != E; ++I) {
81 PrintDomTree(*I, o, Lev+1);
82 }
83}
84
85void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
86 o << "=============================--------------------------------\n"
87 << "Inorder Dominator Tree:\n";
88 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +000089}
90
91void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
92 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
93 I != E; ++I) {
94 o << "=============================--------------------------------\n"
95 << "\nDominance Frontier For Basic Block\n" << I->first
96 << "is: \n" << I->second << endl;
97 }
98}
99
Chris Lattnera2eb2592001-11-26 18:53:29 +0000100
101//===----------------------------------------------------------------------===//
102// Loop Printing Routines
103//===----------------------------------------------------------------------===//
104
105void cfg::WriteToOutput(const Loop *L, ostream &o) {
106 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
107
108 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
109 if (i) o << ",";
110 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
111 }
112 o << endl;
113
114 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
115 ostream_iterator<const Loop*>(o, "\n"));
116}
117
118void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
119 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
120 ostream_iterator<const Loop*>(o, "\n"));
121}
122
123
124
125//===----------------------------------------------------------------------===//
126// Induction Variable Printing Routines
127//===----------------------------------------------------------------------===//
128
129void WriteToOutput(const InductionVariable &IV, ostream &o) {
130 switch (IV.InductionType) {
131 case InductionVariable::Cannonical: o << "Cannonical "; break;
132 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
133 case InductionVariable::Linear: o << "Linear "; break;
134 case InductionVariable::Unknown: o << "Unrecognized "; break;
135 }
136 o << "Induction Variable";
137 if (IV.Phi) {
138 WriteAsOperand(o, (const Value*)IV.Phi);
139 o << ":\n" << (const Value*)IV.Phi;
140 } else {
141 o << endl;
142 }
143 if (IV.InductionType == InductionVariable::Unknown) return;
144
145 o << " Start ="; WriteAsOperand(o, IV.Start);
146 o << " Step =" ; WriteAsOperand(o, IV.Step);
147 o << endl;
148}