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"
16 //===----------------------------------------------------------------------===//
17 // Interval Printing Routines
18 //===----------------------------------------------------------------------===//
20 void cfg::WriteToOutput(const Interval *I, ostream &o) {
21 o << "-------------------------------------------------------------\n"
22 << "Interval Contents:\n";
24 // Print out all of the basic blocks in the interval...
25 copy(I->Nodes.begin(), I->Nodes.end(),
26 ostream_iterator<BasicBlock*>(o, "\n"));
28 o << "Interval Predecessors:\n";
29 copy(I->Predecessors.begin(), I->Predecessors.end(),
30 ostream_iterator<BasicBlock*>(o, "\n"));
32 o << "Interval Successors:\n";
33 copy(I->Successors.begin(), I->Successors.end(),
34 ostream_iterator<BasicBlock*>(o, "\n"));
37 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
38 copy(IP.begin(), IP.end(), ostream_iterator<const Interval *>(o, "\n"));
43 //===----------------------------------------------------------------------===//
44 // Dominator Printing Routines
45 //===----------------------------------------------------------------------===//
47 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
48 copy(BBs.begin(), BBs.end(), ostream_iterator<const BasicBlock*>(o, "\n"));
52 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
53 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
54 o << "=============================--------------------------------\n"
55 << "\nDominator Set For Basic Block\n" << I->first
56 << "-------------------------------\n" << I->second << endl;
61 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
62 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
64 o << "=============================--------------------------------\n"
65 << "\nImmediate Dominator For Basic Block\n" << I->first
66 << "is: \n" << I->second << endl;
71 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
72 return o << Node->getNode() << "\n------------------------------------------\n";
76 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
78 o << "Level #" << Lev << ": " << N;
79 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
81 PrintDomTree(*I, o, Lev+1);
85 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
86 o << "=============================--------------------------------\n"
87 << "Inorder Dominator Tree:\n";
88 PrintDomTree(DT[DT.getRoot()], o, 1);
91 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
92 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
94 o << "=============================--------------------------------\n"
95 << "\nDominance Frontier For Basic Block\n" << I->first
96 << "is: \n" << I->second << endl;
101 //===----------------------------------------------------------------------===//
102 // Loop Printing Routines
103 //===----------------------------------------------------------------------===//
105 void cfg::WriteToOutput(const Loop *L, ostream &o) {
106 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
108 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
110 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
114 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
115 ostream_iterator<const Loop*>(o, "\n"));
118 void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
119 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
120 ostream_iterator<const Loop*>(o, "\n"));
125 //===----------------------------------------------------------------------===//
126 // Induction Variable Printing Routines
127 //===----------------------------------------------------------------------===//
129 void WriteToOutput(const InductionVariable &IV, ostream &o) {
130 switch (IV.InductionType) {
131 case InductionVariable::Cannonical: o << "Cannonical "; break;
132 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
133 case InductionVariable::Linear: o << "Linear "; break;
134 case InductionVariable::Unknown: o << "Unrecognized "; break;
136 o << "Induction Variable";
138 WriteAsOperand(o, (const Value*)IV.Phi);
139 o << ":\n" << (const Value*)IV.Phi;
143 if (IV.InductionType == InductionVariable::Unknown) return;
145 o << " Start ="; WriteAsOperand(o, IV.Start);
146 o << " Step =" ; WriteAsOperand(o, IV.Step);