1 //===- opt.cpp - The LLVM Modular Optimizer -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Optimizations may be specified an arbitrary number of times on the command
11 // line, They are run in the order specified.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/LLVMContext.h"
16 #include "llvm/DataLayout.h"
17 #include "llvm/DebugInfo.h"
18 #include "llvm/Module.h"
19 #include "llvm/PassManager.h"
20 #include "llvm/CallGraphSCCPass.h"
21 #include "llvm/CodeGen/CommandFlags.h"
22 #include "llvm/Bitcode/ReaderWriter.h"
23 #include "llvm/Assembly/PrintModulePass.h"
24 #include "llvm/Analysis/Verifier.h"
25 #include "llvm/Analysis/LoopPass.h"
26 #include "llvm/Analysis/RegionPass.h"
27 #include "llvm/Analysis/CallGraph.h"
28 #include "llvm/Target/TargetLibraryInfo.h"
29 #include "llvm/Target/TargetMachine.h"
30 #include "llvm/ADT/StringSet.h"
31 #include "llvm/ADT/Triple.h"
32 #include "llvm/Support/PassNameParser.h"
33 #include "llvm/Support/Signals.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/IRReader.h"
36 #include "llvm/Support/ManagedStatic.h"
37 #include "llvm/Support/PluginLoader.h"
38 #include "llvm/Support/PrettyStackTrace.h"
39 #include "llvm/Support/SystemUtils.h"
40 #include "llvm/Support/TargetRegistry.h"
41 #include "llvm/Support/ToolOutputFile.h"
42 #include "llvm/MC/SubtargetFeature.h"
43 #include "llvm/LinkAllPasses.h"
44 #include "llvm/LinkAllVMCore.h"
45 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
50 // The OptimizationList is automatically populated with registered Passes by the
53 static cl::list<const PassInfo*, bool, PassNameParser>
54 PassList(cl::desc("Optimizations available:"));
56 // Other command line options...
58 static cl::opt<std::string>
59 InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
60 cl::init("-"), cl::value_desc("filename"));
62 static cl::opt<std::string>
63 OutputFilename("o", cl::desc("Override output filename"),
64 cl::value_desc("filename"));
67 Force("f", cl::desc("Enable binary output on terminals"));
70 PrintEachXForm("p", cl::desc("Print module after each transformation"));
73 NoOutput("disable-output",
74 cl::desc("Do not write result bitcode file"), cl::Hidden);
77 OutputAssembly("S", cl::desc("Write output as LLVM assembly"));
80 NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden);
83 VerifyEach("verify-each", cl::desc("Verify after each transform"));
86 StripDebug("strip-debug",
87 cl::desc("Strip debugger symbol info from translation unit"));
90 DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
93 DisableOptimizations("disable-opt",
94 cl::desc("Do not run any optimization passes"));
97 DisableInternalize("disable-internalize",
98 cl::desc("Do not mark all symbols as internal"));
101 StandardCompileOpts("std-compile-opts",
102 cl::desc("Include the standard compile time optimizations"));
105 StandardLinkOpts("std-link-opts",
106 cl::desc("Include the standard link time optimizations"));
110 cl::desc("Optimization level 1. Similar to clang -O1"));
114 cl::desc("Optimization level 2. Similar to clang -O2"));
118 cl::desc("Like -O2 with extra optimizations for size. Similar to clang -Os"));
122 cl::desc("Like -Os but reduces code size further. Similar to clang -Oz"));
126 cl::desc("Optimization level 3. Similar to clang -O3"));
128 static cl::opt<std::string>
129 TargetTriple("mtriple", cl::desc("Override target triple for module"));
132 UnitAtATime("funit-at-a-time",
133 cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"),
137 DisableSimplifyLibCalls("disable-simplify-libcalls",
138 cl::desc("Disable simplify-libcalls"));
141 Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
144 QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
147 AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
150 PrintBreakpoints("print-breakpoints-for-testing",
151 cl::desc("Print select breakpoints location for testing"));
153 static cl::opt<std::string>
154 DefaultDataLayout("default-data-layout",
155 cl::desc("data layout string to use if not specified by module"),
156 cl::value_desc("layout-string"), cl::init(""));
158 // ---------- Define Printers for module and function passes ------------
161 struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
163 const PassInfo *PassToPrint;
165 std::string PassName;
167 CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
168 CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {
169 std::string PassToPrintName = PassToPrint->getPassName();
170 PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
173 virtual bool runOnSCC(CallGraphSCC &SCC) {
175 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
177 // Get and print pass...
178 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
179 Function *F = (*I)->getFunction();
181 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
187 virtual const char *getPassName() const { return PassName.c_str(); }
189 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
190 AU.addRequiredID(PassToPrint->getTypeInfo());
191 AU.setPreservesAll();
195 char CallGraphSCCPassPrinter::ID = 0;
197 struct ModulePassPrinter : public ModulePass {
199 const PassInfo *PassToPrint;
201 std::string PassName;
203 ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
204 : ModulePass(ID), PassToPrint(PI), Out(out) {
205 std::string PassToPrintName = PassToPrint->getPassName();
206 PassName = "ModulePass Printer: " + PassToPrintName;
209 virtual bool runOnModule(Module &M) {
211 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
213 // Get and print pass...
214 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
218 virtual const char *getPassName() const { return PassName.c_str(); }
220 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
221 AU.addRequiredID(PassToPrint->getTypeInfo());
222 AU.setPreservesAll();
226 char ModulePassPrinter::ID = 0;
227 struct FunctionPassPrinter : public FunctionPass {
228 const PassInfo *PassToPrint;
231 std::string PassName;
233 FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
234 : FunctionPass(ID), PassToPrint(PI), Out(out) {
235 std::string PassToPrintName = PassToPrint->getPassName();
236 PassName = "FunctionPass Printer: " + PassToPrintName;
239 virtual bool runOnFunction(Function &F) {
241 Out << "Printing analysis '" << PassToPrint->getPassName()
242 << "' for function '" << F.getName() << "':\n";
244 // Get and print pass...
245 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
250 virtual const char *getPassName() const { return PassName.c_str(); }
252 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
253 AU.addRequiredID(PassToPrint->getTypeInfo());
254 AU.setPreservesAll();
258 char FunctionPassPrinter::ID = 0;
260 struct LoopPassPrinter : public LoopPass {
262 const PassInfo *PassToPrint;
264 std::string PassName;
266 LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
267 LoopPass(ID), PassToPrint(PI), Out(out) {
268 std::string PassToPrintName = PassToPrint->getPassName();
269 PassName = "LoopPass Printer: " + PassToPrintName;
273 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
275 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
277 // Get and print pass...
278 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
279 L->getHeader()->getParent()->getParent());
283 virtual const char *getPassName() const { return PassName.c_str(); }
285 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
286 AU.addRequiredID(PassToPrint->getTypeInfo());
287 AU.setPreservesAll();
291 char LoopPassPrinter::ID = 0;
293 struct RegionPassPrinter : public RegionPass {
295 const PassInfo *PassToPrint;
297 std::string PassName;
299 RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
300 PassToPrint(PI), Out(out) {
301 std::string PassToPrintName = PassToPrint->getPassName();
302 PassName = "RegionPass Printer: " + PassToPrintName;
305 virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
307 Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
308 << "region: '" << R->getNameStr() << "' in function '"
309 << R->getEntry()->getParent()->getName() << "':\n";
311 // Get and print pass...
312 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
313 R->getEntry()->getParent()->getParent());
317 virtual const char *getPassName() const { return PassName.c_str(); }
319 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
320 AU.addRequiredID(PassToPrint->getTypeInfo());
321 AU.setPreservesAll();
325 char RegionPassPrinter::ID = 0;
327 struct BasicBlockPassPrinter : public BasicBlockPass {
328 const PassInfo *PassToPrint;
331 std::string PassName;
333 BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
334 : BasicBlockPass(ID), PassToPrint(PI), Out(out) {
335 std::string PassToPrintName = PassToPrint->getPassName();
336 PassName = "BasicBlockPass Printer: " + PassToPrintName;
339 virtual bool runOnBasicBlock(BasicBlock &BB) {
341 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
342 << "': Pass " << PassToPrint->getPassName() << ":\n";
344 // Get and print pass...
345 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
346 BB.getParent()->getParent());
350 virtual const char *getPassName() const { return PassName.c_str(); }
352 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
353 AU.addRequiredID(PassToPrint->getTypeInfo());
354 AU.setPreservesAll();
358 char BasicBlockPassPrinter::ID = 0;
360 struct BreakpointPrinter : public ModulePass {
364 BreakpointPrinter(raw_ostream &out)
365 : ModulePass(ID), Out(out) {
368 void getContextName(DIDescriptor Context, std::string &N) {
369 if (Context.isNameSpace()) {
370 DINameSpace NS(Context);
371 if (!NS.getName().empty()) {
372 getContextName(NS.getContext(), N);
373 N = N + NS.getName().str() + "::";
375 } else if (Context.isType()) {
377 if (!TY.getName().empty()) {
378 getContextName(TY.getContext(), N);
379 N = N + TY.getName().str() + "::";
384 virtual bool runOnModule(Module &M) {
385 StringSet<> Processed;
386 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
387 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
389 DISubprogram SP(NMD->getOperand(i));
391 getContextName(SP.getContext(), Name);
392 Name = Name + SP.getDisplayName().str();
393 if (!Name.empty() && Processed.insert(Name)) {
400 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
401 AU.setPreservesAll();
405 } // anonymous namespace
407 char BreakpointPrinter::ID = 0;
409 static inline void addPass(PassManagerBase &PM, Pass *P) {
410 // Add the pass to the pass manager...
413 // If we are verifying all of the intermediate steps, add the verifier...
414 if (VerifyEach) PM.add(createVerifierPass());
417 /// AddOptimizationPasses - This routine adds optimization passes
418 /// based on selected optimization level, OptLevel. This routine
419 /// duplicates llvm-gcc behaviour.
421 /// OptLevel - Optimization Level
422 static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
423 unsigned OptLevel, unsigned SizeLevel) {
424 FPM.add(createVerifierPass()); // Verify that input is correct
426 PassManagerBuilder Builder;
427 Builder.OptLevel = OptLevel;
428 Builder.SizeLevel = SizeLevel;
432 } else if (OptLevel > 1) {
433 unsigned Threshold = 225;
434 if (SizeLevel == 1) // -Os
436 else if (SizeLevel == 2) // -Oz
440 Builder.Inliner = createFunctionInliningPass(Threshold);
442 Builder.Inliner = createAlwaysInlinerPass();
444 Builder.DisableUnitAtATime = !UnitAtATime;
445 Builder.DisableUnrollLoops = OptLevel == 0;
446 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
448 Builder.populateFunctionPassManager(FPM);
449 Builder.populateModulePassManager(MPM);
452 static void AddStandardCompilePasses(PassManagerBase &PM) {
453 PM.add(createVerifierPass()); // Verify that input is correct
455 // If the -strip-debug command line option was specified, do it.
457 addPass(PM, createStripSymbolsPass(true));
459 if (DisableOptimizations) return;
461 // -std-compile-opts adds the same module passes as -O3.
462 PassManagerBuilder Builder;
464 Builder.Inliner = createFunctionInliningPass();
465 Builder.OptLevel = 3;
466 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
467 Builder.populateModulePassManager(PM);
470 static void AddStandardLinkPasses(PassManagerBase &PM) {
471 PM.add(createVerifierPass()); // Verify that input is correct
473 // If the -strip-debug command line option was specified, do it.
475 addPass(PM, createStripSymbolsPass(true));
477 if (DisableOptimizations) return;
479 PassManagerBuilder Builder;
480 Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
481 /*RunInliner=*/ !DisableInline);
484 //===----------------------------------------------------------------------===//
485 // CodeGen-related helper functions.
487 static TargetOptions GetTargetOptions() {
488 TargetOptions Options;
489 Options.LessPreciseFPMADOption = EnableFPMAD;
490 Options.NoFramePointerElim = DisableFPElim;
491 Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
492 Options.AllowFPOpFusion = FuseFPOps;
493 Options.UnsafeFPMath = EnableUnsafeFPMath;
494 Options.NoInfsFPMath = EnableNoInfsFPMath;
495 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
496 Options.HonorSignDependentRoundingFPMathOption =
497 EnableHonorSignDependentRoundingFPMath;
498 Options.UseSoftFloat = GenerateSoftFloatCalls;
499 if (FloatABIForCalls != FloatABI::Default)
500 Options.FloatABIType = FloatABIForCalls;
501 Options.NoZerosInBSS = DontPlaceZerosInBSS;
502 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
503 Options.DisableTailCalls = DisableTailCalls;
504 Options.StackAlignmentOverride = OverrideStackAlignment;
505 Options.RealignStack = EnableRealignStack;
506 Options.TrapFuncName = TrapFuncName;
507 Options.PositionIndependentExecutable = EnablePIE;
508 Options.EnableSegmentedStacks = SegmentedStacks;
509 Options.UseInitArray = UseInitArray;
510 Options.SSPBufferSize = SSPBufferSize;
514 CodeGenOpt::Level GetCodeGenOptLevel() {
516 return CodeGenOpt::Less;
518 return CodeGenOpt::Default;
520 return CodeGenOpt::Aggressive;
521 return CodeGenOpt::None;
524 // Returns the TargetMachine instance or zero if no triple is provided.
525 static TargetMachine* GetTargetMachine(std::string TripleStr) {
526 if (TripleStr.empty())
529 // Get the target specific parser.
531 Triple TheTriple(Triple::normalize(TargetTriple));
533 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
539 // Package up features to be passed to target/subtarget
540 std::string FeaturesStr;
542 SubtargetFeatures Features;
543 for (unsigned i = 0; i != MAttrs.size(); ++i)
544 Features.AddFeature(MAttrs[i]);
545 FeaturesStr = Features.getString();
548 return TheTarget->createTargetMachine(TheTriple.getTriple(),
549 MCPU, FeaturesStr, GetTargetOptions(),
551 GetCodeGenOptLevel());
554 //===----------------------------------------------------------------------===//
557 int main(int argc, char **argv) {
558 sys::PrintStackTraceOnErrorSignal();
559 llvm::PrettyStackTraceProgram X(argc, argv);
561 // Enable debug stream buffering.
562 EnableDebugBuffering = true;
564 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
565 LLVMContext &Context = getGlobalContext();
568 PassRegistry &Registry = *PassRegistry::getPassRegistry();
569 initializeCore(Registry);
570 initializeScalarOpts(Registry);
571 initializeVectorization(Registry);
572 initializeIPO(Registry);
573 initializeAnalysis(Registry);
574 initializeIPA(Registry);
575 initializeTransformUtils(Registry);
576 initializeInstCombine(Registry);
577 initializeInstrumentation(Registry);
578 initializeTarget(Registry);
580 cl::ParseCommandLineOptions(argc, argv,
581 "llvm .bc -> .bc modular optimizer and analysis printer\n");
583 if (AnalyzeOnly && NoOutput) {
584 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
590 // Load the input module...
591 std::auto_ptr<Module> M;
592 M.reset(ParseIRFile(InputFilename, Err, Context));
595 Err.print(argv[0], errs());
599 // If we are supposed to override the target triple, do so now.
600 if (!TargetTriple.empty())
601 M->setTargetTriple(Triple::normalize(TargetTriple));
603 // Figure out what stream we are supposed to write to...
604 OwningPtr<tool_output_file> Out;
606 if (!OutputFilename.empty())
607 errs() << "WARNING: The -o (output filename) option is ignored when\n"
608 "the --disable-output option is used.\n";
610 // Default to standard output.
611 if (OutputFilename.empty())
612 OutputFilename = "-";
614 std::string ErrorInfo;
615 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
616 raw_fd_ostream::F_Binary));
617 if (!ErrorInfo.empty()) {
618 errs() << ErrorInfo << '\n';
623 // If the output is set to be emitted to standard out, and standard out is a
624 // console, print out a warning message and refuse to do it. We don't
625 // impress anyone by spewing tons of binary goo to a terminal.
626 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
627 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
630 // Create a PassManager to hold and optimize the collection of passes we are
635 // Add an appropriate TargetLibraryInfo pass for the module's triple.
636 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
638 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
639 if (DisableSimplifyLibCalls)
640 TLI->disableAllFunctions();
643 // Add an appropriate DataLayout instance for this module.
645 const std::string &ModuleDataLayout = M.get()->getDataLayout();
646 if (!ModuleDataLayout.empty())
647 TD = new DataLayout(ModuleDataLayout);
648 else if (!DefaultDataLayout.empty())
649 TD = new DataLayout(DefaultDataLayout);
654 std::auto_ptr<TargetMachine> TM(GetTargetMachine(TargetTriple));
656 Passes.add(new TargetTransformInfo(TM->getScalarTargetTransformInfo(),
657 TM->getVectorTargetTransformInfo()));
660 OwningPtr<FunctionPassManager> FPasses;
661 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
662 FPasses.reset(new FunctionPassManager(M.get()));
664 FPasses->add(new DataLayout(*TD));
667 if (PrintBreakpoints) {
668 // Default to standard output.
670 if (OutputFilename.empty())
671 OutputFilename = "-";
673 std::string ErrorInfo;
674 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
675 raw_fd_ostream::F_Binary));
676 if (!ErrorInfo.empty()) {
677 errs() << ErrorInfo << '\n';
681 Passes.add(new BreakpointPrinter(Out->os()));
685 // If the -strip-debug command line option was specified, add it. If
686 // -std-compile-opts was also specified, it will handle StripDebug.
687 if (StripDebug && !StandardCompileOpts)
688 addPass(Passes, createStripSymbolsPass(true));
690 // Create a new optimization pass for each one specified on the command line
691 for (unsigned i = 0; i < PassList.size(); ++i) {
692 // Check to see if -std-compile-opts was specified before this option. If
694 if (StandardCompileOpts &&
695 StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
696 AddStandardCompilePasses(Passes);
697 StandardCompileOpts = false;
700 if (StandardLinkOpts &&
701 StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
702 AddStandardLinkPasses(Passes);
703 StandardLinkOpts = false;
706 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
707 AddOptimizationPasses(Passes, *FPasses, 1, 0);
711 if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
712 AddOptimizationPasses(Passes, *FPasses, 2, 0);
716 if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) {
717 AddOptimizationPasses(Passes, *FPasses, 2, 1);
721 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) {
722 AddOptimizationPasses(Passes, *FPasses, 2, 2);
726 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
727 AddOptimizationPasses(Passes, *FPasses, 3, 0);
731 const PassInfo *PassInf = PassList[i];
733 if (PassInf->getNormalCtor())
734 P = PassInf->getNormalCtor()();
736 errs() << argv[0] << ": cannot create pass: "
737 << PassInf->getPassName() << "\n";
739 PassKind Kind = P->getPassKind();
745 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
748 Passes.add(new RegionPassPrinter(PassInf, Out->os()));
751 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
754 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
756 case PT_CallGraphSCC:
757 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
760 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
767 Passes.add(createPrintModulePass(&errs()));
770 // If -std-compile-opts was specified at the end of the pass list, add them.
771 if (StandardCompileOpts) {
772 AddStandardCompilePasses(Passes);
773 StandardCompileOpts = false;
776 if (StandardLinkOpts) {
777 AddStandardLinkPasses(Passes);
778 StandardLinkOpts = false;
782 AddOptimizationPasses(Passes, *FPasses, 1, 0);
785 AddOptimizationPasses(Passes, *FPasses, 2, 0);
788 AddOptimizationPasses(Passes, *FPasses, 2, 1);
791 AddOptimizationPasses(Passes, *FPasses, 2, 2);
794 AddOptimizationPasses(Passes, *FPasses, 3, 0);
796 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
797 FPasses->doInitialization();
798 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
800 FPasses->doFinalization();
803 // Check that the module is well formed on completion of optimization
804 if (!NoVerify && !VerifyEach)
805 Passes.add(createVerifierPass());
807 // Write bitcode or assembly to the output as the last step...
808 if (!NoOutput && !AnalyzeOnly) {
810 Passes.add(createPrintModulePass(&Out->os()));
812 Passes.add(createBitcodeWriterPass(Out->os()));
815 // Before executing passes, print the final values of the LLVM options.
816 cl::PrintOptionValues();
818 // Now that we have all of the passes ready, run them.
819 Passes.run(*M.get());
822 if (!NoOutput || PrintBreakpoints)