blob: 88561ca7d26c09bfe105bc4a7e029d7d3d2e6a5a [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>
Anand Shuklaa9284032002-06-25 20:35:19 +000017#include <iostream>
Chris Lattner697954c2002-01-20 22:54:45 +000018using std::ostream;
19using std::set;
20using std::vector;
21using std::string;
Chris Lattnerda956802001-06-21 05:27:22 +000022
Chris Lattnere6850232001-07-03 15:28:35 +000023//===----------------------------------------------------------------------===//
24// Interval Printing Routines
25//===----------------------------------------------------------------------===//
26
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000027void WriteToOutput(const Interval *I, ostream &o) {
Chris Lattnerda956802001-06-21 05:27:22 +000028 o << "-------------------------------------------------------------\n"
29 << "Interval Contents:\n";
30
31 // Print out all of the basic blocks in the interval...
32 copy(I->Nodes.begin(), I->Nodes.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000033 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000034
35 o << "Interval Predecessors:\n";
36 copy(I->Predecessors.begin(), I->Predecessors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000037 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000038
39 o << "Interval Successors:\n";
40 copy(I->Successors.begin(), I->Successors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000041 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000042}
Chris Lattner347bfda2001-07-02 05:46:47 +000043
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000044void WriteToOutput(const IntervalPartition &IP, ostream &o) {
Chris Lattner697954c2002-01-20 22:54:45 +000045 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
Chris Lattnere6850232001-07-03 15:28:35 +000046}
47
48
49
50//===----------------------------------------------------------------------===//
51// Dominator Printing Routines
52//===----------------------------------------------------------------------===//
53
Chris Lattnera298d272002-04-28 00:15:57 +000054ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
Chris Lattner48746802002-05-08 23:11:08 +000055 for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
56 I != E; ++I) {
57 o << " ";
58 WriteAsOperand(o, (Value*)*I, false);
59 o << "\n";
60 }
Chris Lattner347bfda2001-07-02 05:46:47 +000061 return o;
62}
63
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000064void WriteToOutput(const DominatorSet &DS, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +000065 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
66 o << "=============================--------------------------------\n"
67 << "\nDominator Set For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000068 << "-------------------------------\n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000069 }
70}
71
72
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000073void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +000074 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
75 I != E; ++I) {
76 o << "=============================--------------------------------\n"
77 << "\nImmediate Dominator For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000078 << "is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000079 }
80}
81
82
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000083static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
Chris Lattner3d980492001-07-03 05:36:34 +000084 return o << Node->getNode() << "\n------------------------------------------\n";
85
86}
Chris Lattner347bfda2001-07-02 05:46:47 +000087
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000088static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
89 unsigned Lev) {
Chris Lattner3d980492001-07-03 05:36:34 +000090 o << "Level #" << Lev << ": " << N;
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000091 for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
Chris Lattner3d980492001-07-03 05:36:34 +000092 I != E; ++I) {
93 PrintDomTree(*I, o, Lev+1);
94 }
95}
96
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000097void WriteToOutput(const DominatorTree &DT, ostream &o) {
Chris Lattner3d980492001-07-03 05:36:34 +000098 o << "=============================--------------------------------\n"
99 << "Inorder Dominator Tree:\n";
100 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +0000101}
102
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000103void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
Chris Lattner347bfda2001-07-02 05:46:47 +0000104 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
105 I != E; ++I) {
106 o << "=============================--------------------------------\n"
Chris Lattner48746802002-05-08 23:11:08 +0000107 << "\nDominance Frontier For Basic Block\n";
108 WriteAsOperand(o, (Value*)I->first, false);
109 o << " is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +0000110 }
111}
112
Chris Lattnera2eb2592001-11-26 18:53:29 +0000113
114//===----------------------------------------------------------------------===//
115// Loop Printing Routines
116//===----------------------------------------------------------------------===//
117
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000118void WriteToOutput(const Loop *L, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000119 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
120
121 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
122 if (i) o << ",";
123 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
124 }
Chris Lattner697954c2002-01-20 22:54:45 +0000125 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000126
127 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000128 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000129}
130
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000131void WriteToOutput(const LoopInfo &LI, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000132 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000133 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000134}
135
136
137
138//===----------------------------------------------------------------------===//
139// Induction Variable Printing Routines
140//===----------------------------------------------------------------------===//
141
142void WriteToOutput(const InductionVariable &IV, ostream &o) {
143 switch (IV.InductionType) {
144 case InductionVariable::Cannonical: o << "Cannonical "; break;
145 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
146 case InductionVariable::Linear: o << "Linear "; break;
147 case InductionVariable::Unknown: o << "Unrecognized "; break;
148 }
149 o << "Induction Variable";
150 if (IV.Phi) {
151 WriteAsOperand(o, (const Value*)IV.Phi);
152 o << ":\n" << (const Value*)IV.Phi;
153 } else {
Chris Lattner697954c2002-01-20 22:54:45 +0000154 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000155 }
156 if (IV.InductionType == InductionVariable::Unknown) return;
157
158 o << " Start ="; WriteAsOperand(o, IV.Start);
159 o << " Step =" ; WriteAsOperand(o, IV.Step);
Chris Lattner697954c2002-01-20 22:54:45 +0000160 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000161}