llvm.org GIT mirror llvm / a59cbb2
* Standardize how analysis results/passes as printed with the print() virtual methods * Eliminate AnalysisID: Now it is just a typedef for const PassInfo* * Simplify how AnalysisID's are initialized * Eliminate Analysis/Writer.cpp/.h: incorporate printing functionality into the analyses themselves. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3116 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
17 changed file(s) with 247 addition(s) and 257 deletion(s). Raw diff Collapse all Expand all
2323
2424 #include
2525 #include
26 #include
2627 class Value;
2728 class BasicBlock;
2829 class Function;
2930 class Module;
3031 class AnalysisUsage;
31 class AnalysisID;
3232 class PassInfo;
3333 template class PassManagerT;
3434 struct AnalysisResolver;
35
36 // AnalysisID - Use the PassInfo to identify a pass...
37 typedef const PassInfo* AnalysisID;
38
3539
3640 //===----------------------------------------------------------------------===//
3741 // Pass interface - Implemented by all 'passes'. Subclass this if you are an
5963 // module argument. This should be implemented by all concrete subclasses.
6064 //
6165 virtual bool run(Module &M) = 0;
66
67 // print - Print out the internal state of the pass. This is called by
68 // Analyze to print out the contents of an analysis. Otherwise it is not
69 // neccesary to implement this method. Beware that the module pointer MAY be
70 // null. This automatically forwards to a virtual function that does not
71 // provide the Module* in case the analysis doesn't need it it can just be
72 // ignored.
73 //
74 virtual void print(std::ostream &O, const Module *M) const { print(O); }
75 virtual void print(std::ostream &O) const;
76 void dump() const; // dump - call print(std::cerr, 0);
77
6278
6379 // getAnalysisUsage - This function should be overriden by passes that need
6480 // analysis information to do their job. If a pass specifies that it uses a
116132 virtual void addToPassManager(PassManagerT *PM, AnalysisUsage &AU);
117133 };
118134
135 inline std::ostream &operator<<(std::ostream &OS, const Pass &P) {
136 P.print(OS, 0); return OS;
137 }
119138
120139 //===----------------------------------------------------------------------===//
121140 // FunctionPass class - This class is used to implement most global
1414 // No need to include Pass.h, we are being included by it!
1515
1616
17 // CreatePass - Helper template to invoke the constructor for the AnalysisID
18 // class. Note that this should be a template internal to AnalysisID, but
19 // GCC 2.95.3 crashes if we do that, doh.
20 //
21 template
22 static Pass *CreatePass() { return new AnalysisType(); }
23
24 //===----------------------------------------------------------------------===//
25 // AnalysisID - This class is used to uniquely identify an analysis pass that
26 // is referenced by a transformation.
27 //
28 class AnalysisID {
29 static unsigned NextID; // Next ID # to deal out...
30 unsigned ID; // Unique ID for this analysis
31 Pass *(*Constructor)(); // Constructor to return the Analysis
32
33 AnalysisID(); // Disable default ctor
34 AnalysisID(unsigned id, Pass *(*Ct)()) : ID(id), Constructor(Ct) {}
35 public:
36 // create - the only way to define a new AnalysisID. This static method is
37 // supposed to be used to define the class static AnalysisID's that are
38 // provided by analysis passes. In the implementation (.cpp) file for the
39 // class, there should be a line that looks like this (using CallGraph as an
40 // example):
41 //
42 // AnalysisID CallGraph::ID(AnalysisID::create());
43 //
44 template
45 static AnalysisID create() {
46 return AnalysisID(NextID++, CreatePass);
47 }
48
49 // Special Copy Constructor - This is how analysis passes declare that they
50 // only depend on the CFG of the function they are working on, so they are not
51 // invalidated by other passes that do not modify the CFG. This should be
52 // used like this:
53 // AnalysisID DominatorSet::ID(AnalysisID::create(), true);
54 //
55 AnalysisID(const AnalysisID &AID, bool DependsOnlyOnCFG = false);
56
57
58 inline Pass *createPass() const { return Constructor(); }
59
60 inline bool operator==(const AnalysisID &A) const {
61 return A.ID == ID;
62 }
63 inline bool operator!=(const AnalysisID &A) const {
64 return A.ID != ID;
65 }
66 inline bool operator<(const AnalysisID &A) const {
67 return ID < A.ID;
68 }
69 };
7017
7118 //===----------------------------------------------------------------------===//
7219 // AnalysisUsage - Represent the analysis usage information of a pass. This
7474
7575 Pass *(*getNormalCtor() const)() {
7676 return NormalCtor;
77 }
78
79 // createPass() - Use this
80 Pass *createPass() const {
81 assert(NormalCtor &&
82 "Cannot call createPass on PassInfo without default ctor!");
83 return NormalCtor();
7784 }
7885
7986 // getDataCtor - Return a pointer to a function that creates an instance of
110117
111118 ~RegisterPassBase(); // Intentionally non-virtual...
112119
120 inline operator PassInfo* () const { return PIObj; }
121
113122 protected:
114123 PassInfo *PIObj; // The PassInfo object for this pass
115124 void registerPass(PassInfo *);
4545 #include
4646
4747 static RegisterAnalysis X("callgraph", "Call Graph Construction");
48
49 AnalysisID CallGraph::ID(AnalysisID::create());
48 AnalysisID CallGraph::ID = X;
5049
5150 // getNodeFor - Return the node for the specified function or create one if it
5251 // does not already exist.
2424
2525 static RegisterAnalysis
2626 X("unsafepointertypes", "Find Unsafe Pointer Types");
27 AnalysisID FindUnsafePointerTypes::ID(AnalysisID::create());
27 AnalysisID FindUnsafePointerTypes::ID = X;
2828
2929 // Provide a command line option to turn on printing of which instructions cause
3030 // a type to become invalid
7676 // printResults - Loop over the results of the analysis, printing out unsafe
7777 // types.
7878 //
79 void FindUnsafePointerTypes::printResults(const Module *M,
80 std::ostream &o) const {
79 void FindUnsafePointerTypes::print(std::ostream &o, const Module *M) const {
8180 if (UnsafeTypes.empty()) {
8281 o << "SafePointerAccess Analysis: No unsafe types found!\n";
8382 return;
1212
1313 static RegisterAnalysis
1414 X("printusedtypes", "Find Used Types");
15 AnalysisID FindUsedTypes::ID(AnalysisID::create());
15 AnalysisID FindUsedTypes::ID = X;
1616
1717 // IncorporateType - Incorporate one type and all of its subtypes into the
1818 // collection of used types.
6767 // passed in, then the types are printed symbolically if possible, using the
6868 // symbol table from the module.
6969 //
70 void FindUsedTypes::printTypes(std::ostream &o, const Module *M) const {
70 void FindUsedTypes::print(std::ostream &o, const Module *M) const {
7171 o << "Types in use by this module:\n";
7272 if (M) {
7373 CachedWriter CW(M, o);
2222 #include "llvm/InstrTypes.h"
2323 #include "llvm/Type.h"
2424 #include "llvm/Constants.h"
25 #include "llvm/Assembly/Writer.h"
2526
2627 using analysis::ExprType;
2728
153154 // Classify the induction variable type now...
154155 InductionType = InductionVariable::Classify(Start, Step, L);
155156 }
157
158 void InductionVariable::print(std::ostream &o) const {
159 switch (InductionType) {
160 case InductionVariable::Cannonical: o << "Cannonical "; break;
161 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
162 case InductionVariable::Linear: o << "Linear "; break;
163 case InductionVariable::Unknown: o << "Unrecognized "; break;
164 }
165 o << "Induction Variable";
166 if (Phi) {
167 WriteAsOperand(o, Phi);
168 o << ":\n" << Phi;
169 } else {
170 o << "\n";
171 }
172 if (InductionType == InductionVariable::Unknown) return;
173
174 o << " Start ="; WriteAsOperand(o, Start);
175 o << " Step =" ; WriteAsOperand(o, Step);
176 o << "\n";
177 }
77 #include "llvm/Analysis/Interval.h"
88 #include "llvm/BasicBlock.h"
99 #include "llvm/Support/CFG.h"
10 #include
1011
1112 //===----------------------------------------------------------------------===//
1213 // Interval Implementation
2526 }
2627
2728
29 void Interval::print(ostream &o) const {
30 o << "-------------------------------------------------------------\n"
31 << "Interval Contents:\n";
32
33 // Print out all of the basic blocks in the interval...
34 std::copy(Nodes.begin(), Nodes.end(),
35 std::ostream_iterator(o, "\n"));
36
37 o << "Interval Predecessors:\n";
38 std::copy(Predecessors.begin(), Predecessors.end(),
39 std::ostream_iterator(o, "\n"));
40
41 o << "Interval Successors:\n";
42 std::copy(Successors.begin(), Successors.end(),
43 std::ostream_iterator(o, "\n"));
44 }
1212 static RegisterAnalysis
1313 X("intervals", "Interval Partition Construction");
1414
15 AnalysisID IntervalPartition::ID(AnalysisID::create(), true);
15 AnalysisID IntervalPartition::ID = X;
1616
1717 //===----------------------------------------------------------------------===//
1818 // IntervalPartition Implementation
2323 for_each(begin(), end(), deleter);
2424 IntervalMap.clear();
2525 RootInterval = 0;
26 }
27
28 void IntervalPartition::print(ostream &O) const {
29 std::copy(begin(), end(),
30 std::ostream_iterator(O, "\n"));
2631 }
2732
2833 // addIntervalToPartition - Add an interval to the internal list of intervals,
99 #include "llvm/Analysis/LoopInfo.h"
1010 #include "llvm/Analysis/Dominators.h"
1111 #include "llvm/Support/CFG.h"
12 #include "llvm/Assembly/Writer.h"
1213 #include "Support/DepthFirstIterator.h"
1314 #include
1415
1516 static RegisterAnalysis
1617 X("loops", "Natural Loop Construction");
17 AnalysisID LoopInfo::ID(AnalysisID::create(), true);
18 AnalysisID LoopInfo::ID = X;
1819
1920 //===----------------------------------------------------------------------===//
2021 // Loop implementation
2122 //
2223 bool Loop::contains(const BasicBlock *BB) const {
2324 return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
25 }
26
27 void Loop::print(std::ostream &OS) const {
28 OS << std::string(getLoopDepth()*2, ' ') << "Loop Containing: ";
29
30 for (unsigned i = 0; i < getBlocks().size(); ++i) {
31 if (i) OS << ",";
32 WriteAsOperand(OS, (const Value*)getBlocks()[i]);
33 }
34 OS << "\n";
35
36 std::copy(getSubLoops().begin(), getSubLoops().end(),
37 std::ostream_iterator(OS, "\n"));
38 }
39
40 //===----------------------------------------------------------------------===//
41 // LoopInfo implementation
42 //
43
44 bool LoopInfo::runOnFunction(Function &) {
45 releaseMemory();
46 Calculate(getAnalysis()); // Update
47 return false;
2448 }
2549
2650 void LoopInfo::releaseMemory() {
3256 TopLevelLoops.clear();
3357 }
3458
35
36 //===----------------------------------------------------------------------===//
37 // LoopInfo implementation
38 //
39 bool LoopInfo::runOnFunction(Function &) {
40 releaseMemory();
41 Calculate(getAnalysis()); // Update
42 return false;
43 }
4459
4560 void LoopInfo::Calculate(const DominatorSet &DS) {
4661 BasicBlock *RootNode = DS.getRoot();
6075 AU.addProvided(ID);
6176 }
6277
78 void LoopInfo::print(std::ostream &OS) const {
79 std::copy(getTopLevelLoops().begin(), getTopLevelLoops().end(),
80 std::ostream_iterator(OS, "\n"));
81 }
6382
6483 Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
6584 if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node?
77 #include "llvm/Analysis/Dominators.h"
88 #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
99 #include "llvm/Support/CFG.h"
10 #include "llvm/Assembly/Writer.h"
1011 #include "Support/DepthFirstIterator.h"
1112 #include "Support/STLExtras.h"
1213 #include "Support/SetOperations.h"
2223 static RegisterAnalysis
2324 B("postdomset", "Post-Dominator Set Construction");
2425
25 AnalysisID DominatorSet::ID(AnalysisID::create(), true);
26 AnalysisID PostDominatorSet::ID(AnalysisID::create(), true);
26 AnalysisID DominatorSet::ID = A;
27 AnalysisID PostDominatorSet::ID = B;
2728
2829 // dominates - Return true if A dominates B. This performs the special checks
2930 // neccesary if A and B are in the same basic block.
150151 AU.addRequired(UnifyFunctionExitNodes::ID);
151152 }
152153
154 static ostream &operator<<(ostream &o, const set &BBs) {
155 for (set::const_iterator I = BBs.begin(), E = BBs.end();
156 I != E; ++I) {
157 o << " ";
158 WriteAsOperand(o, *I, false);
159 o << "\n";
160 }
161 return o;
162 }
163
164 void DominatorSetBase::print(std::ostream &o) const {
165 for (const_iterator I = begin(), E = end(); I != E; ++I)
166 o << "=============================--------------------------------\n"
167 << "\nDominator Set For Basic Block\n" << I->first
168 << "-------------------------------\n" << I->second << "\n";
169 }
153170
154171 //===----------------------------------------------------------------------===//
155172 // ImmediateDominators Implementation
160177 static RegisterAnalysis
161178 D("postidom", "Immediate Post-Dominators Construction");
162179
163 AnalysisID ImmediateDominators::ID(AnalysisID::create(), true);
164 AnalysisID ImmediatePostDominators::ID(AnalysisID::create(), true);
180 AnalysisID ImmediateDominators::ID = C;
181 AnalysisID ImmediatePostDominators::ID = D;
165182
166183 // calcIDoms - Calculate the immediate dominator mapping, given a set of
167184 // dominators for every basic block.
199216 }
200217 }
201218
219 void ImmediateDominatorsBase::print(ostream &o) const {
220 for (const_iterator I = begin(), E = end(); I != E; ++I)
221 o << "=============================--------------------------------\n"
222 << "\nImmediate Dominator For Basic Block\n" << *I->first
223 << "is: \n" << *I->second << "\n";
224 }
225
202226
203227 //===----------------------------------------------------------------------===//
204228 // DominatorTree Implementation
209233 static RegisterAnalysis
210234 F("postdomtree", "Post-Dominator Tree Construction");
211235
212 AnalysisID DominatorTree::ID(AnalysisID::create(), true);
213 AnalysisID PostDominatorTree::ID(AnalysisID::create(), true);
236 AnalysisID DominatorTree::ID = E;
237 AnalysisID PostDominatorTree::ID = F;
214238
215239 // DominatorTreeBase::reset - Free all of the tree node memory.
216240 //
315339 }
316340 }
317341
342 static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
343 return o << Node->getNode()
344 << "\n------------------------------------------\n";
345 }
346
347 static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
348 unsigned Lev) {
349 o << "Level #" << Lev << ": " << N;
350 for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
351 I != E; ++I) {
352 PrintDomTree(*I, o, Lev+1);
353 }
354 }
355
356 void DominatorTreeBase::print(std::ostream &o) const {
357 o << "=============================--------------------------------\n"
358 << "Inorder Dominator Tree:\n";
359 PrintDomTree(Nodes.find(getRoot())->second, o, 1);
360 }
318361
319362
320363 //===----------------------------------------------------------------------===//
326369 static RegisterAnalysis
327370 H("postdomfrontier", "Post-Dominance Frontier Construction");
328371
329 AnalysisID DominanceFrontier::ID(AnalysisID::create(), true);
330 AnalysisID PostDominanceFrontier::ID(AnalysisID::create(), true);
372 AnalysisID DominanceFrontier::ID = G;
373 AnalysisID PostDominanceFrontier::ID = H;
331374
332375 const DominanceFrontier::DomSetType &
333376 DominanceFrontier::calculate(const DominatorTree &DT,
395438
396439 return S;
397440 }
441
442 void DominanceFrontierBase::print(std::ostream &o) const {
443 for (const_iterator I = begin(), E = end(); I != E; ++I) {
444 o << "=============================--------------------------------\n"
445 << "\nDominance Frontier For Basic Block\n";
446 WriteAsOperand(o, I->first, false);
447 o << " is: \n" << I->second << "\n";
448 }
449 }
+0
-163
lib/Analysis/Writer.cpp less more
None //===-- Analysis/Writer.cpp - Printing routines for analyses -----*- C++ -*--=//
1 //
2 // This library file implements analysis result printing support for
3 // llvm/Analysis/Writer.h
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "llvm/Analysis/Writer.h"
8 #include "llvm/Analysis/IntervalPartition.h"
9 #include "llvm/Analysis/Dominators.h"
10 #include "llvm/Analysis/LoopInfo.h"
11 #include "llvm/Analysis/InductionVariable.h"
12 #include "llvm/Assembly/Writer.h"
13 #include "llvm/Module.h"
14 #include
15 #include
16 #include
17 #include
18 using std::ostream;
19 using std::set;
20 using std::vector;
21 using std::string;
22
23 //===----------------------------------------------------------------------===//
24 // Interval Printing Routines
25 //===----------------------------------------------------------------------===//
26
27 void WriteToOutput(const Interval *I, ostream &o) {
28 o << "-------------------------------------------------------------\n"
29 << "Interval Contents:\n";
30
31 // Print out all of the basic blocks in the interval...
32 copy(I->Nodes.begin(), I->Nodes.end(),
33 std::ostream_iterator(o, "\n"));
34
35 o << "Interval Predecessors:\n";
36 copy(I->Predecessors.begin(), I->Predecessors.end(),
37 std::ostream_iterator(o, "\n"));
38
39 o << "Interval Successors:\n";
40 copy(I->Successors.begin(), I->Successors.end(),
41 std::ostream_iterator(o, "\n"));
42 }
43
44 void WriteToOutput(const IntervalPartition &IP, ostream &o) {
45 copy(IP.begin(), IP.end(), std::ostream_iterator(o, "\n"));
46 }
47
48
49
50 //===----------------------------------------------------------------------===//
51 // Dominator Printing Routines
52 //===----------------------------------------------------------------------===//
53
54 ostream &operator<<(ostream &o, const set &BBs) {
55 for (set::const_iterator I = BBs.begin(), E = BBs.end();
56 I != E; ++I) {
57 o << " ";
58 WriteAsOperand(o, (Value*)*I, false);
59 o << "\n";
60 }
61 return o;
62 }
63
64 void WriteToOutput(const DominatorSetBase &DS, ostream &o) {
65 for (DominatorSetBase::const_iterator I = DS.begin(), E = DS.end();
66 I != E; ++I) {
67 o << "=============================--------------------------------\n"
68 << "\nDominator Set For Basic Block\n" << I->first
69 << "-------------------------------\n" << I->second << "\n";
70 }
71 }
72
73
74 void WriteToOutput(const ImmediateDominatorsBase &ID, ostream &o) {
75 for (ImmediateDominatorsBase::const_iterator I = ID.begin(), E = ID.end();
76 I != E; ++I) {
77 o << "=============================--------------------------------\n"
78 << "\nImmediate Dominator For Basic Block\n" << *I->first
79 << "is: \n" << *I->second << "\n";
80 }
81 }
82
83
84 static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
85 return o << Node->getNode() << "\n------------------------------------------\n";
86
87 }
88
89 static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
90 unsigned Lev) {
91 o << "Level #" << Lev << ": " << N;
92 for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
93 I != E; ++I) {
94 PrintDomTree(*I, o, Lev+1);
95 }
96 }
97
98 void WriteToOutput(const DominatorTreeBase &DT, ostream &o) {
99 o << "=============================--------------------------------\n"
100 << "Inorder Dominator Tree:\n";
101 PrintDomTree(DT[DT.getRoot()], o, 1);
102 }
103
104 void WriteToOutput(const DominanceFrontierBase &DF, ostream &o) {
105 for (DominanceFrontierBase::const_iterator I = DF.begin(), E = DF.end();
106 I != E; ++I) {
107 o << "=============================--------------------------------\n"
108 << "\nDominance Frontier For Basic Block\n";
109 WriteAsOperand(o, (Value*)I->first, false);
110 o << " is: \n" << I->second << "\n";
111 }
112 }
113
114
115 //===----------------------------------------------------------------------===//
116 // Loop Printing Routines
117 //===----------------------------------------------------------------------===//
118
119 void WriteToOutput(const Loop *L, ostream &o) {
120 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
121
122 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
123 if (i) o << ",";
124 WriteAsOperand(o, (const Value*)L->getBlocks()[i]);
125 }
126 o << "\n";
127
128 copy(L->getSubLoops().begin(), L->getSubLoops().end(),
129 std::ostream_iterator(o, "\n"));
130 }
131
132 void WriteToOutput(const LoopInfo &LI, ostream &o) {
133 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
134 std::ostream_iterator(o, "\n"));
135 }
136
137
138
139 //===----------------------------------------------------------------------===//
140 // Induction Variable Printing Routines
141 //===----------------------------------------------------------------------===//
142
143 void WriteToOutput(const InductionVariable &IV, ostream &o) {
144 switch (IV.InductionType) {
145 case InductionVariable::Cannonical: o << "Cannonical "; break;
146 case InductionVariable::SimpleLinear: o << "SimpleLinear "; break;
147 case InductionVariable::Linear: o << "Linear "; break;
148 case InductionVariable::Unknown: o << "Unrecognized "; break;
149 }
150 o << "Induction Variable";
151 if (IV.Phi) {
152 WriteAsOperand(o, (const Value*)IV.Phi);
153 o << ":\n" << (const Value*)IV.Phi;
154 } else {
155 o << "\n";
156 }
157 if (IV.InductionType == InductionVariable::Unknown) return;
158
159 o << " Start ="; WriteAsOperand(o, IV.Start);
160 o << " Step =" ; WriteAsOperand(o, IV.Step);
161 o << "\n";
162 }
99 #include "llvm/Transforms/Utils/Local.h"
1010 #include "llvm/Type.h"
1111 #include "llvm/Analysis/Dominators.h"
12 #include "llvm/Analysis/Writer.h"
1312 #include "llvm/iTerminators.h"
1413 #include "llvm/iPHINode.h"
1514 #include "llvm/Constant.h"
77 #include "llvm/Transforms/Scalar.h"
88 #include "llvm/Analysis/InductionVariable.h"
99 #include "llvm/Analysis/LoopInfo.h"
10 #include "llvm/Analysis/Writer.h"
1110 #include "llvm/iPHINode.h"
1211 #include "llvm/iOther.h"
1312 #include "llvm/Type.h"
126125 for (unsigned i = 0; i < IndVars.size(); ++i) {
127126 InductionVariable *IV = &IndVars[i];
128127
129 DEBUG(std::cerr << IV);
128 DEBUG(IV->print(std::cerr));
130129
131130 // Don't modify the cannonical indvar or unrecognized indvars...
132131 if (IV != Cannonical && IV->InductionType != InductionVariable::Unknown) {
77 #include "llvm/Analysis/Dominators.h"
88 #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
99 #include "llvm/Support/CFG.h"
10 #include "llvm/Assembly/Writer.h"
1011 #include "Support/DepthFirstIterator.h"
1112 #include "Support/STLExtras.h"
1213 #include "Support/SetOperations.h"
2223 static RegisterAnalysis
2324 B("postdomset", "Post-Dominator Set Construction");
2425
25 AnalysisID DominatorSet::ID(AnalysisID::create(), true);
26 AnalysisID PostDominatorSet::ID(AnalysisID::create(), true);
26 AnalysisID DominatorSet::ID = A;
27 AnalysisID PostDominatorSet::ID = B;
2728
2829 // dominates - Return true if A dominates B. This performs the special checks
2930 // neccesary if A and B are in the same basic block.
150151 AU.addRequired(UnifyFunctionExitNodes::ID);
151152 }
152153
154 static ostream &operator<<(ostream &o, const set &BBs) {
155 for (set::const_iterator I = BBs.begin(), E = BBs.end();
156 I != E; ++I) {
157 o << " ";
158 WriteAsOperand(o, *I, false);
159 o << "\n";
160 }
161 return o;
162 }
163
164 void DominatorSetBase::print(std::ostream &o) const {
165 for (const_iterator I = begin(), E = end(); I != E; ++I)
166 o << "=============================--------------------------------\n"
167 << "\nDominator Set For Basic Block\n" << I->first
168 << "-------------------------------\n" << I->second << "\n";
169 }
153170
154171 //===----------------------------------------------------------------------===//
155172 // ImmediateDominators Implementation
160177 static RegisterAnalysis
161178 D("postidom", "Immediate Post-Dominators Construction");
162179
163 AnalysisID ImmediateDominators::ID(AnalysisID::create(), true);
164 AnalysisID ImmediatePostDominators::ID(AnalysisID::create(), true);
180 AnalysisID ImmediateDominators::ID = C;
181 AnalysisID ImmediatePostDominators::ID = D;
165182
166183 // calcIDoms - Calculate the immediate dominator mapping, given a set of
167184 // dominators for every basic block.
199216 }
200217 }
201218
219 void ImmediateDominatorsBase::print(ostream &o) const {
220 for (const_iterator I = begin(), E = end(); I != E; ++I)
221 o << "=============================--------------------------------\n"
222 << "\nImmediate Dominator For Basic Block\n" << *I->first
223 << "is: \n" << *I->second << "\n";
224 }
225
202226
203227 //===----------------------------------------------------------------------===//
204228 // DominatorTree Implementation
209233 static RegisterAnalysis
210234 F("postdomtree", "Post-Dominator Tree Construction");
211235
212 AnalysisID DominatorTree::ID(AnalysisID::create(), true);
213 AnalysisID PostDominatorTree::ID(AnalysisID::create(), true);
236 AnalysisID DominatorTree::ID = E;
237 AnalysisID PostDominatorTree::ID = F;
214238
215239 // DominatorTreeBase::reset - Free all of the tree node memory.
216240 //
315339 }
316340 }
317341
342 static ostream &operator<<(ostream &o, const DominatorTreeBase::Node *Node) {
343 return o << Node->getNode()
344 << "\n------------------------------------------\n";
345 }
346
347 static void PrintDomTree(const DominatorTreeBase::Node *N, ostream &o,
348 unsigned Lev) {
349 o << "Level #" << Lev << ": " << N;
350 for (DominatorTreeBase::Node::const_iterator I = N->begin(), E = N->end();
351 I != E; ++I) {
352 PrintDomTree(*I, o, Lev+1);
353 }
354 }
355
356 void DominatorTreeBase::print(std::ostream &o) const {
357 o << "=============================--------------------------------\n"
358 << "Inorder Dominator Tree:\n";
359 PrintDomTree(Nodes.find(getRoot())->second, o, 1);
360 }
318361
319362
320363 //===----------------------------------------------------------------------===//
326369 static RegisterAnalysis
327370 H("postdomfrontier", "Post-Dominance Frontier Construction");
328371
329 AnalysisID DominanceFrontier::ID(AnalysisID::create(), true);
330 AnalysisID PostDominanceFrontier::ID(AnalysisID::create(), true);
372 AnalysisID DominanceFrontier::ID = G;
373 AnalysisID PostDominanceFrontier::ID = H;
331374
332375 const DominanceFrontier::DomSetType &
333376 DominanceFrontier::calculate(const DominatorTree &DT,
395438
396439 return S;
397440 }
441
442 void DominanceFrontierBase::print(std::ostream &o) const {
443 for (const_iterator I = begin(), E = end(); I != E; ++I) {
444 o << "=============================--------------------------------\n"
445 << "\nDominance Frontier For Basic Block\n";
446 WriteAsOperand(o, I->first, false);
447 o << " is: \n" << I->second << "\n";
448 }
449 }
2121 //
2222
2323 static std::vector CFGOnlyAnalyses;
24
24 #if 0
2525 // Source of unique analysis ID #'s.
2626 unsigned AnalysisID::NextID = 0;
2727
3434 if (DependsOnlyOnCFG)
3535 CFGOnlyAnalyses.push_back(AID);
3636 }
37 #endif
3738
3839 //===----------------------------------------------------------------------===//
3940 // AnalysisResolver Class Implementation
189190 if (PassDebugging >= Details && !Set.empty()) {
190191 std::cerr << (void*)P << std::string(Depth*2+3, ' ') << Msg << " Analyses:";
191192 for (unsigned i = 0; i != Set.size(); ++i) {
192 Pass *P = Set[i].createPass(); // Good thing this is just debug code...
193 // FIXME: This can use the local pass map!
194 Pass *P = Set[i]->createPass(); // Good thing this is just debug code...
193195 std::cerr << " " << P->getPassName();
194196 delete P;
195197 }
215217 // getPassName - Use C++ RTTI to get a SOMEWHAT intelligable name for the pass.
216218 //
217219 const char *Pass::getPassName() const { return typeid(*this).name(); }
220
221 // print - Print out the internal state of the pass. This is called by Analyse
222 // to print out the contents of an analysis. Otherwise it is not neccesary to
223 // implement this method.
224 //
225 void Pass::print(std::ostream &O) const {
226 O << "Pass::print not implemented for pass: '" << getPassName() << "'!\n";
227 }
228
229 // dump - call print(std::cerr);
230 void Pass::dump() const {
231 print(std::cerr, 0);
232 }
218233
219234 //===----------------------------------------------------------------------===//
220235 // FunctionPass Implementation
296296 for (std::vector::const_iterator I = Required.begin(),
297297 E = Required.end(); I != E; ++I) {
298298 if (getAnalysisOrNullDown(*I) == 0)
299 add((PassClass*)I->createPass());
299 add((PassClass*)(*I)->createPass());
300300 }
301301
302302 // Tell the pass to add itself to this PassManager... the way it does so