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 DisableLoopUnrolling("disable-loop-unrolling",
140 cl::desc("Disable loop unrolling in all relevant passes"),
144 DisableSimplifyLibCalls("disable-simplify-libcalls",
145 cl::desc("Disable simplify-libcalls"));
148 Quiet("q", cl::desc("Obsolete option"), cl::Hidden);
151 QuietA("quiet", cl::desc("Alias for -q"), cl::aliasopt(Quiet));
154 AnalyzeOnly("analyze", cl::desc("Only perform analysis, no optimization"));
157 PrintBreakpoints("print-breakpoints-for-testing",
158 cl::desc("Print select breakpoints location for testing"));
160 static cl::opt<std::string>
161 DefaultDataLayout("default-data-layout",
162 cl::desc("data layout string to use if not specified by module"),
163 cl::value_desc("layout-string"), cl::init(""));
165 // ---------- Define Printers for module and function passes ------------
168 struct CallGraphSCCPassPrinter : public CallGraphSCCPass {
170 const PassInfo *PassToPrint;
172 std::string PassName;
174 CallGraphSCCPassPrinter(const PassInfo *PI, raw_ostream &out) :
175 CallGraphSCCPass(ID), PassToPrint(PI), Out(out) {
176 std::string PassToPrintName = PassToPrint->getPassName();
177 PassName = "CallGraphSCCPass Printer: " + PassToPrintName;
180 virtual bool runOnSCC(CallGraphSCC &SCC) {
182 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
184 // Get and print pass...
185 for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I) {
186 Function *F = (*I)->getFunction();
188 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
194 virtual const char *getPassName() const { return PassName.c_str(); }
196 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
197 AU.addRequiredID(PassToPrint->getTypeInfo());
198 AU.setPreservesAll();
202 char CallGraphSCCPassPrinter::ID = 0;
204 struct ModulePassPrinter : public ModulePass {
206 const PassInfo *PassToPrint;
208 std::string PassName;
210 ModulePassPrinter(const PassInfo *PI, raw_ostream &out)
211 : ModulePass(ID), PassToPrint(PI), Out(out) {
212 std::string PassToPrintName = PassToPrint->getPassName();
213 PassName = "ModulePass Printer: " + PassToPrintName;
216 virtual bool runOnModule(Module &M) {
218 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
220 // Get and print pass...
221 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, &M);
225 virtual const char *getPassName() const { return PassName.c_str(); }
227 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
228 AU.addRequiredID(PassToPrint->getTypeInfo());
229 AU.setPreservesAll();
233 char ModulePassPrinter::ID = 0;
234 struct FunctionPassPrinter : public FunctionPass {
235 const PassInfo *PassToPrint;
238 std::string PassName;
240 FunctionPassPrinter(const PassInfo *PI, raw_ostream &out)
241 : FunctionPass(ID), PassToPrint(PI), Out(out) {
242 std::string PassToPrintName = PassToPrint->getPassName();
243 PassName = "FunctionPass Printer: " + PassToPrintName;
246 virtual bool runOnFunction(Function &F) {
248 Out << "Printing analysis '" << PassToPrint->getPassName()
249 << "' for function '" << F.getName() << "':\n";
251 // Get and print pass...
252 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
257 virtual const char *getPassName() const { return PassName.c_str(); }
259 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
260 AU.addRequiredID(PassToPrint->getTypeInfo());
261 AU.setPreservesAll();
265 char FunctionPassPrinter::ID = 0;
267 struct LoopPassPrinter : public LoopPass {
269 const PassInfo *PassToPrint;
271 std::string PassName;
273 LoopPassPrinter(const PassInfo *PI, raw_ostream &out) :
274 LoopPass(ID), PassToPrint(PI), Out(out) {
275 std::string PassToPrintName = PassToPrint->getPassName();
276 PassName = "LoopPass Printer: " + PassToPrintName;
280 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
282 Out << "Printing analysis '" << PassToPrint->getPassName() << "':\n";
284 // Get and print pass...
285 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
286 L->getHeader()->getParent()->getParent());
290 virtual const char *getPassName() const { return PassName.c_str(); }
292 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
293 AU.addRequiredID(PassToPrint->getTypeInfo());
294 AU.setPreservesAll();
298 char LoopPassPrinter::ID = 0;
300 struct RegionPassPrinter : public RegionPass {
302 const PassInfo *PassToPrint;
304 std::string PassName;
306 RegionPassPrinter(const PassInfo *PI, raw_ostream &out) : RegionPass(ID),
307 PassToPrint(PI), Out(out) {
308 std::string PassToPrintName = PassToPrint->getPassName();
309 PassName = "RegionPass Printer: " + PassToPrintName;
312 virtual bool runOnRegion(Region *R, RGPassManager &RGM) {
314 Out << "Printing analysis '" << PassToPrint->getPassName() << "' for "
315 << "region: '" << R->getNameStr() << "' in function '"
316 << R->getEntry()->getParent()->getName() << "':\n";
318 // Get and print pass...
319 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
320 R->getEntry()->getParent()->getParent());
324 virtual const char *getPassName() const { return PassName.c_str(); }
326 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
327 AU.addRequiredID(PassToPrint->getTypeInfo());
328 AU.setPreservesAll();
332 char RegionPassPrinter::ID = 0;
334 struct BasicBlockPassPrinter : public BasicBlockPass {
335 const PassInfo *PassToPrint;
338 std::string PassName;
340 BasicBlockPassPrinter(const PassInfo *PI, raw_ostream &out)
341 : BasicBlockPass(ID), PassToPrint(PI), Out(out) {
342 std::string PassToPrintName = PassToPrint->getPassName();
343 PassName = "BasicBlockPass Printer: " + PassToPrintName;
346 virtual bool runOnBasicBlock(BasicBlock &BB) {
348 Out << "Printing Analysis info for BasicBlock '" << BB.getName()
349 << "': Pass " << PassToPrint->getPassName() << ":\n";
351 // Get and print pass...
352 getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out,
353 BB.getParent()->getParent());
357 virtual const char *getPassName() const { return PassName.c_str(); }
359 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
360 AU.addRequiredID(PassToPrint->getTypeInfo());
361 AU.setPreservesAll();
365 char BasicBlockPassPrinter::ID = 0;
367 struct BreakpointPrinter : public ModulePass {
370 DITypeIdentifierMap TypeIdentifierMap;
372 BreakpointPrinter(raw_ostream &out)
373 : ModulePass(ID), Out(out) {
376 void getContextName(DIDescriptor Context, std::string &N) {
377 if (Context.isNameSpace()) {
378 DINameSpace NS(Context);
379 if (!NS.getName().empty()) {
380 getContextName(NS.getContext(), N);
381 N = N + NS.getName().str() + "::";
383 } else if (Context.isType()) {
385 if (!TY.getName().empty()) {
386 getContextName(TY.getContext().resolve(TypeIdentifierMap), N);
387 N = N + TY.getName().str() + "::";
392 virtual bool runOnModule(Module &M) {
393 TypeIdentifierMap.clear();
394 NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
396 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
398 StringSet<> Processed;
399 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
400 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
402 DISubprogram SP(NMD->getOperand(i));
403 assert((!SP || SP.isSubprogram()) &&
404 "A MDNode in llvm.dbg.sp should be null or a DISubprogram.");
407 getContextName(SP.getContext(), Name);
408 Name = Name + SP.getDisplayName().str();
409 if (!Name.empty() && Processed.insert(Name)) {
416 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
417 AU.setPreservesAll();
421 } // anonymous namespace
423 char BreakpointPrinter::ID = 0;
425 static inline void addPass(PassManagerBase &PM, Pass *P) {
426 // Add the pass to the pass manager...
429 // If we are verifying all of the intermediate steps, add the verifier...
430 if (VerifyEach) PM.add(createVerifierPass());
433 /// AddOptimizationPasses - This routine adds optimization passes
434 /// based on selected optimization level, OptLevel. This routine
435 /// duplicates llvm-gcc behaviour.
437 /// OptLevel - Optimization Level
438 static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM,
439 unsigned OptLevel, unsigned SizeLevel) {
440 FPM.add(createVerifierPass()); // Verify that input is correct
442 PassManagerBuilder Builder;
443 Builder.OptLevel = OptLevel;
444 Builder.SizeLevel = SizeLevel;
448 } else if (OptLevel > 1) {
449 unsigned Threshold = 225;
450 if (SizeLevel == 1) // -Os
452 else if (SizeLevel == 2) // -Oz
456 Builder.Inliner = createFunctionInliningPass(Threshold);
458 Builder.Inliner = createAlwaysInlinerPass();
460 Builder.DisableUnitAtATime = !UnitAtATime;
461 Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ?
462 DisableLoopUnrolling : OptLevel == 0;
464 Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2;
465 Builder.SLPVectorize = true;
467 Builder.populateFunctionPassManager(FPM);
468 Builder.populateModulePassManager(MPM);
471 static void AddStandardCompilePasses(PassManagerBase &PM) {
472 PM.add(createVerifierPass()); // Verify that input is correct
474 // If the -strip-debug command line option was specified, do it.
476 addPass(PM, createStripSymbolsPass(true));
478 if (DisableOptimizations) return;
480 // -std-compile-opts adds the same module passes as -O3.
481 PassManagerBuilder Builder;
483 Builder.Inliner = createFunctionInliningPass();
484 Builder.OptLevel = 3;
485 Builder.populateModulePassManager(PM);
488 static void AddStandardLinkPasses(PassManagerBase &PM) {
489 PM.add(createVerifierPass()); // Verify that input is correct
491 // If the -strip-debug command line option was specified, do it.
493 addPass(PM, createStripSymbolsPass(true));
495 if (DisableOptimizations) return;
497 PassManagerBuilder Builder;
498 Builder.populateLTOPassManager(PM, /*Internalize=*/ !DisableInternalize,
499 /*RunInliner=*/ !DisableInline);
502 //===----------------------------------------------------------------------===//
503 // CodeGen-related helper functions.
505 static TargetOptions GetTargetOptions() {
506 TargetOptions Options;
507 Options.LessPreciseFPMADOption = EnableFPMAD;
508 Options.NoFramePointerElim = DisableFPElim;
509 Options.AllowFPOpFusion = FuseFPOps;
510 Options.UnsafeFPMath = EnableUnsafeFPMath;
511 Options.NoInfsFPMath = EnableNoInfsFPMath;
512 Options.NoNaNsFPMath = EnableNoNaNsFPMath;
513 Options.HonorSignDependentRoundingFPMathOption =
514 EnableHonorSignDependentRoundingFPMath;
515 Options.UseSoftFloat = GenerateSoftFloatCalls;
516 if (FloatABIForCalls != FloatABI::Default)
517 Options.FloatABIType = FloatABIForCalls;
518 Options.NoZerosInBSS = DontPlaceZerosInBSS;
519 Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt;
520 Options.DisableTailCalls = DisableTailCalls;
521 Options.StackAlignmentOverride = OverrideStackAlignment;
522 Options.TrapFuncName = TrapFuncName;
523 Options.PositionIndependentExecutable = EnablePIE;
524 Options.EnableSegmentedStacks = SegmentedStacks;
525 Options.UseInitArray = UseInitArray;
529 CodeGenOpt::Level GetCodeGenOptLevel() {
531 return CodeGenOpt::Less;
533 return CodeGenOpt::Default;
535 return CodeGenOpt::Aggressive;
536 return CodeGenOpt::None;
539 // Returns the TargetMachine instance or zero if no triple is provided.
540 static TargetMachine* GetTargetMachine(Triple TheTriple) {
542 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple,
544 // Some modules don't specify a triple, and this is okay.
549 // Package up features to be passed to target/subtarget
550 std::string FeaturesStr;
552 SubtargetFeatures Features;
553 for (unsigned i = 0; i != MAttrs.size(); ++i)
554 Features.AddFeature(MAttrs[i]);
555 FeaturesStr = Features.getString();
558 return TheTarget->createTargetMachine(TheTriple.getTriple(),
559 MCPU, FeaturesStr, GetTargetOptions(),
561 GetCodeGenOptLevel());
564 //===----------------------------------------------------------------------===//
567 int main(int argc, char **argv) {
568 sys::PrintStackTraceOnErrorSignal();
569 llvm::PrettyStackTraceProgram X(argc, argv);
571 // Enable debug stream buffering.
572 EnableDebugBuffering = true;
574 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
575 LLVMContext &Context = getGlobalContext();
577 InitializeAllTargets();
578 InitializeAllTargetMCs();
581 PassRegistry &Registry = *PassRegistry::getPassRegistry();
582 initializeCore(Registry);
583 initializeDebugIRPass(Registry);
584 initializeScalarOpts(Registry);
585 initializeObjCARCOpts(Registry);
586 initializeVectorization(Registry);
587 initializeIPO(Registry);
588 initializeAnalysis(Registry);
589 initializeIPA(Registry);
590 initializeTransformUtils(Registry);
591 initializeInstCombine(Registry);
592 initializeInstrumentation(Registry);
593 initializeTarget(Registry);
595 cl::ParseCommandLineOptions(argc, argv,
596 "llvm .bc -> .bc modular optimizer and analysis printer\n");
598 if (AnalyzeOnly && NoOutput) {
599 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n";
605 // Load the input module...
607 M.reset(ParseIRFile(InputFilename, Err, Context));
610 Err.print(argv[0], errs());
614 // If we are supposed to override the target triple, do so now.
615 if (!TargetTriple.empty())
616 M->setTargetTriple(Triple::normalize(TargetTriple));
618 // Figure out what stream we are supposed to write to...
619 OwningPtr<tool_output_file> Out;
621 if (!OutputFilename.empty())
622 errs() << "WARNING: The -o (output filename) option is ignored when\n"
623 "the --disable-output option is used.\n";
625 // Default to standard output.
626 if (OutputFilename.empty())
627 OutputFilename = "-";
629 std::string ErrorInfo;
630 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
632 if (!ErrorInfo.empty()) {
633 errs() << ErrorInfo << '\n';
638 // If the output is set to be emitted to standard out, and standard out is a
639 // console, print out a warning message and refuse to do it. We don't
640 // impress anyone by spewing tons of binary goo to a terminal.
641 if (!Force && !NoOutput && !AnalyzeOnly && !OutputAssembly)
642 if (CheckBitcodeOutputToConsole(Out->os(), !Quiet))
645 // Create a PassManager to hold and optimize the collection of passes we are
650 // Add an appropriate TargetLibraryInfo pass for the module's triple.
651 TargetLibraryInfo *TLI = new TargetLibraryInfo(Triple(M->getTargetTriple()));
653 // The -disable-simplify-libcalls flag actually disables all builtin optzns.
654 if (DisableSimplifyLibCalls)
655 TLI->disableAllFunctions();
658 // Add an appropriate DataLayout instance for this module.
660 const std::string &ModuleDataLayout = M.get()->getDataLayout();
661 if (!ModuleDataLayout.empty())
662 TD = new DataLayout(ModuleDataLayout);
663 else if (!DefaultDataLayout.empty())
664 TD = new DataLayout(DefaultDataLayout);
669 Triple ModuleTriple(M->getTargetTriple());
670 TargetMachine *Machine = 0;
671 if (ModuleTriple.getArch())
672 Machine = GetTargetMachine(Triple(ModuleTriple));
673 OwningPtr<TargetMachine> TM(Machine);
675 // Add internal analysis passes from the target machine.
677 TM->addAnalysisPasses(Passes);
679 OwningPtr<FunctionPassManager> FPasses;
680 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
681 FPasses.reset(new FunctionPassManager(M.get()));
683 FPasses->add(new DataLayout(*TD));
685 TM->addAnalysisPasses(*FPasses);
689 if (PrintBreakpoints) {
690 // Default to standard output.
692 if (OutputFilename.empty())
693 OutputFilename = "-";
695 std::string ErrorInfo;
696 Out.reset(new tool_output_file(OutputFilename.c_str(), ErrorInfo,
698 if (!ErrorInfo.empty()) {
699 errs() << ErrorInfo << '\n';
703 Passes.add(new BreakpointPrinter(Out->os()));
707 // If the -strip-debug command line option was specified, add it. If
708 // -std-compile-opts was also specified, it will handle StripDebug.
709 if (StripDebug && !StandardCompileOpts)
710 addPass(Passes, createStripSymbolsPass(true));
712 // Create a new optimization pass for each one specified on the command line
713 for (unsigned i = 0; i < PassList.size(); ++i) {
714 // Check to see if -std-compile-opts was specified before this option. If
716 if (StandardCompileOpts &&
717 StandardCompileOpts.getPosition() < PassList.getPosition(i)) {
718 AddStandardCompilePasses(Passes);
719 StandardCompileOpts = false;
722 if (StandardLinkOpts &&
723 StandardLinkOpts.getPosition() < PassList.getPosition(i)) {
724 AddStandardLinkPasses(Passes);
725 StandardLinkOpts = false;
728 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) {
729 AddOptimizationPasses(Passes, *FPasses, 1, 0);
733 if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) {
734 AddOptimizationPasses(Passes, *FPasses, 2, 0);
738 if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) {
739 AddOptimizationPasses(Passes, *FPasses, 2, 1);
743 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) {
744 AddOptimizationPasses(Passes, *FPasses, 2, 2);
748 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) {
749 AddOptimizationPasses(Passes, *FPasses, 3, 0);
753 const PassInfo *PassInf = PassList[i];
755 if (PassInf->getNormalCtor())
756 P = PassInf->getNormalCtor()();
758 errs() << argv[0] << ": cannot create pass: "
759 << PassInf->getPassName() << "\n";
761 PassKind Kind = P->getPassKind();
767 Passes.add(new BasicBlockPassPrinter(PassInf, Out->os()));
770 Passes.add(new RegionPassPrinter(PassInf, Out->os()));
773 Passes.add(new LoopPassPrinter(PassInf, Out->os()));
776 Passes.add(new FunctionPassPrinter(PassInf, Out->os()));
778 case PT_CallGraphSCC:
779 Passes.add(new CallGraphSCCPassPrinter(PassInf, Out->os()));
782 Passes.add(new ModulePassPrinter(PassInf, Out->os()));
789 Passes.add(createPrintModulePass(&errs()));
792 // If -std-compile-opts was specified at the end of the pass list, add them.
793 if (StandardCompileOpts) {
794 AddStandardCompilePasses(Passes);
795 StandardCompileOpts = false;
798 if (StandardLinkOpts) {
799 AddStandardLinkPasses(Passes);
800 StandardLinkOpts = false;
804 AddOptimizationPasses(Passes, *FPasses, 1, 0);
807 AddOptimizationPasses(Passes, *FPasses, 2, 0);
810 AddOptimizationPasses(Passes, *FPasses, 2, 1);
813 AddOptimizationPasses(Passes, *FPasses, 2, 2);
816 AddOptimizationPasses(Passes, *FPasses, 3, 0);
818 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) {
819 FPasses->doInitialization();
820 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
822 FPasses->doFinalization();
825 // Check that the module is well formed on completion of optimization
826 if (!NoVerify && !VerifyEach)
827 Passes.add(createVerifierPass());
829 // Write bitcode or assembly to the output as the last step...
830 if (!NoOutput && !AnalyzeOnly) {
832 Passes.add(createPrintModulePass(&Out->os()));
834 Passes.add(createBitcodeWriterPass(Out->os()));
837 // Before executing passes, print the final values of the LLVM options.
838 cl::PrintOptionValues();
840 // Now that we have all of the passes ready, run them.
841 Passes.run(*M.get());
844 if (!NoOutput || PrintBreakpoints)