blob: 3624dd1e6a1e7454ec34ced7829fa8752dcf6d2f [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 Lattner1b7f7dc2002-04-28 16:21:30 +000026void WriteToOutput(const Interval *I, ostream &o) {
Chris Lattnerda956802001-06-21 05:27:22 +000027 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 Lattner1b7f7dc2002-04-28 16:21:30 +000043void 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 Lattnera298d272002-04-28 00:15:57 +000053ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
Chris Lattner48746802002-05-08 23:11:08 +000054 for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
55 I != E; ++I) {
56 o << " ";
57 WriteAsOperand(o, (Value*)*I, false);
58 o << "\n";
59 }
Chris Lattner347bfda2001-07-02 05:46:47 +000060 return o;
61}
62
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000063void WriteToOutput(const DominatorSet &DS, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +000064 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
65 o << "=============================--------------------------------\n"
66 << "\nDominator Set For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000067 << "-------------------------------\n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000068 }
69}
70
71
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000072void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +000073 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
74 I != E; ++I) {
75 o << "=============================--------------------------------\n"
76 << "\nImmediate Dominator For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000077 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000078 }
79}
80
81
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000082static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
Chris Lattner3d980492001-07-03 05:36:34 +000083 return o << Node->getNode() << "\n------------------------------------------\n";
84
85}
Chris Lattner347bfda2001-07-02 05:46:47 +000086
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000087static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
88 unsigned Lev) {
Chris Lattner3d980492001-07-03 05:36:34 +000089 o << "Level #" << Lev << ": " << N;
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000090 for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
Chris Lattner3d980492001-07-03 05:36:34 +000091 I != E; ++I) {
92 PrintDomTree(*I, o, Lev+1);
93 }
94}
95
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000096void WriteToOutput(const DominatorTree &DT, ostream &o) {
Chris Lattner3d980492001-07-03 05:36:34 +000097 o << "=============================--------------------------------\n"
98 << "Inorder Dominator Tree:\n";
99 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +0000100}
101
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000102void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +0000103 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
104 I != E; ++I) {
105 o << "=============================--------------------------------\n"
Chris Lattner48746802002-05-08 23:11:08 +0000106 << "\nDominance Frontier For Basic Block\n";
107 WriteAsOperand(o, (Value*)I->first, false);
108 o << " is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +0000109 }
110}
111
Chris Lattnera2eb2592001-11-26 18:53:29 +0000112
113//===----------------------------------------------------------------------===//
114// Loop Printing Routines
115//===----------------------------------------------------------------------===//
116
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000117void WriteToOutput(const Loop *L, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000118 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
119
120 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
121 if (i) o << ",";
122 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
123 }
Chris Lattner697954c2002-01-20 22:54:45 +0000124 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000125
126 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000127 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000128}
129
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000130void WriteToOutput(const LoopInfo &LI, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000131 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000132 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000133}
134
135
136
137//===----------------------------------------------------------------------===//
138// Induction Variable Printing Routines
139//===----------------------------------------------------------------------===//
140
141void WriteToOutput(const InductionVariable &IV, ostream &o) {
142 switch (IV.InductionType) {
143 case InductionVariable::Cannonical: o << "Cannonical "; break;
144 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
145 case InductionVariable::Linear: o << "Linear "; break;
146 case InductionVariable::Unknown: o << "Unrecognized "; break;
147 }
148 o << "Induction Variable";
149 if (IV.Phi) {
150 WriteAsOperand(o, (const Value*)IV.Phi);
151 o << ":\n" << (const Value*)IV.Phi;
152 } else {
Chris Lattner697954c2002-01-20 22:54:45 +0000153 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000154 }
155 if (IV.InductionType == InductionVariable::Unknown) return;
156
157 o << " Start ="; WriteAsOperand(o, IV.Start);
158 o << " Step =" ; WriteAsOperand(o, IV.Step);
Chris Lattner697954c2002-01-20 22:54:45 +0000159 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000160}