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"
23 //===----------------------------------------------------------------------===//
24 // Interval Printing Routines
25 //===----------------------------------------------------------------------===//
27 void WriteToOutput(const Interval *I, ostream &o) {
28 o << "-------------------------------------------------------------\n"
29 << "Interval Contents:\n";
31 // Print out all of the basic blocks in the interval...
32 copy(I->Nodes.begin(), I->Nodes.end(),
33 std::ostream_iterator<BasicBlock*>(o, "\n"));
35 o << "Interval Predecessors:\n";
36 copy(I->Predecessors.begin(), I->Predecessors.end(),
37 std::ostream_iterator<BasicBlock*>(o, "\n"));
39 o << "Interval Successors:\n";
40 copy(I->Successors.begin(), I->Successors.end(),
41 std::ostream_iterator<BasicBlock*>(o, "\n"));
44 void WriteToOutput(const IntervalPartition &IP, ostream &o) {
45 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
50 //===----------------------------------------------------------------------===//
51 // Dominator Printing Routines
52 //===----------------------------------------------------------------------===//
54 ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
55 for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
58 WriteAsOperand(o, (Value*)*I, false);
64 void WriteToOutput(const DominatorSet &DS, ostream &o) {
65 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
68 << "-------------------------------\n" << I->second << "\n";
73 void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
74 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
76 o << "=============================--------------------------------\n"
77 << "\nImmediate Dominator For Basic Block\n" << I->first
78 << "is: \n" << I->second << "\n";
83 static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
84 return o << Node->getNode() << "\n------------------------------------------\n";
88 static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
90 o << "Level #" << Lev << ": " << N;
91 for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
93 PrintDomTree(*I, o, Lev+1);
97 void WriteToOutput(const DominatorTree &DT, ostream &o) {
98 o << "=============================--------------------------------\n"
99 << "Inorder Dominator Tree:\n";
100 PrintDomTree(DT[DT.getRoot()], o, 1);
103 void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
104 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
106 o << "=============================--------------------------------\n"
107 << "\nDominance Frontier For Basic Block\n";
108 WriteAsOperand(o, (Value*)I->first, false);
109 o << " is: \n" << I->second << "\n";
114 //===----------------------------------------------------------------------===//
115 // Loop Printing Routines
116 //===----------------------------------------------------------------------===//
118 void WriteToOutput(const Loop *L, ostream &o) {
119 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
121 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
123 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
127 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
128 std::ostream_iterator<const Loop*>(o, "\n"));
131 void WriteToOutput(const LoopInfo &LI, ostream &o) {
132 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
133 std::ostream_iterator<const Loop*>(o, "\n"));
138 //===----------------------------------------------------------------------===//
139 // Induction Variable Printing Routines
140 //===----------------------------------------------------------------------===//
142 void 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;
149 o << "Induction Variable";
151 WriteAsOperand(o, (const Value*)IV.Phi);
152 o << ":\n" << (const Value*)IV.Phi;
156 if (IV.InductionType == InductionVariable::Unknown) return;
158 o << " Start ="; WriteAsOperand(o, IV.Start);
159 o << " Step =" ; WriteAsOperand(o, IV.Step);