Commit r331416 breaks the big-endian PPC bot. On the big endian build, we
[llvm-core.git] / tools / opt / PassPrinters.cpp
blob310d491c06a520e8a8b1a73665b5b15c33c77dce
1 //===- PassPrinters.cpp - Utilities to print analysis info for passes -----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// Utilities to print analysis info for various kinds of passes.
12 ///
13 //===----------------------------------------------------------------------===//
15 #include "PassPrinters.h"
16 #include "llvm/Analysis/CallGraph.h"
17 #include "llvm/Analysis/CallGraphSCCPass.h"
18 #include "llvm/Analysis/LoopInfo.h"
19 #include "llvm/Analysis/LoopPass.h"
20 #include "llvm/Analysis/RegionInfo.h"
21 #include "llvm/Analysis/RegionPass.h"
22 #include "llvm/IR/BasicBlock.h"
23 #include "llvm/IR/Function.h"
24 #include "llvm/Pass.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include <string>
28 using namespace llvm;
30 namespace {
32 struct FunctionPassPrinter : public FunctionPass {
33 const PassInfo *PassToPrint;
34 raw_ostream &Out;
35 static char ID;
36 std::string PassName;
37 bool QuietPass;
39 FunctionPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
40 : FunctionPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
41 std::string PassToPrintName = PassToPrint->getPassName();
42 PassName = "FunctionPass Printer: " + PassToPrintName;
45 bool runOnFunction(Function &F) override {
46 if (!QuietPass)
47 Out << "Printing analysis '" << PassToPrint->getPassName()
48 << "' for function '" << F.getName() << "':\n";
50 // Get and print pass...
51 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, F.getParent());
52 return false;
55 StringRef getPassName() const override { return PassName; }
57 void getAnalysisUsage(AnalysisUsage &AU) const override {
58 AU.addRequiredID(PassToPrint->getTypeInfo());
59 AU.setPreservesAll();
63 char FunctionPassPrinter::ID = 0;
65 struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
66 static char ID;
67 const PassInfo *PassToPrint;
68 raw_ostream &Out;
69 std::string PassName;
70 bool QuietPass;
72 CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
73 : CallGraphSCCPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
74 std::string PassToPrintName = PassToPrint->getPassName();
75 PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
78 bool runOnSCC(CallGraphSCC &SCC) override {
79 if (!QuietPass)
80 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
82 // Get and print pass...
83 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
84 Function *F = (*I)->getFunction();
85 if (F)
86 getAnalysisID<Pass>(PassToPrint->getTypeInfo())
87 .print(Out, F->getParent());
89 return false;
92 StringRef getPassName() const override { return PassName; }
94 void getAnalysisUsage(AnalysisUsage &AU) const override {
95 AU.addRequiredID(PassToPrint->getTypeInfo());
96 AU.setPreservesAll();
100 char CallGraphSCCPassPrinter::ID = 0;
102 struct ModulePassPrinter : public ModulePass {
103 static char ID;
104 const PassInfo *PassToPrint;
105 raw_ostream &Out;
106 std::string PassName;
107 bool QuietPass;
109 ModulePassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
110 : ModulePass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
111 std::string PassToPrintName = PassToPrint->getPassName();
112 PassName = "ModulePass Printer: " + PassToPrintName;
115 bool runOnModule(Module &M) override {
116 if (!QuietPass)
117 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
119 // Get and print pass...
120 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
121 return false;
124 StringRef getPassName() const override { return PassName; }
126 void getAnalysisUsage(AnalysisUsage &AU) const override {
127 AU.addRequiredID(PassToPrint->getTypeInfo());
128 AU.setPreservesAll();
132 char ModulePassPrinter::ID = 0;
134 struct LoopPassPrinter : public LoopPass {
135 static char ID;
136 const PassInfo *PassToPrint;
137 raw_ostream &Out;
138 std::string PassName;
139 bool QuietPass;
141 LoopPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
142 : LoopPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
143 std::string PassToPrintName = PassToPrint->getPassName();
144 PassName = "LoopPass Printer: " + PassToPrintName;
147 bool runOnLoop(Loop *L, LPPassManager &LPM) override {
148 if (!QuietPass)
149 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
151 // Get and print pass...
152 getAnalysisID<Pass>(PassToPrint->getTypeInfo())
153 .print(Out, L->getHeader()->getParent()->getParent());
154 return false;
157 StringRef getPassName() const override { return PassName; }
159 void getAnalysisUsage(AnalysisUsage &AU) const override {
160 AU.addRequiredID(PassToPrint->getTypeInfo());
161 AU.setPreservesAll();
165 char LoopPassPrinter::ID = 0;
167 struct RegionPassPrinter : public RegionPass {
168 static char ID;
169 const PassInfo *PassToPrint;
170 raw_ostream &Out;
171 std::string PassName;
172 bool QuietPass;
174 RegionPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
175 : RegionPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
176 std::string PassToPrintName = PassToPrint->getPassName();
177 PassName = "RegionPass Printer: " + PassToPrintName;
180 bool runOnRegion(Region *R, RGPassManager &RGM) override {
181 if (!QuietPass) {
182 Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
183 << "region: '" << R->getNameStr() << "' in function '"
184 << R->getEntry()->getParent()->getName() << "':\n";
186 // Get and print pass...
187 getAnalysisID<Pass>(PassToPrint->getTypeInfo())
188 .print(Out, R->getEntry()->getParent()->getParent());
189 return false;
192 StringRef getPassName() const override { return PassName; }
194 void getAnalysisUsage(AnalysisUsage &AU) const override {
195 AU.addRequiredID(PassToPrint->getTypeInfo());
196 AU.setPreservesAll();
200 char RegionPassPrinter::ID = 0;
202 struct BasicBlockPassPrinter : public BasicBlockPass {
203 const PassInfo *PassToPrint;
204 raw_ostream &Out;
205 static char ID;
206 std::string PassName;
207 bool QuietPass;
209 BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out, bool Quiet)
210 : BasicBlockPass(ID), PassToPrint(PI), Out(out), QuietPass(Quiet) {
211 std::string PassToPrintName = PassToPrint->getPassName();
212 PassName = "BasicBlockPass Printer: " + PassToPrintName;
215 bool runOnBasicBlock(BasicBlock &BB) override {
216 if (!QuietPass)
217 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
218 << "': Pass " << PassToPrint->getPassName() << ":\n";
220 // Get and print pass...
221 getAnalysisID<Pass>(PassToPrint->getTypeInfo())
222 .print(Out, BB.getParent()->getParent());
223 return false;
226 StringRef getPassName() const override { return PassName; }
228 void getAnalysisUsage(AnalysisUsage &AU) const override {
229 AU.addRequiredID(PassToPrint->getTypeInfo());
230 AU.setPreservesAll();
234 char BasicBlockPassPrinter::ID = 0;
236 } // end anonymous namespace
238 FunctionPass *llvm::createFunctionPassPrinter(const PassInfo *PI,
239 raw_ostream &OS, bool Quiet) {
240 return new FunctionPassPrinter(PI, OS, Quiet);
243 CallGraphSCCPass *llvm::createCallGraphPassPrinter(const PassInfo *PI,
244 raw_ostream &OS,
245 bool Quiet) {
246 return new CallGraphSCCPassPrinter(PI, OS, Quiet);
249 ModulePass *llvm::createModulePassPrinter(const PassInfo *PI, raw_ostream &OS,
250 bool Quiet) {
251 return new ModulePassPrinter(PI, OS, Quiet);
254 LoopPass *llvm::createLoopPassPrinter(const PassInfo *PI, raw_ostream &OS,
255 bool Quiet) {
256 return new LoopPassPrinter(PI, OS, Quiet);
259 RegionPass *llvm::createRegionPassPrinter(const PassInfo *PI, raw_ostream &OS,
260 bool Quiet) {
261 return new RegionPassPrinter(PI, OS, Quiet);
264 BasicBlockPass *llvm::createBasicBlockPassPrinter(const PassInfo *PI,
265 raw_ostream &OS, bool Quiet) {
266 return new BasicBlockPassPrinter(PI, OS, Quiet);