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));
393 getContextName(SP.getContext(), Name);
394 Name = Name + SP.getDisplayName().str();
395 if (!Name.empty() && Processed.insert(Name)) {
402 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
403 AU.setPreservesAll();
407 } // anonymous namespace
409 char BreakpointPrinter::ID = 0;
411 static inline void addPass(PassManagerBase &PM, Pass *P) {
412 // Add the pass to the pass manager...
415 // If we are verifying all of the intermediate steps, add the verifier...
416 if (VerifyEach) PM.add(createVerifierPass());
419 /// AddOptimizationPasses - This routine adds optimization passes
420 /// based on selected optimization level, OptLevel. This routine
421 /// duplicates llvm-gcc behaviour.
423 /// OptLevel - Optimization Level
424 static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
425 unsigned OptLevel, unsigned SizeLevel) {
426 FPM.add(createVerifierPass()); // Verify that input is correct
428 PassManagerBuilder Builder;
429 Builder.OptLevel = OptLevel;
430 Builder.SizeLevel = SizeLevel;
434 } else if (OptLevel > 1) {
435 unsigned Threshold = 225;
436 if (SizeLevel == 1) // -Os
438 else if (SizeLevel == 2) // -Oz
442 Builder.Inliner = createFunctionInliningPass(Threshold);
444 Builder.Inliner = createAlwaysInlinerPass();
446 Builder.DisableUnitAtATime = !UnitAtATime;
447 Builder.DisableUnrollLoops = OptLevel == 0;
448 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
450 Builder.populateFunctionPassManager(FPM);
451 Builder.populateModulePassManager(MPM);
454 static void AddStandardCompilePasses(PassManagerBase &PM) {
455 PM.add(createVerifierPass()); // Verify that input is correct
457 // If the -strip-debug command line option was specified, do it.
459 addPass(PM, createStripSymbolsPass(true));
461 if (DisableOptimizations) return;
463 // -std-compile-opts adds the same module passes as -O3.
464 PassManagerBuilder Builder;
466 Builder.Inliner = createFunctionInliningPass();
467 Builder.OptLevel = 3;
468 Builder.DisableSimplifyLibCalls = DisableSimplifyLibCalls;
469 Builder.populateModulePassManager(PM);
472 static void AddStandardLinkPasses(PassManagerBase &PM) {
473 PM.add(createVerifierPass()); // Verify that input is correct
475 // If the -strip-debug command line option was specified, do it.
477 addPass(PM, createStripSymbolsPass(true));
479 if (DisableOptimizations) return;
481 PassManagerBuilder Builder;
482 Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
483 /*RunInliner=*/ !DisableInline);
486 //===----------------------------------------------------------------------===//
487 // CodeGen-related helper functions.
489 static TargetOptions GetTargetOptions() {
490 TargetOptions Options;
491 Options.LessPreciseFPMADOption = EnableFPMAD;
492 Options.NoFramePointerElim = DisableFPElim;
493 Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf;
494 Options.AllowFPOpFusion = FuseFPOps;
495 Options.UnsafeFPMath = EnableUnsafeFPMath;
496 Options.NoInfsFPMath = EnableNoInfsFPMath;
497 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
498 Options.HonorSignDependentRoundingFPMathOption =
499 EnableHonorSignDependentRoundingFPMath;
500 Options.UseSoftFloat = GenerateSoftFloatCalls;
501 if (FloatABIForCalls != FloatABI::Default)
502 Options.FloatABIType = FloatABIForCalls;
503 Options.NoZerosInBSS = DontPlaceZerosInBSS;
504 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
505 Options.DisableTailCalls = DisableTailCalls;
506 Options.StackAlignmentOverride = OverrideStackAlignment;
507 Options.RealignStack = EnableRealignStack;
508 Options.TrapFuncName = TrapFuncName;
509 Options.PositionIndependentExecutable = EnablePIE;
510 Options.EnableSegmentedStacks = SegmentedStacks;
511 Options.UseInitArray = UseInitArray;
512 Options.SSPBufferSize = SSPBufferSize;
516 CodeGenOpt::Level GetCodeGenOptLevel() {
518 return CodeGenOpt::Less;
520 return CodeGenOpt::Default;
522 return CodeGenOpt::Aggressive;
523 return CodeGenOpt::None;
526 // Returns the TargetMachine instance or zero if no triple is provided.
527 static TargetMachine* GetTargetMachine(Triple TheTriple) {
529 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
531 // Some modules don't specify a triple, and this is okay.
536 // Package up features to be passed to target/subtarget
537 std::string FeaturesStr;
539 SubtargetFeatures Features;
540 for (unsigned i = 0; i != MAttrs.size(); ++i)
541 Features.AddFeature(MAttrs[i]);
542 FeaturesStr = Features.getString();
545 return TheTarget->createTargetMachine(TheTriple.getTriple(),
546 MCPU, FeaturesStr, GetTargetOptions(),
548 GetCodeGenOptLevel());
551 //===----------------------------------------------------------------------===//
554 int main(int argc, char **argv) {
555 sys::PrintStackTraceOnErrorSignal();
556 llvm::PrettyStackTraceProgram X(argc, argv);
558 // Enable debug stream buffering.
559 EnableDebugBuffering = true;
561 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
562 LLVMContext &Context = getGlobalContext();
564 InitializeAllTargets();
565 InitializeAllTargetMCs();
568 PassRegistry &Registry = *PassRegistry::getPassRegistry();
569 initializeCore(Registry);
570 initializeScalarOpts(Registry);
571 initializeObjCARCOpts(Registry);
572 initializeVectorization(Registry);
573 initializeIPO(Registry);
574 initializeAnalysis(Registry);
575 initializeIPA(Registry);
576 initializeTransformUtils(Registry);
577 initializeInstCombine(Registry);
578 initializeInstrumentation(Registry);
579 initializeTarget(Registry);
581 cl::ParseCommandLineOptions(argc, argv,
582 "llvm .bc -> .bc modular optimizer and analysis printer\n");
584 if (AnalyzeOnly && NoOutput) {
585 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
591 // Load the input module...
593 M.reset(ParseIRFile(InputFilename, Err, Context));
596 Err.print(argv[0], errs());
600 // If we are supposed to override the target triple, do so now.
601 if (!TargetTriple.empty())
602 M->setTargetTriple(Triple::normalize(TargetTriple));
604 // Figure out what stream we are supposed to write to...
605 OwningPtr<tool_output_file> Out;
607 if (!OutputFilename.empty())
608 errs() << "WARNING: The -o (output filename) option is ignored when\n"
609 "the --disable-output option is used.\n";
611 // Default to standard output.
612 if (OutputFilename.empty())
613 OutputFilename = "-";
615 std::string ErrorInfo;
616 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
617 raw_fd_ostream::F_Binary));
618 if (!ErrorInfo.empty()) {
619 errs() << ErrorInfo << '\n';
624 // If the output is set to be emitted to standard out, and standard out is a
625 // console, print out a warning message and refuse to do it. We don't
626 // impress anyone by spewing tons of binary goo to a terminal.
627 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
628 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
631 // Create a PassManager to hold and optimize the collection of passes we are
636 // Add an appropriate TargetLibraryInfo pass for the module's triple.
637 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
639 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
640 if (DisableSimplifyLibCalls)
641 TLI->disableAllFunctions();
644 // Add an appropriate DataLayout instance for this module.
646 const std::string &ModuleDataLayout = M.get()->getDataLayout();
647 if (!ModuleDataLayout.empty())
648 TD = new DataLayout(ModuleDataLayout);
649 else if (!DefaultDataLayout.empty())
650 TD = new DataLayout(DefaultDataLayout);
655 Triple ModuleTriple(M->getTargetTriple());
656 TargetMachine *Machine = 0;
657 if (ModuleTriple.getArch())
658 Machine = GetTargetMachine(Triple(ModuleTriple));
659 OwningPtr<TargetMachine> TM(Machine);
661 // Add internal analysis passes from the target machine.
663 TM->addAnalysisPasses(Passes);
665 OwningPtr<FunctionPassManager> FPasses;
666 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
667 FPasses.reset(new FunctionPassManager(M.get()));
669 FPasses->add(new DataLayout(*TD));
672 if (PrintBreakpoints) {
673 // Default to standard output.
675 if (OutputFilename.empty())
676 OutputFilename = "-";
678 std::string ErrorInfo;
679 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
680 raw_fd_ostream::F_Binary));
681 if (!ErrorInfo.empty()) {
682 errs() << ErrorInfo << '\n';
686 Passes.add(new BreakpointPrinter(Out->os()));
690 // If the -strip-debug command line option was specified, add it. If
691 // -std-compile-opts was also specified, it will handle StripDebug.
692 if (StripDebug && !StandardCompileOpts)
693 addPass(Passes, createStripSymbolsPass(true));
695 // Create a new optimization pass for each one specified on the command line
696 for (unsigned i = 0; i < PassList.size(); ++i) {
697 // Check to see if -std-compile-opts was specified before this option. If
699 if (StandardCompileOpts &&
700 StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
701 AddStandardCompilePasses(Passes);
702 StandardCompileOpts = false;
705 if (StandardLinkOpts &&
706 StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
707 AddStandardLinkPasses(Passes);
708 StandardLinkOpts = false;
711 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
712 AddOptimizationPasses(Passes, *FPasses, 1, 0);
716 if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
717 AddOptimizationPasses(Passes, *FPasses, 2, 0);
721 if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) {
722 AddOptimizationPasses(Passes, *FPasses, 2, 1);
726 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) {
727 AddOptimizationPasses(Passes, *FPasses, 2, 2);
731 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
732 AddOptimizationPasses(Passes, *FPasses, 3, 0);
736 const PassInfo *PassInf = PassList[i];
738 if (PassInf->getNormalCtor())
739 P = PassInf->getNormalCtor()();
741 errs() << argv[0] << ": cannot create pass: "
742 << PassInf->getPassName() << "\n";
744 PassKind Kind = P->getPassKind();
750 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
753 Passes.add(new RegionPassPrinter(PassInf, Out->os()));
756 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
759 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
761 case PT_CallGraphSCC:
762 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
765 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
772 Passes.add(createPrintModulePass(&errs()));
775 // If -std-compile-opts was specified at the end of the pass list, add them.
776 if (StandardCompileOpts) {
777 AddStandardCompilePasses(Passes);
778 StandardCompileOpts = false;
781 if (StandardLinkOpts) {
782 AddStandardLinkPasses(Passes);
783 StandardLinkOpts = false;
787 AddOptimizationPasses(Passes, *FPasses, 1, 0);
790 AddOptimizationPasses(Passes, *FPasses, 2, 0);
793 AddOptimizationPasses(Passes, *FPasses, 2, 1);
796 AddOptimizationPasses(Passes, *FPasses, 2, 2);
799 AddOptimizationPasses(Passes, *FPasses, 3, 0);
801 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
802 FPasses->doInitialization();
803 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
805 FPasses->doFinalization();
808 // Check that the module is well formed on completion of optimization
809 if (!NoVerify && !VerifyEach)
810 Passes.add(createVerifierPass());
812 // Write bitcode or assembly to the output as the last step...
813 if (!NoOutput && !AnalyzeOnly) {
815 Passes.add(createPrintModulePass(&Out->os()));
817 Passes.add(createBitcodeWriterPass(Out->os()));
820 // Before executing passes, print the final values of the LLVM options.
821 cl::PrintOptionValues();
823 // Now that we have all of the passes ready, run them.
824 Passes.run(*M.get());
827 if (!NoOutput || PrintBreakpoints)