Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 1 | //===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=// |
Chris Lattner | da95680 | 2001-06-21 05:27:22 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 3 | // This library file implements analysis result printing support for |
| 4 | // llvm/Analysis/Writer.h |
Chris Lattner | da95680 | 2001-06-21 05:27:22 +0000 | [diff] [blame] | 5 | // |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | |
Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 8 | #include "llvm/Analysis/Writer.h" |
Chris Lattner | e685023 | 2001-07-03 15:28:35 +0000 | [diff] [blame] | 9 | #include "llvm/Analysis/IntervalPartition.h" |
Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 10 | #include "llvm/Analysis/Dominators.h" |
Chris Lattner | a2eb259 | 2001-11-26 18:53:29 +0000 | [diff] [blame^] | 11 | #include "llvm/Analysis/LoopInfo.h" |
| 12 | #include "llvm/Analysis/InductionVariable.h" |
Chris Lattner | da95680 | 2001-06-21 05:27:22 +0000 | [diff] [blame] | 13 | #include <iterator> |
| 14 | #include <algorithm> |
| 15 | |
Chris Lattner | e685023 | 2001-07-03 15:28:35 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | // Interval Printing Routines |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Chris Lattner | da95680 | 2001-06-21 05:27:22 +0000 | [diff] [blame] | 20 | void cfg::WriteToOutput(const Interval *I, ostream &o) { |
| 21 | o << "-------------------------------------------------------------\n" |
| 22 | << "Interval Contents:\n"; |
| 23 | |
| 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")); |
| 27 | |
| 28 | o << "Interval Predecessors:\n"; |
| 29 | copy(I->Predecessors.begin(), I->Predecessors.end(), |
| 30 | ostream_iterator<BasicBlock*>(o, "\n")); |
| 31 | |
| 32 | o << "Interval Successors:\n"; |
| 33 | copy(I->Successors.begin(), I->Successors.end(), |
| 34 | ostream_iterator<BasicBlock*>(o, "\n")); |
| 35 | } |
Chris Lattner | 347bfda | 2001-07-02 05:46:47 +0000 | [diff] [blame] | 36 | |
Chris Lattner | e685023 | 2001-07-03 15:28:35 +0000 | [diff] [blame] | 37 | void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) { |
| 38 | copy(IP.begin(), IP.end(), ostream_iterator<const Interval *>(o, "\n")); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | // Dominator Printing Routines |
| 45 | //===----------------------------------------------------------------------===// |
| 46 | |
Chris Lattner | 347bfda | 2001-07-02 05:46:47 +0000 | [diff] [blame] | 47 | ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) { |
| 48 | copy(BBs.begin(), BBs.end(), ostream_iterator<const BasicBlock*>(o, "\n")); |
| 49 | return o; |
| 50 | } |
| 51 | |
| 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; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) { |
| 62 | for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end(); |
| 63 | I != E; ++I) { |
| 64 | o << "=============================--------------------------------\n" |
| 65 | << "\nImmediate Dominator For Basic Block\n" << I->first |
| 66 | << "is: \n" << I->second << endl; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | |
Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 71 | static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) { |
| 72 | return o << Node->getNode() << "\n------------------------------------------\n"; |
| 73 | |
| 74 | } |
Chris Lattner | 347bfda | 2001-07-02 05:46:47 +0000 | [diff] [blame] | 75 | |
Chris Lattner | 3d98049 | 2001-07-03 05:36:34 +0000 | [diff] [blame] | 76 | static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o, |
| 77 | unsigned Lev) { |
| 78 | o << "Level #" << Lev << ": " << N; |
| 79 | for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end(); |
| 80 | I != E; ++I) { |
| 81 | PrintDomTree(*I, o, Lev+1); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) { |
| 86 | o << "=============================--------------------------------\n" |
| 87 | << "Inorder Dominator Tree:\n"; |
| 88 | PrintDomTree(DT[DT.getRoot()], o, 1); |
Chris Lattner | 347bfda | 2001-07-02 05:46:47 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) { |
| 92 | for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end(); |
| 93 | I != E; ++I) { |
| 94 | o << "=============================--------------------------------\n" |
| 95 | << "\nDominance Frontier For Basic Block\n" << I->first |
| 96 | << "is: \n" << I->second << endl; |
| 97 | } |
| 98 | } |
| 99 | |
Chris Lattner | a2eb259 | 2001-11-26 18:53:29 +0000 | [diff] [blame^] | 100 | |
| 101 | //===----------------------------------------------------------------------===// |
| 102 | // Loop Printing Routines |
| 103 | //===----------------------------------------------------------------------===// |
| 104 | |
| 105 | void cfg::WriteToOutput(const Loop *L, ostream &o) { |
| 106 | o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: "; |
| 107 | |
| 108 | for (unsigned i = 0; i < L->getBlocks().size(); ++i) { |
| 109 | if (i) o << ","; |
| 110 | WriteAsOperand(o, (const Value*)L->getBlocks()[i]); |
| 111 | } |
| 112 | o << endl; |
| 113 | |
| 114 | copy(L->getSubLoops().begin(), L->getSubLoops().end(), |
| 115 | ostream_iterator<const Loop*>(o, "\n")); |
| 116 | } |
| 117 | |
| 118 | void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) { |
| 119 | copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(), |
| 120 | ostream_iterator<const Loop*>(o, "\n")); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | |
| 125 | //===----------------------------------------------------------------------===// |
| 126 | // Induction Variable Printing Routines |
| 127 | //===----------------------------------------------------------------------===// |
| 128 | |
| 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; |
| 135 | } |
| 136 | o << "Induction Variable"; |
| 137 | if (IV.Phi) { |
| 138 | WriteAsOperand(o, (const Value*)IV.Phi); |
| 139 | o << ":\n" << (const Value*)IV.Phi; |
| 140 | } else { |
| 141 | o << endl; |
| 142 | } |
| 143 | if (IV.InductionType == InductionVariable::Unknown) return; |
| 144 | |
| 145 | o << " Start ="; WriteAsOperand(o, IV.Start); |
| 146 | o << " Step =" ; WriteAsOperand(o, IV.Step); |
| 147 | o << endl; |
| 148 | } |