Add a simple breakpoint location printer. This will be used by upcoming "debug info...
[oota-llvm.git] / tools / opt / opt.cpp
1 //===- opt.cpp - The LLVM Modular Optimizer -------------------------------===//
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 // Optimizations may be specified an arbitrary number of times on the command
11 // line, They are run in the order specified.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/LLVMContext.h"
16 #include "llvm/Module.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/CallGraphSCCPass.h"
19 #include "llvm/Bitcode/ReaderWriter.h"
20 #include "llvm/Assembly/PrintModulePass.h"
21 #include "llvm/Analysis/DebugInfo.h"
22 #include "llvm/Analysis/Verifier.h"
23 #include "llvm/Analysis/LoopPass.h"
24 #include "llvm/Analysis/RegionPass.h"
25 #include "llvm/Analysis/CallGraph.h"
26 #include "llvm/Target/TargetData.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Support/PassNameParser.h"
29 #include "llvm/Support/Signals.h"
30 #include "llvm/Support/Debug.h"
31 #include "llvm/Support/IRReader.h"
32 #include "llvm/Support/ManagedStatic.h"
33 #include "llvm/Support/PluginLoader.h"
34 #include "llvm/Support/PrettyStackTrace.h"
35 #include "llvm/Support/StandardPasses.h"
36 #include "llvm/Support/SystemUtils.h"
37 #include "llvm/Support/ToolOutputFile.h"
38 #include "llvm/LinkAllPasses.h"
39 #include "llvm/LinkAllVMCore.h"
40 #include <memory>
41 #include <algorithm>
42 using namespace llvm;
43
44 // The OptimizationList is automatically populated with registered Passes by the
45 // PassNameParser.
46 //
47 static cl::list<const PassInfo*, bool, PassNameParser>
48 PassList(cl::desc("Optimizations available:"));
49
50 // Other command line options...
51 //
52 static cl::opt<std::string>
53 InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
54     cl::init("-"), cl::value_desc("filename"));
55
56 static cl::opt<std::string>
57 OutputFilename("o", cl::desc("Override output filename"),
58                cl::value_desc("filename"));
59
60 static cl::opt<bool>
61 Force("f", cl::desc("Enable binary output on terminals"));
62
63 static cl::opt<bool>
64 PrintEachXForm("p", cl::desc("Print module after each transformation"));
65
66 static cl::opt<bool>
67 NoOutput("disable-output",
68          cl::desc("Do not write result bitcode file"), cl::Hidden);
69
70 static cl::opt<bool>
71 OutputAssembly("S", cl::desc("Write output as LLVM assembly"));
72
73 static cl::opt<bool>
74 NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden);
75
76 static cl::opt<bool>
77 VerifyEach("verify-each", cl::desc("Verify after each transform"));
78
79 static cl::opt<bool>
80 StripDebug("strip-debug",
81            cl::desc("Strip debugger symbol info from translation unit"));
82
83 static cl::opt<bool>
84 DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
85
86 static cl::opt<bool>
87 DisableOptimizations("disable-opt",
88                      cl::desc("Do not run any optimization passes"));
89
90 static cl::opt<bool>
91 DisableInternalize("disable-internalize",
92                    cl::desc("Do not mark all symbols as internal"));
93
94 static cl::opt<bool>
95 StandardCompileOpts("std-compile-opts",
96                    cl::desc("Include the standard compile time optimizations"));
97
98 static cl::opt<bool>
99 StandardLinkOpts("std-link-opts",
100                  cl::desc("Include the standard link time optimizations"));
101
102 static cl::opt<bool>
103 OptLevelO1("O1",
104            cl::desc("Optimization level 1. Similar to llvm-gcc -O1"));
105
106 static cl::opt<bool>
107 OptLevelO2("O2",
108            cl::desc("Optimization level 2. Similar to llvm-gcc -O2"));
109
110 static cl::opt<bool>
111 OptLevelO3("O3",
112            cl::desc("Optimization level 3. Similar to llvm-gcc -O3"));
113
114 static cl::opt<bool>
115 UnitAtATime("funit-at-a-time",
116             cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"),
117             cl::init(true));
118
119 static cl::opt<bool>
120 DisableSimplifyLibCalls("disable-simplify-libcalls",
121                         cl::desc("Disable simplify-libcalls"));
122
123 static cl::opt<bool>
124 Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
125
126 static cl::alias
127 QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
128
129 static cl::opt<bool>
130 AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
131
132 static cl::opt<bool>
133 PrintBreakpoints("print-breakpoints-for-testing", 
134                  cl::desc("Print select breakpoints location for testing"));
135
136 static cl::opt<std::string>
137 DefaultDataLayout("default-data-layout", 
138           cl::desc("data layout string to use if not specified by module"),
139           cl::value_desc("layout-string"), cl::init(""));
140
141 // ---------- Define Printers for module and function passes ------------
142 namespace {
143
144 struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
145   static char ID;
146   const PassInfo *PassToPrint;
147   raw_ostream &Out;
148   std::string PassName;
149
150   CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
151     CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {
152       std::string PassToPrintName =  PassToPrint->getPassName();
153       PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
154     }
155
156   virtual bool runOnSCC(CallGraphSCC &SCC) {
157     if (!Quiet)
158       Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
159
160     // Get and print pass...
161     for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
162       Function *F = (*I)->getFunction();
163       if (F)
164         getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
165                                                               F->getParent());
166     }
167     return false;
168   }
169
170   virtual const char *getPassName() const { return PassName.c_str(); }
171
172   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
173     AU.addRequiredID(PassToPrint->getTypeInfo());
174     AU.setPreservesAll();
175   }
176 };
177
178 char CallGraphSCCPassPrinter::ID = 0;
179
180 struct ModulePassPrinter : public ModulePass {
181   static char ID;
182   const PassInfo *PassToPrint;
183   raw_ostream &Out;
184   std::string PassName;
185
186   ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
187     : ModulePass(ID), PassToPrint(PI), Out(out) {
188       std::string PassToPrintName =  PassToPrint->getPassName();
189       PassName = "ModulePass Printer: " + PassToPrintName;
190     }
191
192   virtual bool runOnModule(Module &M) {
193     if (!Quiet)
194       Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
195
196     // Get and print pass...
197     getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
198     return false;
199   }
200
201   virtual const char *getPassName() const { return PassName.c_str(); }
202
203   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
204     AU.addRequiredID(PassToPrint->getTypeInfo());
205     AU.setPreservesAll();
206   }
207 };
208
209 char ModulePassPrinter::ID = 0;
210 struct FunctionPassPrinter : public FunctionPass {
211   const PassInfo *PassToPrint;
212   raw_ostream &Out;
213   static char ID;
214   std::string PassName;
215
216   FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
217     : FunctionPass(ID), PassToPrint(PI), Out(out) {
218       std::string PassToPrintName =  PassToPrint->getPassName();
219       PassName = "FunctionPass Printer: " + PassToPrintName;
220     }
221
222   virtual bool runOnFunction(Function &F) {
223     if (!Quiet)
224       Out << "Printing analysis '" << PassToPrint->getPassName()
225           << "' for function '" << F.getName() << "':\n";
226
227     // Get and print pass...
228     getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
229             F.getParent());
230     return false;
231   }
232
233   virtual const char *getPassName() const { return PassName.c_str(); }
234
235   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
236     AU.addRequiredID(PassToPrint->getTypeInfo());
237     AU.setPreservesAll();
238   }
239 };
240
241 char FunctionPassPrinter::ID = 0;
242
243 struct LoopPassPrinter : public LoopPass {
244   static char ID;
245   const PassInfo *PassToPrint;
246   raw_ostream &Out;
247   std::string PassName;
248
249   LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
250     LoopPass(ID), PassToPrint(PI), Out(out) {
251       std::string PassToPrintName =  PassToPrint->getPassName();
252       PassName = "LoopPass Printer: " + PassToPrintName;
253     }
254
255
256   virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
257     if (!Quiet)
258       Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
259
260     // Get and print pass...
261     getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
262                         L->getHeader()->getParent()->getParent());
263     return false;
264   }
265
266   virtual const char *getPassName() const { return PassName.c_str(); }
267
268   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
269     AU.addRequiredID(PassToPrint->getTypeInfo());
270     AU.setPreservesAll();
271   }
272 };
273
274 char LoopPassPrinter::ID = 0;
275
276 struct RegionPassPrinter : public RegionPass {
277   static char ID;
278   const PassInfo *PassToPrint;
279   raw_ostream &Out;
280   std::string PassName;
281
282   RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
283     PassToPrint(PI), Out(out) {
284     std::string PassToPrintName =  PassToPrint->getPassName();
285     PassName = "LoopPass Printer: " + PassToPrintName;
286   }
287
288   virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
289     if (!Quiet) {
290       Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
291         << "region: '" << R->getNameStr() << "' in function '"
292         << R->getEntry()->getParent()->getNameStr() << "':\n";
293     }
294     // Get and print pass...
295    getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
296                        R->getEntry()->getParent()->getParent());
297     return false;
298   }
299
300   virtual const char *getPassName() const { return "'Pass' Printer"; }
301
302   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
303     AU.addRequiredID(PassToPrint->getTypeInfo());
304     AU.setPreservesAll();
305   }
306 };
307
308 char RegionPassPrinter::ID = 0;
309
310 struct BasicBlockPassPrinter : public BasicBlockPass {
311   const PassInfo *PassToPrint;
312   raw_ostream &Out;
313   static char ID;
314   std::string PassName;
315
316   BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
317     : BasicBlockPass(ID), PassToPrint(PI), Out(out) {
318       std::string PassToPrintName =  PassToPrint->getPassName();
319       PassName = "BasicBlockPass Printer: " + PassToPrintName;
320     }
321
322   virtual bool runOnBasicBlock(BasicBlock &BB) {
323     if (!Quiet)
324       Out << "Printing Analysis info for BasicBlock '" << BB.getName()
325           << "': Pass " << PassToPrint->getPassName() << ":\n";
326
327     // Get and print pass...
328     getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, 
329             BB.getParent()->getParent());
330     return false;
331   }
332
333   virtual const char *getPassName() const { return PassName.c_str(); }
334
335   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
336     AU.addRequiredID(PassToPrint->getTypeInfo());
337     AU.setPreservesAll();
338   }
339 };
340
341 char BasicBlockPassPrinter::ID = 0;
342
343 struct BreakpointPrinter : public FunctionPass {
344   raw_ostream &Out;
345   static char ID;
346
347   BreakpointPrinter(raw_ostream &out)
348     : FunctionPass(ID), Out(out) {
349     }
350
351   virtual bool runOnFunction(Function &F) {
352     for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
353       BasicBlock::const_iterator BI = I->end();
354       --BI;
355       do {
356         const Instruction *In = BI;
357         const DebugLoc DL = In->getDebugLoc();
358         if (!DL.isUnknown()) {
359           DIScope S(DL.getScope(getGlobalContext()));
360           Out << S.getFilename() << " " << DL.getLine() << "\n";
361           break;
362         }
363         --BI;
364       } while (BI != I->begin());
365       break;
366     }
367     return false;
368   }
369
370   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
371     AU.setPreservesAll();
372   }
373 };
374
375 char BreakpointPrinter::ID = 0;
376
377 inline void addPass(PassManagerBase &PM, Pass *P) {
378   // Add the pass to the pass manager...
379   PM.add(P);
380
381   // If we are verifying all of the intermediate steps, add the verifier...
382   if (VerifyEach) PM.add(createVerifierPass());
383 }
384
385 /// AddOptimizationPasses - This routine adds optimization passes
386 /// based on selected optimization level, OptLevel. This routine
387 /// duplicates llvm-gcc behaviour.
388 ///
389 /// OptLevel - Optimization Level
390 void AddOptimizationPasses(PassManagerBase &MPM, PassManagerBase &FPM,
391                            unsigned OptLevel) {
392   createStandardFunctionPasses(&FPM, OptLevel);
393
394   llvm::Pass *InliningPass = 0;
395   if (DisableInline) {
396     // No inlining pass
397   } else if (OptLevel) {
398     unsigned Threshold = 225;
399     if (OptLevel > 2)
400       Threshold = 275;
401     InliningPass = createFunctionInliningPass(Threshold);
402   } else {
403     InliningPass = createAlwaysInlinerPass();
404   }
405   createStandardModulePasses(&MPM, OptLevel,
406                              /*OptimizeSize=*/ false,
407                              UnitAtATime,
408                              /*UnrollLoops=*/ OptLevel > 1,
409                              !DisableSimplifyLibCalls,
410                              /*HaveExceptions=*/ true,
411                              InliningPass);
412 }
413
414 void AddStandardCompilePasses(PassManagerBase &PM) {
415   PM.add(createVerifierPass());                  // Verify that input is correct
416
417   addPass(PM, createLowerSetJmpPass());          // Lower llvm.setjmp/.longjmp
418
419   // If the -strip-debug command line option was specified, do it.
420   if (StripDebug)
421     addPass(PM, createStripSymbolsPass(true));
422
423   if (DisableOptimizations) return;
424
425   llvm::Pass *InliningPass = !DisableInline ? createFunctionInliningPass() : 0;
426
427   // -std-compile-opts adds the same module passes as -O3.
428   createStandardModulePasses(&PM, 3,
429                              /*OptimizeSize=*/ false,
430                              /*UnitAtATime=*/ true,
431                              /*UnrollLoops=*/ true,
432                              /*SimplifyLibCalls=*/ true,
433                              /*HaveExceptions=*/ true,
434                              InliningPass);
435 }
436
437 void AddStandardLinkPasses(PassManagerBase &PM) {
438   PM.add(createVerifierPass());                  // Verify that input is correct
439
440   // If the -strip-debug command line option was specified, do it.
441   if (StripDebug)
442     addPass(PM, createStripSymbolsPass(true));
443
444   if (DisableOptimizations) return;
445
446   createStandardLTOPasses(&PM, /*Internalize=*/ !DisableInternalize,
447                           /*RunInliner=*/ !DisableInline,
448                           /*VerifyEach=*/ VerifyEach);
449 }
450
451 } // anonymous namespace
452
453
454 //===----------------------------------------------------------------------===//
455 // main for opt
456 //
457 int main(int argc, char **argv) {
458   sys::PrintStackTraceOnErrorSignal();
459   llvm::PrettyStackTraceProgram X(argc, argv);
460
461   // Enable debug stream buffering.
462   EnableDebugBuffering = true;
463
464   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
465   LLVMContext &Context = getGlobalContext();
466   
467   // Initialize passes
468   PassRegistry &Registry = *PassRegistry::getPassRegistry();
469   initializeCore(Registry);
470   initializeScalarOpts(Registry);
471   initializeIPO(Registry);
472   initializeAnalysis(Registry);
473   initializeIPA(Registry);
474   initializeTransformUtils(Registry);
475   initializeInstCombine(Registry);
476   initializeInstrumentation(Registry);
477   initializeTarget(Registry);
478   
479   cl::ParseCommandLineOptions(argc, argv,
480     "llvm .bc -> .bc modular optimizer and analysis printer\n");
481
482   if (AnalyzeOnly && NoOutput) {
483     errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
484     return 1;
485   }
486
487   // Allocate a full target machine description only if necessary.
488   // FIXME: The choice of target should be controllable on the command line.
489   std::auto_ptr<TargetMachine> target;
490
491   SMDiagnostic Err;
492
493   // Load the input module...
494   std::auto_ptr<Module> M;
495   M.reset(ParseIRFile(InputFilename, Err, Context));
496
497   if (M.get() == 0) {
498     Err.Print(argv[0], errs());
499     return 1;
500   }
501
502   // Figure out what stream we are supposed to write to...
503   OwningPtr<tool_output_file> Out;
504   if (NoOutput) {
505     if (!OutputFilename.empty())
506       errs() << "WARNING: The -o (output filename) option is ignored when\n"
507                 "the --disable-output option is used.\n";
508   } else {
509     // Default to standard output.
510     if (OutputFilename.empty())
511       OutputFilename = "-";
512
513     std::string ErrorInfo;
514     Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
515                                    raw_fd_ostream::F_Binary));
516     if (!ErrorInfo.empty()) {
517       errs() << ErrorInfo << '\n';
518       return 1;
519     }
520   }
521
522   // If the output is set to be emitted to standard out, and standard out is a
523   // console, print out a warning message and refuse to do it.  We don't
524   // impress anyone by spewing tons of binary goo to a terminal.
525   if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
526     if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
527       NoOutput = true;
528
529   // Create a PassManager to hold and optimize the collection of passes we are
530   // about to build...
531   //
532   PassManager Passes;
533
534   // Add an appropriate TargetData instance for this module...
535   TargetData *TD = 0;
536   const std::string &ModuleDataLayout = M.get()->getDataLayout();
537   if (!ModuleDataLayout.empty())
538     TD = new TargetData(ModuleDataLayout);
539   else if (!DefaultDataLayout.empty())
540     TD = new TargetData(DefaultDataLayout);
541
542   if (TD)
543     Passes.add(TD);
544
545   OwningPtr<PassManager> FPasses;
546   if (OptLevelO1 || OptLevelO2 || OptLevelO3) {
547     FPasses.reset(new PassManager());
548     if (TD)
549       FPasses->add(new TargetData(*TD));
550   }
551
552   if (PrintBreakpoints) {
553     // Default to standard output.
554     if (!Out) {
555       if (OutputFilename.empty())
556         OutputFilename = "-";
557       
558       std::string ErrorInfo;
559       Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
560                                      raw_fd_ostream::F_Binary));
561       if (!ErrorInfo.empty()) {
562         errs() << ErrorInfo << '\n';
563         return 1;
564       }
565     }
566     Passes.add(new BreakpointPrinter(Out->os()));
567     NoOutput = true;
568   }
569
570   // If the -strip-debug command line option was specified, add it.  If
571   // -std-compile-opts was also specified, it will handle StripDebug.
572   if (StripDebug && !StandardCompileOpts)
573     addPass(Passes, createStripSymbolsPass(true));
574
575   // Create a new optimization pass for each one specified on the command line
576   for (unsigned i = 0; i < PassList.size(); ++i) {
577     // Check to see if -std-compile-opts was specified before this option.  If
578     // so, handle it.
579     if (StandardCompileOpts &&
580         StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
581       AddStandardCompilePasses(Passes);
582       StandardCompileOpts = false;
583     }
584
585     if (StandardLinkOpts &&
586         StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
587       AddStandardLinkPasses(Passes);
588       StandardLinkOpts = false;
589     }
590
591     if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
592       AddOptimizationPasses(Passes, *FPasses, 1);
593       OptLevelO1 = false;
594     }
595
596     if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
597       AddOptimizationPasses(Passes, *FPasses, 2);
598       OptLevelO2 = false;
599     }
600
601     if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
602       AddOptimizationPasses(Passes, *FPasses, 3);
603       OptLevelO3 = false;
604     }
605
606     const PassInfo *PassInf = PassList[i];
607     Pass *P = 0;
608     if (PassInf->getNormalCtor())
609       P = PassInf->getNormalCtor()();
610     else
611       errs() << argv[0] << ": cannot create pass: "
612              << PassInf->getPassName() << "\n";
613     if (P) {
614       PassKind Kind = P->getPassKind();
615       addPass(Passes, P);
616
617       if (AnalyzeOnly) {
618         switch (Kind) {
619         case PT_BasicBlock:
620           Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
621           break;
622         case PT_Region:
623           Passes.add(new RegionPassPrinter(PassInf, Out->os()));
624           break;
625         case PT_Loop:
626           Passes.add(new LoopPassPrinter(PassInf, Out->os()));
627           break;
628         case PT_Function:
629           Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
630           break;
631         case PT_CallGraphSCC:
632           Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
633           break;
634         default:
635           Passes.add(new ModulePassPrinter(PassInf, Out->os()));
636           break;
637         }
638       }
639     }
640
641     if (PrintEachXForm)
642       Passes.add(createPrintModulePass(&errs()));
643   }
644
645   // If -std-compile-opts was specified at the end of the pass list, add them.
646   if (StandardCompileOpts) {
647     AddStandardCompilePasses(Passes);
648     StandardCompileOpts = false;
649   }
650
651   if (StandardLinkOpts) {
652     AddStandardLinkPasses(Passes);
653     StandardLinkOpts = false;
654   }
655
656   if (OptLevelO1)
657     AddOptimizationPasses(Passes, *FPasses, 1);
658
659   if (OptLevelO2)
660     AddOptimizationPasses(Passes, *FPasses, 2);
661
662   if (OptLevelO3)
663     AddOptimizationPasses(Passes, *FPasses, 3);
664
665   if (OptLevelO1 || OptLevelO2 || OptLevelO3)
666     FPasses->run(*M.get());
667
668   // Check that the module is well formed on completion of optimization
669   if (!NoVerify && !VerifyEach)
670     Passes.add(createVerifierPass());
671
672   // Write bitcode or assembly to the output as the last step...
673   if (!NoOutput && !AnalyzeOnly) {
674     if (OutputAssembly)
675       Passes.add(createPrintModulePass(&Out->os()));
676     else
677       Passes.add(createBitcodeWriterPass(Out->os()));
678   }
679
680   // Now that we have all of the passes ready, run them.
681   Passes.run(*M.get());
682
683   // Declare success.
684   if (!NoOutput || PrintBreakpoints)
685     Out->keep();
686
687   return 0;
688 }