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"
14 //===----------------------------------------------------------------------===//
15 // Interval Printing Routines
16 //===----------------------------------------------------------------------===//
18 void cfg::WriteToOutput(const Interval *I, ostream &o) {
19 o << "-------------------------------------------------------------\n"
20 << "Interval Contents:\n";
22 // Print out all of the basic blocks in the interval...
23 copy(I->Nodes.begin(), I->Nodes.end(),
24 ostream_iterator<BasicBlock*>(o, "\n"));
26 o << "Interval Predecessors:\n";
27 copy(I->Predecessors.begin(), I->Predecessors.end(),
28 ostream_iterator<BasicBlock*>(o, "\n"));
30 o << "Interval Successors:\n";
31 copy(I->Successors.begin(), I->Successors.end(),
32 ostream_iterator<BasicBlock*>(o, "\n"));
35 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
36 copy(IP.begin(), IP.end(), ostream_iterator<const Interval *>(o, "\n"));
41 //===----------------------------------------------------------------------===//
42 // Dominator Printing Routines
43 //===----------------------------------------------------------------------===//
45 ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
46 copy(BBs.begin(), BBs.end(), ostream_iterator<const BasicBlock*>(o, "\n"));
50 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
51 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
52 o << "=============================--------------------------------\n"
53 << "\nDominator Set For Basic Block\n" << I->first
54 << "-------------------------------\n" << I->second << endl;
59 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
60 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
62 o << "=============================--------------------------------\n"
63 << "\nImmediate Dominator For Basic Block\n" << I->first
64 << "is: \n" << I->second << endl;
69 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
70 return o << Node->getNode() << "\n------------------------------------------\n";
74 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
76 o << "Level #" << Lev << ": " << N;
77 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
79 PrintDomTree(*I, o, Lev+1);
83 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
84 o << "=============================--------------------------------\n"
85 << "Inorder Dominator Tree:\n";
86 PrintDomTree(DT[DT.getRoot()], o, 1);
89 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
90 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
92 o << "=============================--------------------------------\n"
93 << "\nDominance Frontier For Basic Block\n" << I->first
94 << "is: \n" << I->second << endl;