blob: b4d5375ebd80551b8bb37dc5f43701ab349d33cc [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 Lattnerab448712002-04-08 21:56:50 +000013#include "llvm/Assembly/Writer.h"
Chris Lattnerda956802001-06-21 05:27:22 +000014#include <iterator>
15#include <algorithm>
Chris Lattnerab448712002-04-08 21:56:50 +000016#include <string>
Chris Lattner697954c2002-01-20 22:54:45 +000017using std::ostream;
18using std::set;
19using std::vector;
20using std::string;
Chris Lattnerda956802001-06-21 05:27:22 +000021
Chris Lattnere6850232001-07-03 15:28:35 +000022//===----------------------------------------------------------------------===//
23// Interval Printing Routines
24//===----------------------------------------------------------------------===//
25
Chris Lattnerda956802001-06-21 05:27:22 +000026void 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(),
Chris Lattner697954c2002-01-20 22:54:45 +000032 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000033
34 o << "Interval Predecessors:\n";
35 copy(I->Predecessors.begin(), I->Predecessors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000036 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000037
38 o << "Interval Successors:\n";
39 copy(I->Successors.begin(), I->Successors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000040 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000041}
Chris Lattner347bfda2001-07-02 05:46:47 +000042
Chris Lattnere6850232001-07-03 15:28:35 +000043void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
Chris Lattner697954c2002-01-20 22:54:45 +000044 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
Chris Lattnere6850232001-07-03 15:28:35 +000045}
46
47
48
49//===----------------------------------------------------------------------===//
50// Dominator Printing Routines
51//===----------------------------------------------------------------------===//
52
Chris Lattner347bfda2001-07-02 05:46:47 +000053ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
Chris Lattner697954c2002-01-20 22:54:45 +000054 copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
Chris Lattner347bfda2001-07-02 05:46:47 +000055 return o;
56}
57
58void 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
Chris Lattner697954c2002-01-20 22:54:45 +000062 << "-------------------------------\n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000063 }
64}
65
66
67void 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
Chris Lattner697954c2002-01-20 22:54:45 +000072 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000073 }
74}
75
76
Chris Lattner3d980492001-07-03 05:36:34 +000077static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
78 return o << Node->getNode() << "\n------------------------------------------\n";
79
80}
Chris Lattner347bfda2001-07-02 05:46:47 +000081
Chris Lattner3d980492001-07-03 05:36:34 +000082static 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
91void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
92 o << "=============================--------------------------------\n"
93 << "Inorder Dominator Tree:\n";
94 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +000095}
96
97void 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
Chris Lattner697954c2002-01-20 22:54:45 +0000102 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +0000103 }
104}
105
Chris Lattnera2eb2592001-11-26 18:53:29 +0000106
107//===----------------------------------------------------------------------===//
108// Loop Printing Routines
109//===----------------------------------------------------------------------===//
110
111void 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 }
Chris Lattner697954c2002-01-20 22:54:45 +0000118 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000119
120 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000121 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000122}
123
124void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
125 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000126 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000127}
128
129
130
131//===----------------------------------------------------------------------===//
132// Induction Variable Printing Routines
133//===----------------------------------------------------------------------===//
134
135void 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 {
Chris Lattner697954c2002-01-20 22:54:45 +0000147 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000148 }
149 if (IV.InductionType == InductionVariable::Unknown) return;
150
151 o << " Start ="; WriteAsOperand(o, IV.Start);
152 o << " Step =" ; WriteAsOperand(o, IV.Step);
Chris Lattner697954c2002-01-20 22:54:45 +0000153 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000154}