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/IR/LLVMContext.h"
16 #include "llvm/ADT/StringSet.h"
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Analysis/CallGraph.h"
19 #include "llvm/Analysis/CallGraphSCCPass.h"
20 #include "llvm/Analysis/LoopPass.h"
21 #include "llvm/Analysis/RegionPass.h"
22 #include "llvm/Analysis/Verifier.h"
23 #include "llvm/Assembly/PrintModulePass.h"
24 #include "llvm/Bitcode/ReaderWriter.h"
25 #include "llvm/CodeGen/CommandFlags.h"
26 #include "llvm/DebugInfo.h"
27 #include "llvm/IR/DataLayout.h"
28 #include "llvm/IR/Module.h"
29 #include "llvm/IRReader/IRReader.h"
30 #include "llvm/LinkAllIR.h"
31 #include "llvm/LinkAllPasses.h"
32 #include "llvm/MC/SubtargetFeature.h"
33 #include "llvm/PassManager.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/ManagedStatic.h"
36 #include "llvm/Support/PassNameParser.h"
37 #include "llvm/Support/PluginLoader.h"
38 #include "llvm/Support/PrettyStackTrace.h"
39 #include "llvm/Support/Signals.h"
40 #include "llvm/Support/SourceMgr.h"
41 #include "llvm/Support/SystemUtils.h"
42 #include "llvm/Support/TargetRegistry.h"
43 #include "llvm/Support/TargetSelect.h"
44 #include "llvm/Support/ToolOutputFile.h"
45 #include "llvm/Target/TargetLibraryInfo.h"
46 #include "llvm/Target/TargetMachine.h"
47 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
52 // The OptimizationList is automatically populated with registered Passes by the
55 static cl::list<const PassInfo*, bool, PassNameParser>
56 PassList(cl::desc("Optimizations available:"));
58 // Other command line options...
60 static cl::opt<std::string>
61 InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
62 cl::init("-"), cl::value_desc("filename"));
64 static cl::opt<std::string>
65 OutputFilename("o", cl::desc("Override output filename"),
66 cl::value_desc("filename"));
69 Force("f", cl::desc("Enable binary output on terminals"));
72 PrintEachXForm("p", cl::desc("Print module after each transformation"));
75 NoOutput("disable-output",
76 cl::desc("Do not write result bitcode file"), cl::Hidden);
79 OutputAssembly("S", cl::desc("Write output as LLVM assembly"));
82 NoVerify("disable-verify", cl::desc("Do not verify result module"), cl::Hidden);
85 VerifyEach("verify-each", cl::desc("Verify after each transform"));
88 StripDebug("strip-debug",
89 cl::desc("Strip debugger symbol info from translation unit"));
92 DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
95 DisableOptimizations("disable-opt",
96 cl::desc("Do not run any optimization passes"));
99 DisableInternalize("disable-internalize",
100 cl::desc("Do not mark all symbols as internal"));
103 StandardCompileOpts("std-compile-opts",
104 cl::desc("Include the standard compile time optimizations"));
107 StandardLinkOpts("std-link-opts",
108 cl::desc("Include the standard link time optimizations"));
112 cl::desc("Optimization level 1. Similar to clang -O1"));
116 cl::desc("Optimization level 2. Similar to clang -O2"));
120 cl::desc("Like -O2 with extra optimizations for size. Similar to clang -Os"));
124 cl::desc("Like -Os but reduces code size further. Similar to clang -Oz"));
128 cl::desc("Optimization level 3. Similar to clang -O3"));
130 static cl::opt<std::string>
131 TargetTriple("mtriple", cl::desc("Override target triple for module"));
134 UnitAtATime("funit-at-a-time",
135 cl::desc("Enable IPO. This is same as llvm-gcc's -funit-at-a-time"),
139 DisableSimplifyLibCalls("disable-simplify-libcalls",
140 cl::desc("Disable simplify-libcalls"));
143 Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
146 QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
149 AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
152 PrintBreakpoints("print-breakpoints-for-testing",
153 cl::desc("Print select breakpoints location for testing"));
155 static cl::opt<std::string>
156 DefaultDataLayout("default-data-layout",
157 cl::desc("data layout string to use if not specified by module"),
158 cl::value_desc("layout-string"), cl::init(""));
160 // ---------- Define Printers for module and function passes ------------
163 struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
165 const PassInfo *PassToPrint;
167 std::string PassName;
169 CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
170 CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {
171 std::string PassToPrintName = PassToPrint->getPassName();
172 PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
175 virtual bool runOnSCC(CallGraphSCC &SCC) {
177 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
179 // Get and print pass...
180 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
181 Function *F = (*I)->getFunction();
183 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
189 virtual const char *getPassName() const { return PassName.c_str(); }
191 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
192 AU.addRequiredID(PassToPrint->getTypeInfo());
193 AU.setPreservesAll();
197 char CallGraphSCCPassPrinter::ID = 0;
199 struct ModulePassPrinter : public ModulePass {
201 const PassInfo *PassToPrint;
203 std::string PassName;
205 ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
206 : ModulePass(ID), PassToPrint(PI), Out(out) {
207 std::string PassToPrintName = PassToPrint->getPassName();
208 PassName = "ModulePass Printer: " + PassToPrintName;
211 virtual bool runOnModule(Module &M) {
213 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
215 // Get and print pass...
216 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
220 virtual const char *getPassName() const { return PassName.c_str(); }
222 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
223 AU.addRequiredID(PassToPrint->getTypeInfo());
224 AU.setPreservesAll();
228 char ModulePassPrinter::ID = 0;
229 struct FunctionPassPrinter : public FunctionPass {
230 const PassInfo *PassToPrint;
233 std::string PassName;
235 FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
236 : FunctionPass(ID), PassToPrint(PI), Out(out) {
237 std::string PassToPrintName = PassToPrint->getPassName();
238 PassName = "FunctionPass Printer: " + PassToPrintName;
241 virtual bool runOnFunction(Function &F) {
243 Out << "Printing analysis '" << PassToPrint->getPassName()
244 << "' for function '" << F.getName() << "':\n";
246 // Get and print pass...
247 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
252 virtual const char *getPassName() const { return PassName.c_str(); }
254 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
255 AU.addRequiredID(PassToPrint->getTypeInfo());
256 AU.setPreservesAll();
260 char FunctionPassPrinter::ID = 0;
262 struct LoopPassPrinter : public LoopPass {
264 const PassInfo *PassToPrint;
266 std::string PassName;
268 LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
269 LoopPass(ID), PassToPrint(PI), Out(out) {
270 std::string PassToPrintName = PassToPrint->getPassName();
271 PassName = "LoopPass Printer: " + PassToPrintName;
275 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
277 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
279 // Get and print pass...
280 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
281 L->getHeader()->getParent()->getParent());
285 virtual const char *getPassName() const { return PassName.c_str(); }
287 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
288 AU.addRequiredID(PassToPrint->getTypeInfo());
289 AU.setPreservesAll();
293 char LoopPassPrinter::ID = 0;
295 struct RegionPassPrinter : public RegionPass {
297 const PassInfo *PassToPrint;
299 std::string PassName;
301 RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
302 PassToPrint(PI), Out(out) {
303 std::string PassToPrintName = PassToPrint->getPassName();
304 PassName = "RegionPass Printer: " + PassToPrintName;
307 virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
309 Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
310 << "region: '" << R->getNameStr() << "' in function '"
311 << R->getEntry()->getParent()->getName() << "':\n";
313 // Get and print pass...
314 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
315 R->getEntry()->getParent()->getParent());
319 virtual const char *getPassName() const { return PassName.c_str(); }
321 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
322 AU.addRequiredID(PassToPrint->getTypeInfo());
323 AU.setPreservesAll();
327 char RegionPassPrinter::ID = 0;
329 struct BasicBlockPassPrinter : public BasicBlockPass {
330 const PassInfo *PassToPrint;
333 std::string PassName;
335 BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
336 : BasicBlockPass(ID), PassToPrint(PI), Out(out) {
337 std::string PassToPrintName = PassToPrint->getPassName();
338 PassName = "BasicBlockPass Printer: " + PassToPrintName;
341 virtual bool runOnBasicBlock(BasicBlock &BB) {
343 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
344 << "': Pass " << PassToPrint->getPassName() << ":\n";
346 // Get and print pass...
347 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
348 BB.getParent()->getParent());
352 virtual const char *getPassName() const { return PassName.c_str(); }
354 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
355 AU.addRequiredID(PassToPrint->getTypeInfo());
356 AU.setPreservesAll();
360 char BasicBlockPassPrinter::ID = 0;
362 struct BreakpointPrinter : public ModulePass {
366 BreakpointPrinter(raw_ostream &out)
367 : ModulePass(ID), Out(out) {
370 void getContextName(DIDescriptor Context, std::string &N) {
371 if (Context.isNameSpace()) {
372 DINameSpace NS(Context);
373 if (!NS.getName().empty()) {
374 getContextName(NS.getContext(), N);
375 N = N + NS.getName().str() + "::";
377 } else if (Context.isType()) {
379 if (!TY.getName().empty()) {
380 getContextName(TY.getContext(), N);
381 N = N + TY.getName().str() + "::";
386 virtual bool runOnModule(Module &M) {
387 StringSet<> Processed;
388 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
389 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
391 DISubprogram SP(NMD->getOperand(i));
392 assert((!SP || SP.isSubprogram()) &&
393 "A MDNode in llvm.dbg.sp should be null or a DISubprogram.");
396 getContextName(SP.getContext(), Name);
397 Name = Name + SP.getDisplayName().str();
398 if (!Name.empty() && Processed.insert(Name)) {
405 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
406 AU.setPreservesAll();
410 } // anonymous namespace
412 char BreakpointPrinter::ID = 0;
414 static inline void addPass(PassManagerBase &PM, Pass *P) {
415 // Add the pass to the pass manager...
418 // If we are verifying all of the intermediate steps, add the verifier...
419 if (VerifyEach) PM.add(createVerifierPass());
422 /// AddOptimizationPasses - This routine adds optimization passes
423 /// based on selected optimization level, OptLevel. This routine
424 /// duplicates llvm-gcc behaviour.
426 /// OptLevel - Optimization Level
427 static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
428 unsigned OptLevel, unsigned SizeLevel) {
429 FPM.add(createVerifierPass()); // Verify that input is correct
431 PassManagerBuilder Builder;
432 Builder.OptLevel = OptLevel;
433 Builder.SizeLevel = SizeLevel;
437 } else if (OptLevel > 1) {
438 unsigned Threshold = 225;
439 if (SizeLevel == 1) // -Os
441 else if (SizeLevel == 2) // -Oz
445 Builder.Inliner = createFunctionInliningPass(Threshold);
447 Builder.Inliner = createAlwaysInlinerPass();
449 Builder.DisableUnitAtATime = !UnitAtATime;
450 Builder.DisableUnrollLoops = OptLevel == 0;
452 Builder.populateFunctionPassManager(FPM);
453 Builder.populateModulePassManager(MPM);
456 static void AddStandardCompilePasses(PassManagerBase &PM) {
457 PM.add(createVerifierPass()); // Verify that input is correct
459 // If the -strip-debug command line option was specified, do it.
461 addPass(PM, createStripSymbolsPass(true));
463 if (DisableOptimizations) return;
465 // -std-compile-opts adds the same module passes as -O3.
466 PassManagerBuilder Builder;
468 Builder.Inliner = createFunctionInliningPass();
469 Builder.OptLevel = 3;
470 Builder.populateModulePassManager(PM);
473 static void AddStandardLinkPasses(PassManagerBase &PM) {
474 PM.add(createVerifierPass()); // Verify that input is correct
476 // If the -strip-debug command line option was specified, do it.
478 addPass(PM, createStripSymbolsPass(true));
480 if (DisableOptimizations) return;
482 PassManagerBuilder Builder;
483 Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
484 /*RunInliner=*/ !DisableInline);
487 //===----------------------------------------------------------------------===//
488 // CodeGen-related helper functions.
490 static TargetOptions GetTargetOptions() {
491 TargetOptions Options;
492 Options.LessPreciseFPMADOption = EnableFPMAD;
493 Options.NoFramePointerElim = DisableFPElim;
494 Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
495 Options.AllowFPOpFusion = FuseFPOps;
496 Options.UnsafeFPMath = EnableUnsafeFPMath;
497 Options.NoInfsFPMath = EnableNoInfsFPMath;
498 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
499 Options.HonorSignDependentRoundingFPMathOption =
500 EnableHonorSignDependentRoundingFPMath;
501 Options.UseSoftFloat = GenerateSoftFloatCalls;
502 if (FloatABIForCalls != FloatABI::Default)
503 Options.FloatABIType = FloatABIForCalls;
504 Options.NoZerosInBSS = DontPlaceZerosInBSS;
505 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
506 Options.DisableTailCalls = DisableTailCalls;
507 Options.StackAlignmentOverride = OverrideStackAlignment;
508 Options.RealignStack = EnableRealignStack;
509 Options.TrapFuncName = TrapFuncName;
510 Options.PositionIndependentExecutable = EnablePIE;
511 Options.EnableSegmentedStacks = SegmentedStacks;
512 Options.UseInitArray = UseInitArray;
513 Options.SSPBufferSize = SSPBufferSize;
517 CodeGenOpt::Level GetCodeGenOptLevel() {
519 return CodeGenOpt::Less;
521 return CodeGenOpt::Default;
523 return CodeGenOpt::Aggressive;
524 return CodeGenOpt::None;
527 // Returns the TargetMachine instance or zero if no triple is provided.
528 static TargetMachine* GetTargetMachine(Triple TheTriple) {
530 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
532 // Some modules don't specify a triple, and this is okay.
537 // Package up features to be passed to target/subtarget
538 std::string FeaturesStr;
540 SubtargetFeatures Features;
541 for (unsigned i = 0; i != MAttrs.size(); ++i)
542 Features.AddFeature(MAttrs[i]);
543 FeaturesStr = Features.getString();
546 return TheTarget->createTargetMachine(TheTriple.getTriple(),
547 MCPU, FeaturesStr, GetTargetOptions(),
549 GetCodeGenOptLevel());
552 //===----------------------------------------------------------------------===//
555 int main(int argc, char **argv) {
556 sys::PrintStackTraceOnErrorSignal();
557 llvm::PrettyStackTraceProgram X(argc, argv);
559 // Enable debug stream buffering.
560 EnableDebugBuffering = true;
562 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
563 LLVMContext &Context = getGlobalContext();
565 InitializeAllTargets();
566 InitializeAllTargetMCs();
569 PassRegistry &Registry = *PassRegistry::getPassRegistry();
570 initializeCore(Registry);
571 initializeDebugIRPass(Registry);
572 initializeScalarOpts(Registry);
573 initializeObjCARCOpts(Registry);
574 initializeVectorization(Registry);
575 initializeIPO(Registry);
576 initializeAnalysis(Registry);
577 initializeIPA(Registry);
578 initializeTransformUtils(Registry);
579 initializeInstCombine(Registry);
580 initializeInstrumentation(Registry);
581 initializeTarget(Registry);
583 cl::ParseCommandLineOptions(argc, argv,
584 "llvm .bc -> .bc modular optimizer and analysis printer\n");
586 if (AnalyzeOnly && NoOutput) {
587 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
593 // Load the input module...
595 M.reset(ParseIRFile(InputFilename, Err, Context));
598 Err.print(argv[0], errs());
602 // If we are supposed to override the target triple, do so now.
603 if (!TargetTriple.empty())
604 M->setTargetTriple(Triple::normalize(TargetTriple));
606 // Figure out what stream we are supposed to write to...
607 OwningPtr<tool_output_file> Out;
609 if (!OutputFilename.empty())
610 errs() << "WARNING: The -o (output filename) option is ignored when\n"
611 "the --disable-output option is used.\n";
613 // Default to standard output.
614 if (OutputFilename.empty())
615 OutputFilename = "-";
617 std::string ErrorInfo;
618 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
620 if (!ErrorInfo.empty()) {
621 errs() << ErrorInfo << '\n';
626 // If the output is set to be emitted to standard out, and standard out is a
627 // console, print out a warning message and refuse to do it. We don't
628 // impress anyone by spewing tons of binary goo to a terminal.
629 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
630 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
633 // Create a PassManager to hold and optimize the collection of passes we are
638 // Add an appropriate TargetLibraryInfo pass for the module's triple.
639 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
641 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
642 if (DisableSimplifyLibCalls)
643 TLI->disableAllFunctions();
646 // Add an appropriate DataLayout instance for this module.
648 const std::string &ModuleDataLayout = M.get()->getDataLayout();
649 if (!ModuleDataLayout.empty())
650 TD = new DataLayout(ModuleDataLayout);
651 else if (!DefaultDataLayout.empty())
652 TD = new DataLayout(DefaultDataLayout);
657 Triple ModuleTriple(M->getTargetTriple());
658 TargetMachine *Machine = 0;
659 if (ModuleTriple.getArch())
660 Machine = GetTargetMachine(Triple(ModuleTriple));
661 OwningPtr<TargetMachine> TM(Machine);
663 // Add internal analysis passes from the target machine.
665 TM->addAnalysisPasses(Passes);
667 OwningPtr<FunctionPassManager> FPasses;
668 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
669 FPasses.reset(new FunctionPassManager(M.get()));
671 FPasses->add(new DataLayout(*TD));
674 if (PrintBreakpoints) {
675 // Default to standard output.
677 if (OutputFilename.empty())
678 OutputFilename = "-";
680 std::string ErrorInfo;
681 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
683 if (!ErrorInfo.empty()) {
684 errs() << ErrorInfo << '\n';
688 Passes.add(new BreakpointPrinter(Out->os()));
692 // If the -strip-debug command line option was specified, add it. If
693 // -std-compile-opts was also specified, it will handle StripDebug.
694 if (StripDebug && !StandardCompileOpts)
695 addPass(Passes, createStripSymbolsPass(true));
697 // Create a new optimization pass for each one specified on the command line
698 for (unsigned i = 0; i < PassList.size(); ++i) {
699 // Check to see if -std-compile-opts was specified before this option. If
701 if (StandardCompileOpts &&
702 StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
703 AddStandardCompilePasses(Passes);
704 StandardCompileOpts = false;
707 if (StandardLinkOpts &&
708 StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
709 AddStandardLinkPasses(Passes);
710 StandardLinkOpts = false;
713 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
714 AddOptimizationPasses(Passes, *FPasses, 1, 0);
718 if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
719 AddOptimizationPasses(Passes, *FPasses, 2, 0);
723 if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) {
724 AddOptimizationPasses(Passes, *FPasses, 2, 1);
728 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) {
729 AddOptimizationPasses(Passes, *FPasses, 2, 2);
733 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
734 AddOptimizationPasses(Passes, *FPasses, 3, 0);
738 const PassInfo *PassInf = PassList[i];
740 if (PassInf->getNormalCtor())
741 P = PassInf->getNormalCtor()();
743 errs() << argv[0] << ": cannot create pass: "
744 << PassInf->getPassName() << "\n";
746 PassKind Kind = P->getPassKind();
752 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
755 Passes.add(new RegionPassPrinter(PassInf, Out->os()));
758 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
761 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
763 case PT_CallGraphSCC:
764 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
767 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
774 Passes.add(createPrintModulePass(&errs()));
777 // If -std-compile-opts was specified at the end of the pass list, add them.
778 if (StandardCompileOpts) {
779 AddStandardCompilePasses(Passes);
780 StandardCompileOpts = false;
783 if (StandardLinkOpts) {
784 AddStandardLinkPasses(Passes);
785 StandardLinkOpts = false;
789 AddOptimizationPasses(Passes, *FPasses, 1, 0);
792 AddOptimizationPasses(Passes, *FPasses, 2, 0);
795 AddOptimizationPasses(Passes, *FPasses, 2, 1);
798 AddOptimizationPasses(Passes, *FPasses, 2, 2);
801 AddOptimizationPasses(Passes, *FPasses, 3, 0);
803 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
804 FPasses->doInitialization();
805 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
807 FPasses->doFinalization();
810 // Check that the module is well formed on completion of optimization
811 if (!NoVerify && !VerifyEach)
812 Passes.add(createVerifierPass());
814 // Write bitcode or assembly to the output as the last step...
815 if (!NoOutput && !AnalyzeOnly) {
817 Passes.add(createPrintModulePass(&Out->os()));
819 Passes.add(createBitcodeWriterPass(Out->os()));
822 // Before executing passes, print the final values of the LLVM options.
823 cl::PrintOptionValues();
825 // Now that we have all of the passes ready, run them.
826 Passes.run(*M.get());
829 if (!NoOutput || PrintBreakpoints)