| OLD | NEW |
| 1 //===- opt.cpp - The LLVM Modular Optimizer -------------------------------===// | 1 //===- opt.cpp - The LLVM Modular Optimizer -------------------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // Optimizations may be specified an arbitrary number of times on the command | 10 // Optimizations may be specified an arbitrary number of times on the command |
| 11 // line, They are run in the order specified. | 11 // line, They are run in the order specified. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "BreakpointPrinter.h" | 15 #include "BreakpointPrinter.h" |
| 16 #include "NewPMDriver.h" | 16 #include "NewPMDriver.h" |
| 17 #include "PassPrinters.h" | 17 #include "PassPrinters.h" |
| 18 #include "llvm/ADT/Triple.h" | 18 #include "llvm/ADT/Triple.h" |
| 19 #include "llvm/Analysis/CallGraph.h" | 19 #include "llvm/Analysis/CallGraph.h" |
| 20 #include "llvm/Analysis/CallGraphSCCPass.h" | 20 #include "llvm/Analysis/CallGraphSCCPass.h" |
| 21 #include "llvm/Analysis/LoopPass.h" | 21 #include "llvm/Analysis/LoopPass.h" |
| 22 #include "llvm/Analysis/RegionPass.h" | 22 #include "llvm/Analysis/RegionPass.h" |
| 23 #include "llvm/Bitcode/BitcodeWriterPass.h" | 23 #include "llvm/Bitcode/BitcodeWriterPass.h" |
| 24 #include "llvm/Bitcode/NaCl/NaClBitcodeWriterPass.h" // @LOCALMOD |
| 24 #include "llvm/CodeGen/CommandFlags.h" | 25 #include "llvm/CodeGen/CommandFlags.h" |
| 25 #include "llvm/IR/DataLayout.h" | 26 #include "llvm/IR/DataLayout.h" |
| 26 #include "llvm/IR/IRPrintingPasses.h" | 27 #include "llvm/IR/IRPrintingPasses.h" |
| 27 #include "llvm/IR/LLVMContext.h" | 28 #include "llvm/IR/LLVMContext.h" |
| 28 #include "llvm/IR/LegacyPassNameParser.h" | 29 #include "llvm/IR/LegacyPassNameParser.h" |
| 29 #include "llvm/IR/Module.h" | 30 #include "llvm/IR/Module.h" |
| 30 #include "llvm/IR/Verifier.h" | 31 #include "llvm/IR/Verifier.h" |
| 31 #include "llvm/IRReader/IRReader.h" | 32 #include "llvm/IRReader/IRReader.h" |
| 32 #include "llvm/InitializePasses.h" | 33 #include "llvm/InitializePasses.h" |
| 33 #include "llvm/LinkAllIR.h" | 34 #include "llvm/LinkAllIR.h" |
| 34 #include "llvm/LinkAllPasses.h" | 35 #include "llvm/LinkAllPasses.h" |
| 35 #include "llvm/MC/SubtargetFeature.h" | 36 #include "llvm/MC/SubtargetFeature.h" |
| 36 #include "llvm/PassManager.h" | 37 #include "llvm/PassManager.h" |
| 37 #include "llvm/Support/Debug.h" | 38 #include "llvm/Support/Debug.h" |
| 38 #include "llvm/Support/FileSystem.h" | 39 #include "llvm/Support/FileSystem.h" |
| 39 #include "llvm/Support/ManagedStatic.h" | 40 #include "llvm/Support/ManagedStatic.h" |
| 40 #include "llvm/Support/PluginLoader.h" | 41 #include "llvm/Support/PluginLoader.h" |
| 41 #include "llvm/Support/PrettyStackTrace.h" | 42 #include "llvm/Support/PrettyStackTrace.h" |
| 42 #include "llvm/Support/Signals.h" | 43 #include "llvm/Support/Signals.h" |
| 43 #include "llvm/Support/SourceMgr.h" | 44 #include "llvm/Support/SourceMgr.h" |
| 44 #include "llvm/Support/SystemUtils.h" | 45 #include "llvm/Support/SystemUtils.h" |
| 45 #include "llvm/Support/TargetRegistry.h" | 46 #include "llvm/Support/TargetRegistry.h" |
| 46 #include "llvm/Support/TargetSelect.h" | 47 #include "llvm/Support/TargetSelect.h" |
| 47 #include "llvm/Support/ToolOutputFile.h" | 48 #include "llvm/Support/ToolOutputFile.h" |
| 48 #include "llvm/Target/TargetLibraryInfo.h" | 49 #include "llvm/Target/TargetLibraryInfo.h" |
| 49 #include "llvm/Target/TargetMachine.h" | 50 #include "llvm/Target/TargetMachine.h" |
| 50 #include "llvm/Transforms/IPO/PassManagerBuilder.h" | 51 #include "llvm/Transforms/IPO/PassManagerBuilder.h" |
| 52 #include "llvm/Transforms/MinSFI.h" // @LOCALMOD |
| 53 #include "llvm/Transforms/NaCl.h" // @LOCALMOD |
| 51 #include <algorithm> | 54 #include <algorithm> |
| 52 #include <memory> | 55 #include <memory> |
| 53 using namespace llvm; | 56 using namespace llvm; |
| 54 using namespace opt_tool; | 57 using namespace opt_tool; |
| 55 | 58 |
| 56 // The OptimizationList is automatically populated with registered Passes by the | 59 // The OptimizationList is automatically populated with registered Passes by the |
| 57 // PassNameParser. | 60 // PassNameParser. |
| 58 // | 61 // |
| 59 static cl::list<const PassInfo*, bool, PassNameParser> | 62 static cl::list<const PassInfo*, bool, PassNameParser> |
| 60 PassList(cl::desc("Optimizations available:")); | 63 PassList(cl::desc("Optimizations available:")); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 cl::desc("Like -O2 with extra optimizations for size. Similar to clan
g -Os")); | 128 cl::desc("Like -O2 with extra optimizations for size. Similar to clan
g -Os")); |
| 126 | 129 |
| 127 static cl::opt<bool> | 130 static cl::opt<bool> |
| 128 OptLevelOz("Oz", | 131 OptLevelOz("Oz", |
| 129 cl::desc("Like -Os but reduces code size further. Similar to clang -O
z")); | 132 cl::desc("Like -Os but reduces code size further. Similar to clang -O
z")); |
| 130 | 133 |
| 131 static cl::opt<bool> | 134 static cl::opt<bool> |
| 132 OptLevelO3("O3", | 135 OptLevelO3("O3", |
| 133 cl::desc("Optimization level 3. Similar to clang -O3")); | 136 cl::desc("Optimization level 3. Similar to clang -O3")); |
| 134 | 137 |
| 138 // @LOCALMOD-BEGIN |
| 139 static cl::opt<bool> |
| 140 PNaClABISimplifyPreOpt( |
| 141 "pnacl-abi-simplify-preopt", |
| 142 cl::desc("PNaCl ABI simplifications for before optimizations")); |
| 143 |
| 144 static cl::opt<bool> |
| 145 PNaClABISimplifyPostOpt( |
| 146 "pnacl-abi-simplify-postopt", |
| 147 cl::desc("PNaCl ABI simplifications for after optimizations")); |
| 148 |
| 149 static cl::opt<bool> |
| 150 MinSFI("minsfi", |
| 151 cl::desc("MinSFI sandboxing")); |
| 152 // @LOCALMOD-END |
| 153 |
| 135 static cl::opt<std::string> | 154 static cl::opt<std::string> |
| 136 TargetTriple("mtriple", cl::desc("Override target triple for module")); | 155 TargetTriple("mtriple", cl::desc("Override target triple for module")); |
| 137 | 156 |
| 138 static cl::opt<bool> | 157 static cl::opt<bool> |
| 139 UnitAtATime("funit-at-a-time", | 158 UnitAtATime("funit-at-a-time", |
| 140 cl::desc("Enable IPO. This corresponds to gcc's -funit-at-a-time"), | 159 cl::desc("Enable IPO. This corresponds to gcc's -funit-at-a-time"), |
| 141 cl::init(true)); | 160 cl::init(true)); |
| 142 | 161 |
| 143 static cl::opt<bool> | 162 static cl::opt<bool> |
| 144 DisableLoopUnrolling("disable-loop-unrolling", | 163 DisableLoopUnrolling("disable-loop-unrolling", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 170 | 189 |
| 171 static cl::opt<bool> | 190 static cl::opt<bool> |
| 172 PrintBreakpoints("print-breakpoints-for-testing", | 191 PrintBreakpoints("print-breakpoints-for-testing", |
| 173 cl::desc("Print select breakpoints location for testing")); | 192 cl::desc("Print select breakpoints location for testing")); |
| 174 | 193 |
| 175 static cl::opt<std::string> | 194 static cl::opt<std::string> |
| 176 DefaultDataLayout("default-data-layout", | 195 DefaultDataLayout("default-data-layout", |
| 177 cl::desc("data layout string to use if not specified by module"), | 196 cl::desc("data layout string to use if not specified by module"), |
| 178 cl::value_desc("layout-string"), cl::init("")); | 197 cl::value_desc("layout-string"), cl::init("")); |
| 179 | 198 |
| 199 // @LOCALMOD-BEGIN |
| 200 static cl::opt<NaClFileFormat> |
| 201 OutputFileFormat( |
| 202 "bitcode-format", |
| 203 cl::desc("Define format of generated bitcode file:"), |
| 204 cl::values( |
| 205 clEnumValN(LLVMFormat, "llvm", "LLVM bitcode file (default)"), |
| 206 clEnumValN(PNaClFormat, "pnacl", "PNaCl bitcode file"), |
| 207 clEnumValEnd), |
| 208 cl::init(LLVMFormat)); |
| 209 extern bool OutputFileFormatIsPNaCl; |
| 210 // @LOCALMOD-END |
| 180 | 211 |
| 181 | 212 |
| 182 static inline void addPass(PassManagerBase &PM, Pass *P) { | 213 static inline void addPass(PassManagerBase &PM, Pass *P) { |
| 183 // Add the pass to the pass manager... | 214 // Add the pass to the pass manager... |
| 184 PM.add(P); | 215 PM.add(P); |
| 185 | 216 |
| 186 // If we are verifying all of the intermediate steps, add the verifier... | 217 // If we are verifying all of the intermediate steps, add the verifier... |
| 187 if (VerifyEach) { | 218 if (VerifyEach) { |
| 188 PM.add(createVerifierPass()); | 219 PM.add(createVerifierPass()); |
| 189 PM.add(createDebugInfoVerifierPass()); | 220 PM.add(createDebugInfoVerifierPass()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 if (OptLevelO2) | 282 if (OptLevelO2) |
| 252 return CodeGenOpt::Default; | 283 return CodeGenOpt::Default; |
| 253 if (OptLevelO3) | 284 if (OptLevelO3) |
| 254 return CodeGenOpt::Aggressive; | 285 return CodeGenOpt::Aggressive; |
| 255 return CodeGenOpt::None; | 286 return CodeGenOpt::None; |
| 256 } | 287 } |
| 257 | 288 |
| 258 // Returns the TargetMachine instance or zero if no triple is provided. | 289 // Returns the TargetMachine instance or zero if no triple is provided. |
| 259 static TargetMachine* GetTargetMachine(Triple TheTriple) { | 290 static TargetMachine* GetTargetMachine(Triple TheTriple) { |
| 260 std::string Error; | 291 std::string Error; |
| 292 // @LOCALMOD-BEGIN: Some optimization passes like SimplifyCFG do nice |
| 293 // things for code size, but only do it if the TTI says it is okay. |
| 294 // For now, use the ARM TTI for LE32 until we have an LE32 TTI. |
| 295 // https://code.google.com/p/nativeclient/issues/detail?id=2554 |
| 296 if (TheTriple.getArch() == Triple::le32) { |
| 297 TheTriple.setArchName("armv7a"); |
| 298 } |
| 299 // @LOCALMOD-END |
| 261 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, | 300 const Target *TheTarget = TargetRegistry::lookupTarget(MArch, TheTriple, |
| 262 Error); | 301 Error); |
| 263 // Some modules don't specify a triple, and this is okay. | 302 // Some modules don't specify a triple, and this is okay. |
| 264 if (!TheTarget) { | 303 if (!TheTarget) { |
| 265 return nullptr; | 304 return nullptr; |
| 266 } | 305 } |
| 267 | 306 |
| 268 // Package up features to be passed to target/subtarget | 307 // Package up features to be passed to target/subtarget |
| 269 std::string FeaturesStr; | 308 std::string FeaturesStr; |
| 270 if (MAttrs.size()) { | 309 if (MAttrs.size()) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 // For codegen passes, only passes that do IR to IR transformation are | 359 // For codegen passes, only passes that do IR to IR transformation are |
| 321 // supported. | 360 // supported. |
| 322 initializeCodeGenPreparePass(Registry); | 361 initializeCodeGenPreparePass(Registry); |
| 323 initializeAtomicExpandPass(Registry); | 362 initializeAtomicExpandPass(Registry); |
| 324 initializeRewriteSymbolsPass(Registry); | 363 initializeRewriteSymbolsPass(Registry); |
| 325 | 364 |
| 326 #ifdef LINK_POLLY_INTO_TOOLS | 365 #ifdef LINK_POLLY_INTO_TOOLS |
| 327 polly::initializePollyPasses(Registry); | 366 polly::initializePollyPasses(Registry); |
| 328 #endif | 367 #endif |
| 329 | 368 |
| 369 // @LOCALMOD-BEGIN |
| 370 initializeAddPNaClExternalDeclsPass(Registry); |
| 371 initializeAllocateDataSegmentPass(Registry); |
| 372 initializeBackendCanonicalizePass(Registry); |
| 373 initializeCanonicalizeMemIntrinsicsPass(Registry); |
| 374 initializeConstantInsertExtractElementIndexPass(Registry); |
| 375 initializeExpandAllocasPass(Registry); |
| 376 initializeExpandArithWithOverflowPass(Registry); |
| 377 initializeExpandByValPass(Registry); |
| 378 initializeExpandConstantExprPass(Registry); |
| 379 initializeExpandCtorsPass(Registry); |
| 380 initializeExpandGetElementPtrPass(Registry); |
| 381 initializeExpandIndirectBrPass(Registry); |
| 382 initializeExpandLargeIntegersPass(Registry); |
| 383 initializeExpandShuffleVectorPass(Registry); |
| 384 initializeExpandSmallArgumentsPass(Registry); |
| 385 initializeExpandStructRegsPass(Registry); |
| 386 initializeExpandTlsConstantExprPass(Registry); |
| 387 initializeExpandTlsPass(Registry); |
| 388 initializeExpandVarArgsPass(Registry); |
| 389 initializeFixVectorLoadStoreAlignmentPass(Registry); |
| 390 initializeFlattenGlobalsPass(Registry); |
| 391 initializeGlobalCleanupPass(Registry); |
| 392 initializeGlobalizeConstantVectorsPass(Registry); |
| 393 initializeInsertDivideCheckPass(Registry); |
| 394 initializePNaClABIVerifyFunctionsPass(Registry); |
| 395 initializePNaClABIVerifyModulePass(Registry); |
| 396 initializePNaClSjLjEHPass(Registry); |
| 397 initializePromoteI1OpsPass(Registry); |
| 398 initializePromoteIntegersPass(Registry); |
| 399 initializeRemoveAsmMemoryPass(Registry); |
| 400 initializeRenameEntryPointPass(Registry); |
| 401 initializeReplacePtrsWithIntsPass(Registry); |
| 402 initializeResolveAliasesPass(Registry); |
| 403 initializeResolvePNaClIntrinsicsPass(Registry); |
| 404 initializeRewriteAtomicsPass(Registry); |
| 405 initializeRewriteLLVMIntrinsicsPass(Registry); |
| 406 initializeRewritePNaClLibraryCallsPass(Registry); |
| 407 initializeSandboxIndirectCallsPass(Registry); |
| 408 initializeSandboxMemoryAccessesPass(Registry); |
| 409 initializeSimplifyAllocasPass(Registry); |
| 410 initializeStripAttributesPass(Registry); |
| 411 initializeStripMetadataPass(Registry); |
| 412 initializeStripModuleFlagsPass(Registry); |
| 413 initializeStripTlsPass(Registry); |
| 414 initializeSubstituteUndefsPass(Registry); |
| 415 // @LOCALMOD-END |
| 416 |
| 330 cl::ParseCommandLineOptions(argc, argv, | 417 cl::ParseCommandLineOptions(argc, argv, |
| 331 "llvm .bc -> .bc modular optimizer and analysis printer\n"); | 418 "llvm .bc -> .bc modular optimizer and analysis printer\n"); |
| 332 | 419 |
| 333 if (AnalyzeOnly && NoOutput) { | 420 if (AnalyzeOnly && NoOutput) { |
| 334 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n"; | 421 errs() << argv[0] << ": analyze mode conflicts with no-output mode.\n"; |
| 335 return 1; | 422 return 1; |
| 336 } | 423 } |
| 337 | 424 |
| 338 SMDiagnostic Err; | 425 SMDiagnostic Err; |
| 339 | 426 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 Passes.add(createBreakpointPrinter(Out->os())); | 541 Passes.add(createBreakpointPrinter(Out->os())); |
| 455 NoOutput = true; | 542 NoOutput = true; |
| 456 } | 543 } |
| 457 | 544 |
| 458 // If the -strip-debug command line option was specified, add it. | 545 // If the -strip-debug command line option was specified, add it. |
| 459 if (StripDebug) | 546 if (StripDebug) |
| 460 addPass(Passes, createStripSymbolsPass(true)); | 547 addPass(Passes, createStripSymbolsPass(true)); |
| 461 | 548 |
| 462 // Create a new optimization pass for each one specified on the command line | 549 // Create a new optimization pass for each one specified on the command line |
| 463 for (unsigned i = 0; i < PassList.size(); ++i) { | 550 for (unsigned i = 0; i < PassList.size(); ++i) { |
| 551 // @LOCALMOD-BEGIN |
| 552 if (PNaClABISimplifyPreOpt && |
| 553 PNaClABISimplifyPreOpt.getPosition() < PassList.getPosition(i)) { |
| 554 PNaClABISimplifyAddPreOptPasses(Passes); |
| 555 PNaClABISimplifyPreOpt = false; |
| 556 } |
| 557 // @LOCALMOD-END |
| 558 |
| 464 if (StandardLinkOpts && | 559 if (StandardLinkOpts && |
| 465 StandardLinkOpts.getPosition() < PassList.getPosition(i)) { | 560 StandardLinkOpts.getPosition() < PassList.getPosition(i)) { |
| 466 AddStandardLinkPasses(Passes); | 561 AddStandardLinkPasses(Passes); |
| 467 StandardLinkOpts = false; | 562 StandardLinkOpts = false; |
| 468 } | 563 } |
| 469 | 564 |
| 470 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { | 565 if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { |
| 471 AddOptimizationPasses(Passes, *FPasses, 1, 0); | 566 AddOptimizationPasses(Passes, *FPasses, 1, 0); |
| 472 OptLevelO1 = false; | 567 OptLevelO1 = false; |
| 473 } | 568 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 485 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) { | 580 if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) { |
| 486 AddOptimizationPasses(Passes, *FPasses, 2, 2); | 581 AddOptimizationPasses(Passes, *FPasses, 2, 2); |
| 487 OptLevelOz = false; | 582 OptLevelOz = false; |
| 488 } | 583 } |
| 489 | 584 |
| 490 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { | 585 if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { |
| 491 AddOptimizationPasses(Passes, *FPasses, 3, 0); | 586 AddOptimizationPasses(Passes, *FPasses, 3, 0); |
| 492 OptLevelO3 = false; | 587 OptLevelO3 = false; |
| 493 } | 588 } |
| 494 | 589 |
| 590 // @LOCALMOD-BEGIN |
| 591 if (PNaClABISimplifyPostOpt && |
| 592 PNaClABISimplifyPostOpt.getPosition() < PassList.getPosition(i)) { |
| 593 PNaClABISimplifyAddPostOptPasses(Passes); |
| 594 PNaClABISimplifyPostOpt = false; |
| 595 } |
| 596 |
| 597 if (MinSFI && MinSFI.getPosition() < PassList.getPosition(i)) { |
| 598 MinSFIPasses(Passes); |
| 599 MinSFI = false; |
| 600 } |
| 601 // @LOCALMOD-END |
| 602 |
| 495 const PassInfo *PassInf = PassList[i]; | 603 const PassInfo *PassInf = PassList[i]; |
| 496 Pass *P = nullptr; | 604 Pass *P = nullptr; |
| 497 if (PassInf->getTargetMachineCtor()) | 605 if (PassInf->getTargetMachineCtor()) |
| 498 P = PassInf->getTargetMachineCtor()(TM.get()); | 606 P = PassInf->getTargetMachineCtor()(TM.get()); |
| 499 else if (PassInf->getNormalCtor()) | 607 else if (PassInf->getNormalCtor()) |
| 500 P = PassInf->getNormalCtor()(); | 608 P = PassInf->getNormalCtor()(); |
| 501 else | 609 else |
| 502 errs() << argv[0] << ": cannot create pass: " | 610 errs() << argv[0] << ": cannot create pass: " |
| 503 << PassInf->getPassName() << "\n"; | 611 << PassInf->getPassName() << "\n"; |
| 504 if (P) { | 612 if (P) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 526 Passes.add(createModulePassPrinter(PassInf, Out->os(), Quiet)); | 634 Passes.add(createModulePassPrinter(PassInf, Out->os(), Quiet)); |
| 527 break; | 635 break; |
| 528 } | 636 } |
| 529 } | 637 } |
| 530 } | 638 } |
| 531 | 639 |
| 532 if (PrintEachXForm) | 640 if (PrintEachXForm) |
| 533 Passes.add(createPrintModulePass(errs())); | 641 Passes.add(createPrintModulePass(errs())); |
| 534 } | 642 } |
| 535 | 643 |
| 644 // @LOCALMOD-BEGIN |
| 645 if (PNaClABISimplifyPreOpt) |
| 646 PNaClABISimplifyAddPreOptPasses(Passes); |
| 647 // @LOCALMOD-END |
| 648 |
| 536 if (StandardLinkOpts) { | 649 if (StandardLinkOpts) { |
| 537 AddStandardLinkPasses(Passes); | 650 AddStandardLinkPasses(Passes); |
| 538 StandardLinkOpts = false; | 651 StandardLinkOpts = false; |
| 539 } | 652 } |
| 540 | 653 |
| 541 if (OptLevelO1) | 654 if (OptLevelO1) |
| 542 AddOptimizationPasses(Passes, *FPasses, 1, 0); | 655 AddOptimizationPasses(Passes, *FPasses, 1, 0); |
| 543 | 656 |
| 544 if (OptLevelO2) | 657 if (OptLevelO2) |
| 545 AddOptimizationPasses(Passes, *FPasses, 2, 0); | 658 AddOptimizationPasses(Passes, *FPasses, 2, 0); |
| 546 | 659 |
| 547 if (OptLevelOs) | 660 if (OptLevelOs) |
| 548 AddOptimizationPasses(Passes, *FPasses, 2, 1); | 661 AddOptimizationPasses(Passes, *FPasses, 2, 1); |
| 549 | 662 |
| 550 if (OptLevelOz) | 663 if (OptLevelOz) |
| 551 AddOptimizationPasses(Passes, *FPasses, 2, 2); | 664 AddOptimizationPasses(Passes, *FPasses, 2, 2); |
| 552 | 665 |
| 553 if (OptLevelO3) | 666 if (OptLevelO3) |
| 554 AddOptimizationPasses(Passes, *FPasses, 3, 0); | 667 AddOptimizationPasses(Passes, *FPasses, 3, 0); |
| 555 | 668 |
| 556 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { | 669 if (OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || OptLevelO3) { |
| 557 FPasses->doInitialization(); | 670 FPasses->doInitialization(); |
| 558 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F) | 671 for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F) |
| 559 FPasses->run(*F); | 672 FPasses->run(*F); |
| 560 FPasses->doFinalization(); | 673 FPasses->doFinalization(); |
| 561 } | 674 } |
| 562 | 675 |
| 676 // @LOCALMOD-BEGIN |
| 677 if (PNaClABISimplifyPostOpt) |
| 678 PNaClABISimplifyAddPostOptPasses(Passes); |
| 679 |
| 680 if (MinSFI) |
| 681 MinSFIPasses(Passes); |
| 682 // @LOCALMOD-END |
| 683 |
| 563 // Check that the module is well formed on completion of optimization | 684 // Check that the module is well formed on completion of optimization |
| 564 if (!NoVerify && !VerifyEach) { | 685 if (!NoVerify && !VerifyEach) { |
| 565 Passes.add(createVerifierPass()); | 686 Passes.add(createVerifierPass()); |
| 566 Passes.add(createDebugInfoVerifierPass()); | 687 Passes.add(createDebugInfoVerifierPass()); |
| 567 } | 688 } |
| 568 | 689 |
| 569 // Write bitcode or assembly to the output as the last step... | 690 // Write bitcode or assembly to the output as the last step... |
| 570 if (!NoOutput && !AnalyzeOnly) { | 691 if (!NoOutput && !AnalyzeOnly) { |
| 571 if (OutputAssembly) | 692 if (OutputAssembly) |
| 572 Passes.add(createPrintModulePass(Out->os())); | 693 Passes.add(createPrintModulePass(Out->os())); |
| 573 else | 694 else |
| 574 Passes.add(createBitcodeWriterPass(Out->os())); | 695 // @LOCALMOD-START |
| 696 switch (OutputFileFormat) { |
| 697 case LLVMFormat: |
| 698 Passes.add(createBitcodeWriterPass(Out->os())); |
| 699 break; |
| 700 case PNaClFormat: |
| 701 Passes.add(createNaClBitcodeWriterPass(Out->os())); |
| 702 break; |
| 703 case AutodetectFileFormat: |
| 704 report_fatal_error("Command can't autodetect file format!"); |
| 705 break; |
| 706 } |
| 707 // @LOCALMOD-END |
| 575 } | 708 } |
| 576 | 709 |
| 577 // Before executing passes, print the final values of the LLVM options. | 710 // Before executing passes, print the final values of the LLVM options. |
| 578 cl::PrintOptionValues(); | 711 cl::PrintOptionValues(); |
| 579 | 712 |
| 580 // Now that we have all of the passes ready, run them. | 713 // Now that we have all of the passes ready, run them. |
| 581 Passes.run(*M.get()); | 714 Passes.run(*M.get()); |
| 582 | 715 |
| 583 // Declare success. | 716 // Declare success. |
| 584 if (!NoOutput || PrintBreakpoints) | 717 if (!NoOutput || PrintBreakpoints) |
| 585 Out->keep(); | 718 Out->keep(); |
| 586 | 719 |
| 587 return 0; | 720 return 0; |
| 588 } | 721 } |
| OLD | NEW |