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"
22 //===----------------------------------------------------------------------===//
23 // Interval Printing Routines
24 //===----------------------------------------------------------------------===//
26 void cfg::WriteToOutput(const Interval *I, ostream &o) {
27 o << "-------------------------------------------------------------\n"
28 << "Interval Contents:\n";
30 // Print out all of the basic blocks in the interval...
31 copy(I->Nodes.begin(), I->Nodes.end(),
32 std::ostream_iterator<BasicBlock*>(o, "\n"));
34 o << "Interval Predecessors:\n";
35 copy(I->Predecessors.begin(), I->Predecessors.end(),
36 std::ostream_iterator<BasicBlock*>(o, "\n"));
38 o << "Interval Successors:\n";
39 copy(I->Successors.begin(), I->Successors.end(),
40 std::ostream_iterator<BasicBlock*>(o, "\n"));
43 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
44 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
49 //===----------------------------------------------------------------------===//
50 // Dominator Printing Routines
51 //===----------------------------------------------------------------------===//
53 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
54 copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
58 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
59 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
60 o << "=============================--------------------------------\n"
61 << "\nDominator Set For Basic Block\n" << I->first
62 << "-------------------------------\n" << I->second << "\n";
67 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
68 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
70 o << "=============================--------------------------------\n"
71 << "\nImmediate Dominator For Basic Block\n" << I->first
72 << "is: \n" << I->second << "\n";
77 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
78 return o << Node->getNode() << "\n------------------------------------------\n";
82 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
84 o << "Level #" << Lev << ": " << N;
85 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
87 PrintDomTree(*I, o, Lev+1);
91 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
92 o << "=============================--------------------------------\n"
93 << "Inorder Dominator Tree:\n";
94 PrintDomTree(DT[DT.getRoot()], o, 1);
97 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
98 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
100 o << "=============================--------------------------------\n"
101 << "\nDominance Frontier For Basic Block\n" << I->first
102 << "is: \n" << I->second << "\n";
107 //===----------------------------------------------------------------------===//
108 // Loop Printing Routines
109 //===----------------------------------------------------------------------===//
111 void cfg::WriteToOutput(const Loop *L, ostream &o) {
112 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
114 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
116 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
120 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
121 std::ostream_iterator<const Loop*>(o, "\n"));
124 void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
125 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
126 std::ostream_iterator<const Loop*>(o, "\n"));
131 //===----------------------------------------------------------------------===//
132 // Induction Variable Printing Routines
133 //===----------------------------------------------------------------------===//
135 void WriteToOutput(const InductionVariable &IV, ostream &o) {
136 switch (IV.InductionType) {
137 case InductionVariable::Cannonical: o << "Cannonical "; break;
138 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
139 case InductionVariable::Linear: o << "Linear "; break;
140 case InductionVariable::Unknown: o << "Unrecognized "; break;
142 o << "Induction Variable";
144 WriteAsOperand(o, (const Value*)IV.Phi);
145 o << ":\n" << (const Value*)IV.Phi;
149 if (IV.InductionType == InductionVariable::Unknown) return;
151 o << " Start ="; WriteAsOperand(o, IV.Start);
152 o << " Step =" ; WriteAsOperand(o, IV.Step);