1 //===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
3 // This library file implements analysis result printing support for
4 // llvm/Analysis/Writer.h
6 //===----------------------------------------------------------------------===//
8 #include "llvm/Analysis/Writer.h"
9 #include "llvm/Analysis/IntervalPartition.h"
10 #include "llvm/Analysis/Dominators.h"
11 #include "llvm/Analysis/LoopInfo.h"
12 #include "llvm/Analysis/InductionVariable.h"
13 #include "llvm/Assembly/Writer.h"
14 #include "llvm/Module.h"
24 //===----------------------------------------------------------------------===//
25 // Interval Printing Routines
26 //===----------------------------------------------------------------------===//
28 void WriteToOutput(const Interval *I, ostream &o) {
29 o << "-------------------------------------------------------------\n"
30 << "Interval Contents:\n";
32 // Print out all of the basic blocks in the interval...
33 copy(I->Nodes.begin(), I->Nodes.end(),
34 std::ostream_iterator<BasicBlock*>(o, "\n"));
36 o << "Interval Predecessors:\n";
37 copy(I->Predecessors.begin(), I->Predecessors.end(),
38 std::ostream_iterator<BasicBlock*>(o, "\n"));
40 o << "Interval Successors:\n";
41 copy(I->Successors.begin(), I->Successors.end(),
42 std::ostream_iterator<BasicBlock*>(o, "\n"));
45 void WriteToOutput(const IntervalPartition &IP, ostream &o) {
46 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
51 //===----------------------------------------------------------------------===//
52 // Dominator Printing Routines
53 //===----------------------------------------------------------------------===//
55 ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
56 for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
59 WriteAsOperand(o, (Value*)*I, false);
65 void WriteToOutput(const DominatorSetBase &DS, ostream &o) {
66 for (DominatorSetBase::const_iterator I = DS.begin(), E = DS.end();
68 o << "=============================--------------------------------\n"
69 << "\nDominator Set For Basic Block\n" << I->first
70 << "-------------------------------\n" << I->second << "\n";
75 void WriteToOutput(const ImmediateDominatorsBase &ID, ostream &o) {
76 for (ImmediateDominatorsBase::const_iterator I = ID.begin(), E = ID.end();
78 o << "=============================--------------------------------\n"
79 << "\nImmediate Dominator For Basic Block\n" << *I->first
80 << "is: \n" << *I->second << "\n";
85 static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
86 return o << Node->getNode() << "\n------------------------------------------\n";
90 static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
92 o << "Level #" << Lev << ": " << N;
93 for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
95 PrintDomTree(*I, o, Lev+1);
99 void WriteToOutput(const DominatorTreeBase &DT, ostream &o) {
100 o << "=============================--------------------------------\n"
101 << "Inorder Dominator Tree:\n";
102 PrintDomTree(DT[DT.getRoot()], o, 1);
105 void WriteToOutput(const DominanceFrontierBase &DF, ostream &o) {
106 for (DominanceFrontierBase::const_iterator I = DF.begin(), E = DF.end();
108 o << "=============================--------------------------------\n"
109 << "\nDominance Frontier For Basic Block\n";
110 WriteAsOperand(o, (Value*)I->first, false);
111 o << " is: \n" << I->second << "\n";
116 //===----------------------------------------------------------------------===//
117 // Loop Printing Routines
118 //===----------------------------------------------------------------------===//
120 void WriteToOutput(const Loop *L, ostream &o) {
121 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
123 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
125 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
129 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
130 std::ostream_iterator<const Loop*>(o, "\n"));
133 void WriteToOutput(const LoopInfo &LI, ostream &o) {
134 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
135 std::ostream_iterator<const Loop*>(o, "\n"));
140 //===----------------------------------------------------------------------===//
141 // Induction Variable Printing Routines
142 //===----------------------------------------------------------------------===//
144 void 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;
151 o << "Induction Variable";
153 WriteAsOperand(o, (const Value*)IV.Phi);
154 o << ":\n" << (const Value*)IV.Phi;
158 if (IV.InductionType == InductionVariable::Unknown) return;
160 o << " Start ="; WriteAsOperand(o, IV.Start);
161 o << " Step =" ; WriteAsOperand(o, IV.Step);