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"
20 //===----------------------------------------------------------------------===//
21 // Interval Printing Routines
22 //===----------------------------------------------------------------------===//
24 void cfg::WriteToOutput(const Interval *I, ostream &o) {
25 o << "-------------------------------------------------------------\n"
26 << "Interval Contents:\n";
28 // Print out all of the basic blocks in the interval...
29 copy(I->Nodes.begin(), I->Nodes.end(),
30 std::ostream_iterator<BasicBlock*>(o, "\n"));
32 o << "Interval Predecessors:\n";
33 copy(I->Predecessors.begin(), I->Predecessors.end(),
34 std::ostream_iterator<BasicBlock*>(o, "\n"));
36 o << "Interval Successors:\n";
37 copy(I->Successors.begin(), I->Successors.end(),
38 std::ostream_iterator<BasicBlock*>(o, "\n"));
41 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
42 copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
47 //===----------------------------------------------------------------------===//
48 // Dominator Printing Routines
49 //===----------------------------------------------------------------------===//
51 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
52 copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
56 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
57 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
58 o << "=============================--------------------------------\n"
59 << "\nDominator Set For Basic Block\n" << I->first
60 << "-------------------------------\n" << I->second << "\n";
65 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
66 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
68 o << "=============================--------------------------------\n"
69 << "\nImmediate Dominator For Basic Block\n" << I->first
70 << "is: \n" << I->second << "\n";
75 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
76 return o << Node->getNode() << "\n------------------------------------------\n";
80 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
82 o << "Level #" << Lev << ": " << N;
83 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
85 PrintDomTree(*I, o, Lev+1);
89 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
90 o << "=============================--------------------------------\n"
91 << "Inorder Dominator Tree:\n";
92 PrintDomTree(DT[DT.getRoot()], o, 1);
95 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
96 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
98 o << "=============================--------------------------------\n"
99 << "\nDominance Frontier For Basic Block\n" << I->first
100 << "is: \n" << I->second << "\n";
105 //===----------------------------------------------------------------------===//
106 // Loop Printing Routines
107 //===----------------------------------------------------------------------===//
109 void cfg::WriteToOutput(const Loop *L, ostream &o) {
110 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
112 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
114 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
118 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
119 std::ostream_iterator<const Loop*>(o, "\n"));
122 void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
123 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
124 std::ostream_iterator<const Loop*>(o, "\n"));
129 //===----------------------------------------------------------------------===//
130 // Induction Variable Printing Routines
131 //===----------------------------------------------------------------------===//
133 void WriteToOutput(const InductionVariable &IV, ostream &o) {
134 switch (IV.InductionType) {
135 case InductionVariable::Cannonical: o << "Cannonical "; break;
136 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
137 case InductionVariable::Linear: o << "Linear "; break;
138 case InductionVariable::Unknown: o << "Unrecognized "; break;
140 o << "Induction Variable";
142 WriteAsOperand(o, (const Value*)IV.Phi);
143 o << ":\n" << (const Value*)IV.Phi;
147 if (IV.InductionType == InductionVariable::Unknown) return;
149 o << " Start ="; WriteAsOperand(o, IV.Start);
150 o << " Step =" ; WriteAsOperand(o, IV.Step);