blob: 80a8f91e47622ff4122f2e64cae156729e85026b [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 Lattner173e4242002-07-22 02:06:50 +000014#include "llvm/Module.h"
Chris Lattnerda956802001-06-21 05:27:22 +000015#include <iterator>
16#include <algorithm>
Chris Lattnerab448712002-04-08 21:56:50 +000017#include <string>
Anand Shuklaa9284032002-06-25 20:35:19 +000018#include <iostream>
Chris Lattner697954c2002-01-20 22:54:45 +000019using std::ostream;
20using std::set;
21using std::vector;
22using std::string;
Chris Lattnerda956802001-06-21 05:27:22 +000023
Chris Lattnere6850232001-07-03 15:28:35 +000024//===----------------------------------------------------------------------===//
25// Interval Printing Routines
26//===----------------------------------------------------------------------===//
27
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000028void WriteToOutput(const Interval *I, ostream &o) {
Chris Lattnerda956802001-06-21 05:27:22 +000029 o << "-------------------------------------------------------------\n"
30 << "Interval Contents:\n";
31
32 // Print out all of the basic blocks in the interval...
33 copy(I->Nodes.begin(), I->Nodes.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000034 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000035
36 o << "Interval Predecessors:\n";
37 copy(I->Predecessors.begin(), I->Predecessors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000038 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000039
40 o << "Interval Successors:\n";
41 copy(I->Successors.begin(), I->Successors.end(),
Chris Lattner697954c2002-01-20 22:54:45 +000042 std::ostream_iterator<BasicBlock*>(o, "\n"));
Chris Lattnerda956802001-06-21 05:27:22 +000043}
Chris Lattner347bfda2001-07-02 05:46:47 +000044
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000045void WriteToOutput(const IntervalPartition &IP, ostream &o) {
Chris Lattner697954c2002-01-20 22:54:45 +000046 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
Chris Lattnere6850232001-07-03 15:28:35 +000047}
48
49
50
51//===----------------------------------------------------------------------===//
52// Dominator Printing Routines
53//===----------------------------------------------------------------------===//
54
Chris Lattnera298d272002-04-28 00:15:57 +000055ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
Chris Lattner48746802002-05-08 23:11:08 +000056 for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
57 I != E; ++I) {
58 o << " ";
59 WriteAsOperand(o, (Value*)*I, false);
60 o << "\n";
61 }
Chris Lattner347bfda2001-07-02 05:46:47 +000062 return o;
63}
64
Chris Lattnerce6ef112002-07-26 18:40:14 +000065void WriteToOutput(const DominatorSetBase &DS, ostream &o) {
66 for (DominatorSetBase::const_iterator I = DS.begin(), E = DS.end();
67 I != E; ++I) {
Chris Lattner347bfda2001-07-02 05:46:47 +000068 o << "=============================--------------------------------\n"
69 << "\nDominator Set For Basic Block\n" << I->first
Chris Lattner697954c2002-01-20 22:54:45 +000070 << "-------------------------------\n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000071 }
72}
73
74
Chris Lattnerce6ef112002-07-26 18:40:14 +000075void WriteToOutput(const ImmediateDominatorsBase &ID, ostream &o) {
76 for (ImmediateDominatorsBase::const_iterator I = ID.begin(), E = ID.end();
Chris Lattner347bfda2001-07-02 05:46:47 +000077 I != E; ++I) {
78 o << "=============================--------------------------------\n"
Chris Lattner173e4242002-07-22 02:06:50 +000079 << "\nImmediate Dominator For Basic Block\n" << *I->first
80 << "is: \n" << *I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +000081 }
82}
83
84
Chris Lattnerce6ef112002-07-26 18:40:14 +000085static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
Chris Lattner3d980492001-07-03 05:36:34 +000086 return o << Node->getNode() << "\n------------------------------------------\n";
87
88}
Chris Lattner347bfda2001-07-02 05:46:47 +000089
Chris Lattnerce6ef112002-07-26 18:40:14 +000090static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
Chris Lattner1b7f7dc2002-04-28 16:21:30 +000091 unsigned Lev) {
Chris Lattner3d980492001-07-03 05:36:34 +000092 o << "Level #" << Lev << ": " << N;
Chris Lattnerce6ef112002-07-26 18:40:14 +000093 for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
Chris Lattner3d980492001-07-03 05:36:34 +000094 I != E; ++I) {
95 PrintDomTree(*I, o, Lev+1);
96 }
97}
98
Chris Lattnerce6ef112002-07-26 18:40:14 +000099void WriteToOutput(const DominatorTreeBase &DT, ostream &o) {
Chris Lattner3d980492001-07-03 05:36:34 +0000100 o << "=============================--------------------------------\n"
101 << "Inorder Dominator Tree:\n";
102 PrintDomTree(DT[DT.getRoot()], o, 1);
Chris Lattner347bfda2001-07-02 05:46:47 +0000103}
104
Chris Lattnerce6ef112002-07-26 18:40:14 +0000105void WriteToOutput(const DominanceFrontierBase &DF, ostream &o) {
106 for (DominanceFrontierBase::const_iterator I = DF.begin(), E = DF.end();
Chris Lattner347bfda2001-07-02 05:46:47 +0000107 I != E; ++I) {
108 o << "=============================--------------------------------\n"
Chris Lattner48746802002-05-08 23:11:08 +0000109 << "\nDominance Frontier For Basic Block\n";
110 WriteAsOperand(o, (Value*)I->first, false);
111 o << " is: \n" << I->second << "\n";
Chris Lattner347bfda2001-07-02 05:46:47 +0000112 }
113}
114
Chris Lattnera2eb2592001-11-26 18:53:29 +0000115
116//===----------------------------------------------------------------------===//
117// Loop Printing Routines
118//===----------------------------------------------------------------------===//
119
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000120void WriteToOutput(const Loop *L, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000121 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
122
123 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
124 if (i) o << ",";
125 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
126 }
Chris Lattner697954c2002-01-20 22:54:45 +0000127 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000128
129 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000130 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000131}
132
Chris Lattner1b7f7dc2002-04-28 16:21:30 +0000133void WriteToOutput(const LoopInfo &LI, ostream &o) {
Chris Lattnera2eb2592001-11-26 18:53:29 +0000134 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
Chris Lattner697954c2002-01-20 22:54:45 +0000135 std::ostream_iterator<const Loop*>(o, "\n"));
Chris Lattnera2eb2592001-11-26 18:53:29 +0000136}
137
138
139
140//===----------------------------------------------------------------------===//
141// Induction Variable Printing Routines
142//===----------------------------------------------------------------------===//
143
144void WriteToOutput(const InductionVariable &IV, ostream &o) {
145 switch (IV.InductionType) {
146 case InductionVariable::Cannonical: o << "Cannonical "; break;
147 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
148 case InductionVariable::Linear: o << "Linear "; break;
149 case InductionVariable::Unknown: o << "Unrecognized "; break;
150 }
151 o << "Induction Variable";
152 if (IV.Phi) {
153 WriteAsOperand(o, (const Value*)IV.Phi);
154 o << ":\n" << (const Value*)IV.Phi;
155 } else {
Chris Lattner697954c2002-01-20 22:54:45 +0000156 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000157 }
158 if (IV.InductionType == InductionVariable::Unknown) return;
159
160 o << " Start ="; WriteAsOperand(o, IV.Start);
161 o << " Step =" ; WriteAsOperand(o, IV.Step);
Chris Lattner697954c2002-01-20 22:54:45 +0000162 o << "\n";
Chris Lattnera2eb2592001-11-26 18:53:29 +0000163}