aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/Writer.cpp
blob: 3624dd1e6a1e7454ec34ced7829fa8752dcf6d2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
//
// This library file implements analysis result printing support for 
// llvm/Analysis/Writer.h
//
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/Writer.h"
#include "llvm/Analysis/IntervalPartition.h"
#include "llvm/Analysis/Dominators.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/InductionVariable.h"
#include "llvm/Assembly/Writer.h"
#include <iterator>
#include <algorithm>
#include <string>
using std::ostream;
using std::set;
using std::vector;
using std::string;

//===----------------------------------------------------------------------===//
//  Interval Printing Routines
//===----------------------------------------------------------------------===//

void WriteToOutput(const Interval *I, ostream &o) {
  o << "-------------------------------------------------------------\n"
       << "Interval Contents:\n";
  
  // Print out all of the basic blocks in the interval...
  copy(I->Nodes.begin(), I->Nodes.end(), 
       std::ostream_iterator<BasicBlock*>(o, "\n"));

  o << "Interval Predecessors:\n";
  copy(I->Predecessors.begin(), I->Predecessors.end(), 
       std::ostream_iterator<BasicBlock*>(o, "\n"));
  
  o << "Interval Successors:\n";
  copy(I->Successors.begin(), I->Successors.end(), 
       std::ostream_iterator<BasicBlock*>(o, "\n"));
}

void WriteToOutput(const IntervalPartition &IP, ostream &o) {
  copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
}



//===----------------------------------------------------------------------===//
//  Dominator Printing Routines
//===----------------------------------------------------------------------===//

ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
  for (set<BasicBlock*>::const_iterator I = BBs.begin(), E = BBs.end();
       I != E; ++I) {
    o << "  ";
    WriteAsOperand(o, (Value*)*I, false);
    o << "\n";
   }
  return o;
}

void WriteToOutput(const DominatorSet &DS, ostream &o) {
  for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
    o << "=============================--------------------------------\n"
      << "\nDominator Set For Basic Block\n" << I->first
      << "-------------------------------\n" << I->second << "\n";
  }
}


void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
  for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
       I != E; ++I) {
    o << "=============================--------------------------------\n"
      << "\nImmediate Dominator For Basic Block\n" << I->first
      << "is: \n" << I->second << "\n";
  }
}


static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
  return o << Node->getNode() << "\n------------------------------------------\n";
	   
}

static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
                         unsigned Lev) {
  o << "Level #" << Lev << ":  " << N;
  for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end(); 
       I != E; ++I) {
    PrintDomTree(*I, o, Lev+1);
  }
}

void WriteToOutput(const DominatorTree &DT, ostream &o) {
  o << "=============================--------------------------------\n"
    << "Inorder Dominator Tree:\n";
  PrintDomTree(DT[DT.getRoot()], o, 1);
}

void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
  for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
       I != E; ++I) {
    o << "=============================--------------------------------\n"
      << "\nDominance Frontier For Basic Block\n";
    WriteAsOperand(o, (Value*)I->first, false);
    o << " is: \n" << I->second << "\n";
  }
}


//===----------------------------------------------------------------------===//
//  Loop Printing Routines
//===----------------------------------------------------------------------===//

void WriteToOutput(const Loop *L, ostream &o) {
  o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";

  for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
    if (i) o << ",";
    WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
  }
  o << "\n";

  copy(L->getSubLoops().begin(), L->getSubLoops().end(),
       std::ostream_iterator<const Loop*>(o, "\n"));
}

void WriteToOutput(const LoopInfo &LI, ostream &o) {
  copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
       std::ostream_iterator<const Loop*>(o, "\n"));
}



//===----------------------------------------------------------------------===//
//  Induction Variable Printing Routines
//===----------------------------------------------------------------------===//

void WriteToOutput(const InductionVariable &IV, ostream &o) {
  switch (IV.InductionType) {
  case InductionVariable::Cannonical:   o << "Cannonical ";   break;
  case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
  case InductionVariable::Linear:       o << "Linear ";       break;
  case InductionVariable::Unknown:      o << "Unrecognized "; break;
  }
  o << "Induction Variable";
  if (IV.Phi) {
    WriteAsOperand(o, (const Value*)IV.Phi);
    o << ":\n" << (const Value*)IV.Phi;
  } else {
    o << "\n";
  }
  if (IV.InductionType == InductionVariable::Unknown) return;

  o << "  Start ="; WriteAsOperand(o, IV.Start);
  o << "  Step =" ; WriteAsOperand(o, IV.Step);
  o << "\n";
}