LLVM  11.0.0git
PassBuilder.cpp
Go to the documentation of this file.
1 //===- Parsing, selection, and construction of pass pipelines -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 ///
10 /// This file provides the implementation of the PassBuilder based on our
11 /// static pass registry as well as related functionality. It also provides
12 /// helpers to aid in analyzing, debugging, and testing passes and pass
13 /// pipelines.
14 ///
15 //===----------------------------------------------------------------------===//
16 
18 #include "llvm/ADT/StringSwitch.h"
30 #include "llvm/Analysis/DDG.h"
35 #include "llvm/Analysis/IVUsers.h"
42 #include "llvm/Analysis/LoopInfo.h"
60 #include "llvm/IR/Dominators.h"
62 #include "llvm/IR/PassManager.h"
64 #include "llvm/IR/Verifier.h"
66 #include "llvm/Support/Debug.h"
68 #include "llvm/Support/Regex.h"
195 
196 using namespace llvm;
197 
198 static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
200 static cl::opt<bool>
201  RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
203  cl::desc("Run Partial inlinining pass"));
204 
206  "npm-preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore,
207  cl::desc("Control the amount of inlining in pre-instrumentation inliner "
208  "(default = 75)"));
209 
210 static cl::opt<bool>
211  RunNewGVN("enable-npm-newgvn", cl::init(false),
213  cl::desc("Run NewGVN instead of GVN"));
214 
216  "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
217  cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
218 
220  "enable-ml-inliner", cl::init(InliningAdvisorMode::Default), cl::Hidden,
221  cl::desc("Enable ML policy for inliner. Currently trained for -Oz only"),
223  "Heuristics-based inliner version."),
225  "Use development mode (runtime-loadable model)."),
227  "Use release mode (AOT-compiled model).")));
228 
230  "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
231  cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
232 
234  "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden,
235  cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"));
236 
238  "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
239  cl::desc("Run synthetic function entry count generation "
240  "pass"));
241 
242 static const Regex DefaultAliasRegex(
243  "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
244 
245 // This option is used in simplifying testing SampleFDO optimizations for
246 // profile loading.
247 static cl::opt<bool>
248  EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
249  cl::desc("Enable control height reduction optimization (CHR)"));
250 
252  "enable-npm-call-graph-profile", cl::init(true), cl::Hidden,
253  cl::desc("Enable call graph profile pass for the new PM (default = on)"));
254 
255 /// Flag to enable inline deferral during PGO.
256 static cl::opt<bool>
257  EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true),
258  cl::Hidden,
259  cl::desc("Enable inline deferral during PGO"));
260 
262  LoopInterleaving = true;
263  LoopVectorization = true;
264  SLPVectorization = false;
265  LoopUnrolling = true;
267  Coroutines = false;
271 }
272 
275 
277 
280 
282  /*SpeedLevel*/ 0,
283  /*SizeLevel*/ 0};
285  /*SpeedLevel*/ 1,
286  /*SizeLevel*/ 0};
288  /*SpeedLevel*/ 2,
289  /*SizeLevel*/ 0};
291  /*SpeedLevel*/ 3,
292  /*SizeLevel*/ 0};
294  /*SpeedLevel*/ 2,
295  /*SizeLevel*/ 1};
297  /*SpeedLevel*/ 2,
298  /*SizeLevel*/ 2};
299 
300 namespace {
301 
302 /// No-op module pass which does nothing.
303 struct NoOpModulePass {
305  return PreservedAnalyses::all();
306  }
307  static StringRef name() { return "NoOpModulePass"; }
308 };
309 
310 /// No-op module analysis.
311 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
313  static AnalysisKey Key;
314 
315 public:
316  struct Result {};
317  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
318  static StringRef name() { return "NoOpModuleAnalysis"; }
319 };
320 
321 /// No-op CGSCC pass which does nothing.
322 struct NoOpCGSCCPass {
325  return PreservedAnalyses::all();
326  }
327  static StringRef name() { return "NoOpCGSCCPass"; }
328 };
329 
330 /// No-op CGSCC analysis.
331 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
333  static AnalysisKey Key;
334 
335 public:
336  struct Result {};
338  return Result();
339  }
340  static StringRef name() { return "NoOpCGSCCAnalysis"; }
341 };
342 
343 /// No-op function pass which does nothing.
344 struct NoOpFunctionPass {
346  return PreservedAnalyses::all();
347  }
348  static StringRef name() { return "NoOpFunctionPass"; }
349 };
350 
351 /// No-op function analysis.
352 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
354  static AnalysisKey Key;
355 
356 public:
357  struct Result {};
358  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
359  static StringRef name() { return "NoOpFunctionAnalysis"; }
360 };
361 
362 /// No-op loop pass which does nothing.
363 struct NoOpLoopPass {
366  return PreservedAnalyses::all();
367  }
368  static StringRef name() { return "NoOpLoopPass"; }
369 };
370 
371 /// No-op loop analysis.
372 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
374  static AnalysisKey Key;
375 
376 public:
377  struct Result {};
379  return Result();
380  }
381  static StringRef name() { return "NoOpLoopAnalysis"; }
382 };
383 
388 
389 } // End anonymous namespace.
390 
391 void PassBuilder::invokePeepholeEPCallbacks(
393  for (auto &C : PeepholeEPCallbacks)
394  C(FPM, Level);
395 }
396 
398 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
399  MAM.registerPass([&] { return CREATE_PASS; });
400 #include "PassRegistry.def"
401 
402  for (auto &C : ModuleAnalysisRegistrationCallbacks)
403  C(MAM);
404 }
405 
407 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
408  CGAM.registerPass([&] { return CREATE_PASS; });
409 #include "PassRegistry.def"
410 
411  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
412  C(CGAM);
413 }
414 
416 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
417  FAM.registerPass([&] { return CREATE_PASS; });
418 #include "PassRegistry.def"
419 
420  for (auto &C : FunctionAnalysisRegistrationCallbacks)
421  C(FAM);
422 }
423 
425 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
426  LAM.registerPass([&] { return CREATE_PASS; });
427 #include "PassRegistry.def"
428 
429  for (auto &C : LoopAnalysisRegistrationCallbacks)
430  C(LAM);
431 }
432 
433 // TODO: Investigate the cost/benefit of tail call elimination on debugging.
434 FunctionPassManager PassBuilder::buildO1FunctionSimplificationPipeline(
435  OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
436 
437  FunctionPassManager FPM(DebugLogging);
438 
439  // Form SSA out of local memory accesses after breaking apart aggregates into
440  // scalars.
441  FPM.addPass(SROA());
442 
443  // Catch trivial redundancies
444  FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
445 
446  // Hoisting of scalars and load expressions.
447  FPM.addPass(SimplifyCFGPass());
448  FPM.addPass(InstCombinePass());
449 
451 
452  invokePeepholeEPCallbacks(FPM, Level);
453 
454  FPM.addPass(SimplifyCFGPass());
455 
456  // Form canonically associated expression trees, and simplify the trees using
457  // basic mathematical properties. For example, this will form (nearly)
458  // minimal multiplication trees.
459  FPM.addPass(ReassociatePass());
460 
461  // Add the primary loop simplification pipeline.
462  // FIXME: Currently this is split into two loop pass pipelines because we run
463  // some function passes in between them. These can and should be removed
464  // and/or replaced by scheduling the loop pass equivalents in the correct
465  // positions. But those equivalent passes aren't powerful enough yet.
466  // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
467  // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
468  // fully replace `SimplifyCFGPass`, and the closest to the other we have is
469  // `LoopInstSimplify`.
470  LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
471 
472  // Simplify the loop body. We do this initially to clean up after other loop
473  // passes run, either when iterating on a loop or on inner loops with
474  // implications on the outer loop.
475  LPM1.addPass(LoopInstSimplifyPass());
476  LPM1.addPass(LoopSimplifyCFGPass());
477 
478  LPM1.addPass(LoopRotatePass(/* Disable header duplication */ true));
479  // TODO: Investigate promotion cap for O1.
480  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
481  LPM1.addPass(SimpleLoopUnswitchPass());
482  LPM2.addPass(IndVarSimplifyPass());
484 
485  for (auto &C : LateLoopOptimizationsEPCallbacks)
486  C(LPM2, Level);
487 
488  LPM2.addPass(LoopDeletionPass());
489  // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
490  // because it changes IR to makes profile annotation in back compile
491  // inaccurate. The normal unroller doesn't pay attention to forced full unroll
492  // attributes so we need to make sure and allow the full unroll pass to pay
493  // attention to it.
494  if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
495  PGOOpt->Action != PGOOptions::SampleUse)
497  /* OnlyWhenForced= */ !PTO.LoopUnrolling,
498  PTO.ForgetAllSCEVInLoopUnroll));
499 
500  for (auto &C : LoopOptimizerEndEPCallbacks)
501  C(LPM2, Level);
502 
503  // We provide the opt remark emitter pass for LICM to use. We only need to do
504  // this once as it is immutable.
505  FPM.addPass(
508  std::move(LPM1), EnableMSSALoopDependency, DebugLogging));
509  FPM.addPass(SimplifyCFGPass());
510  FPM.addPass(InstCombinePass());
511  // The loop passes in LPM2 (LoopFullUnrollPass) do not preserve MemorySSA.
512  // *All* loop passes must preserve it, in order to be able to use it.
514  std::move(LPM2), /*UseMemorySSA=*/false, DebugLogging));
515 
516  // Delete small array after loop unroll.
517  FPM.addPass(SROA());
518 
519  // Specially optimize memory movement as it doesn't look like dataflow in SSA.
520  FPM.addPass(MemCpyOptPass());
521 
522  // Sparse conditional constant propagation.
523  // FIXME: It isn't clear why we do this *after* loop passes rather than
524  // before...
525  FPM.addPass(SCCPPass());
526 
527  // Delete dead bit computations (instcombine runs after to fold away the dead
528  // computations, and then ADCE will run later to exploit any new DCE
529  // opportunities that creates).
530  FPM.addPass(BDCEPass());
531 
532  // Run instcombine after redundancy and dead bit elimination to exploit
533  // opportunities opened up by them.
534  FPM.addPass(InstCombinePass());
535  invokePeepholeEPCallbacks(FPM, Level);
536 
537  if (PTO.Coroutines)
538  FPM.addPass(CoroElidePass());
539 
540  for (auto &C : ScalarOptimizerLateEPCallbacks)
541  C(FPM, Level);
542 
543  // Finally, do an expensive DCE pass to catch all the dead code exposed by
544  // the simplifications and basic cleanup after all the simplifications.
545  // TODO: Investigate if this is too expensive.
546  FPM.addPass(ADCEPass());
547  FPM.addPass(SimplifyCFGPass());
548  FPM.addPass(InstCombinePass());
549  invokePeepholeEPCallbacks(FPM, Level);
550 
551  return FPM;
552 }
553 
556  ThinLTOPhase Phase,
557  bool DebugLogging) {
558  assert(Level != OptimizationLevel::O0 && "Must request optimizations!");
559 
560  // The O1 pipeline has a separate pipeline creation function to simplify
561  // construction readability.
562  if (Level.getSpeedupLevel() == 1)
563  return buildO1FunctionSimplificationPipeline(Level, Phase, DebugLogging);
564 
565  FunctionPassManager FPM(DebugLogging);
566 
567  // Form SSA out of local memory accesses after breaking apart aggregates into
568  // scalars.
569  FPM.addPass(SROA());
570 
571  // Catch trivial redundancies
572  FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
573  if (EnableKnowledgeRetention)
575 
576  // Hoisting of scalars and load expressions.
577  if (EnableGVNHoist)
578  FPM.addPass(GVNHoistPass());
579 
580  // Global value numbering based sinking.
581  if (EnableGVNSink) {
582  FPM.addPass(GVNSinkPass());
583  FPM.addPass(SimplifyCFGPass());
584  }
585 
586  // Speculative execution if the target has divergent branches; otherwise nop.
587  FPM.addPass(SpeculativeExecutionPass(/* OnlyIfDivergentTarget =*/true));
588 
589  // Optimize based on known information about branches, and cleanup afterward.
590  FPM.addPass(JumpThreadingPass());
592 
593  FPM.addPass(SimplifyCFGPass());
594  if (Level == OptimizationLevel::O3)
596  FPM.addPass(InstCombinePass());
597 
598  if (!Level.isOptimizingForSize())
600 
601  invokePeepholeEPCallbacks(FPM, Level);
602 
603  // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
604  // using the size value profile. Don't perform this when optimizing for size.
605  if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse &&
606  !Level.isOptimizingForSize())
607  FPM.addPass(PGOMemOPSizeOpt());
608 
609  FPM.addPass(TailCallElimPass());
610  FPM.addPass(SimplifyCFGPass());
611 
612  // Form canonically associated expression trees, and simplify the trees using
613  // basic mathematical properties. For example, this will form (nearly)
614  // minimal multiplication trees.
615  FPM.addPass(ReassociatePass());
616 
617  // Add the primary loop simplification pipeline.
618  // FIXME: Currently this is split into two loop pass pipelines because we run
619  // some function passes in between them. These can and should be removed
620  // and/or replaced by scheduling the loop pass equivalents in the correct
621  // positions. But those equivalent passes aren't powerful enough yet.
622  // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
623  // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
624  // fully replace `SimplifyCFGPass`, and the closest to the other we have is
625  // `LoopInstSimplify`.
626  LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
627 
628  // Simplify the loop body. We do this initially to clean up after other loop
629  // passes run, either when iterating on a loop or on inner loops with
630  // implications on the outer loop.
631  LPM1.addPass(LoopInstSimplifyPass());
632  LPM1.addPass(LoopSimplifyCFGPass());
633 
634  // Rotate Loop - disable header duplication at -Oz
635  LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz));
636  // TODO: Investigate promotion cap for O1.
637  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
638  LPM1.addPass(SimpleLoopUnswitchPass());
639  LPM2.addPass(IndVarSimplifyPass());
641 
642  for (auto &C : LateLoopOptimizationsEPCallbacks)
643  C(LPM2, Level);
644 
645  LPM2.addPass(LoopDeletionPass());
646  // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
647  // because it changes IR to makes profile annotation in back compile
648  // inaccurate. The normal unroller doesn't pay attention to forced full unroll
649  // attributes so we need to make sure and allow the full unroll pass to pay
650  // attention to it.
651  if (Phase != ThinLTOPhase::PreLink || !PGOOpt ||
652  PGOOpt->Action != PGOOptions::SampleUse)
654  /* OnlyWhenForced= */ !PTO.LoopUnrolling,
655  PTO.ForgetAllSCEVInLoopUnroll));
656 
657  for (auto &C : LoopOptimizerEndEPCallbacks)
658  C(LPM2, Level);
659 
660  // We provide the opt remark emitter pass for LICM to use. We only need to do
661  // this once as it is immutable.
662  FPM.addPass(
665  std::move(LPM1), EnableMSSALoopDependency, DebugLogging));
666  FPM.addPass(SimplifyCFGPass());
667  FPM.addPass(InstCombinePass());
668  // The loop passes in LPM2 (IndVarSimplifyPass, LoopIdiomRecognizePass,
669  // LoopDeletionPass and LoopFullUnrollPass) do not preserve MemorySSA.
670  // *All* loop passes must preserve it, in order to be able to use it.
672  std::move(LPM2), /*UseMemorySSA=*/false, DebugLogging));
673 
674  // Delete small array after loop unroll.
675  FPM.addPass(SROA());
676 
677  // Eliminate redundancies.
679  if (RunNewGVN)
680  FPM.addPass(NewGVNPass());
681  else
682  FPM.addPass(GVN());
683 
684  // Specially optimize memory movement as it doesn't look like dataflow in SSA.
685  FPM.addPass(MemCpyOptPass());
686 
687  // Sparse conditional constant propagation.
688  // FIXME: It isn't clear why we do this *after* loop passes rather than
689  // before...
690  FPM.addPass(SCCPPass());
691 
692  // Delete dead bit computations (instcombine runs after to fold away the dead
693  // computations, and then ADCE will run later to exploit any new DCE
694  // opportunities that creates).
695  FPM.addPass(BDCEPass());
696 
697  // Run instcombine after redundancy and dead bit elimination to exploit
698  // opportunities opened up by them.
699  FPM.addPass(InstCombinePass());
700  invokePeepholeEPCallbacks(FPM, Level);
701 
702  // Re-consider control flow based optimizations after redundancy elimination,
703  // redo DCE, etc.
704  FPM.addPass(JumpThreadingPass());
706  FPM.addPass(DSEPass());
708  LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
709  EnableMSSALoopDependency, DebugLogging));
710 
711  if (PTO.Coroutines)
712  FPM.addPass(CoroElidePass());
713 
714  for (auto &C : ScalarOptimizerLateEPCallbacks)
715  C(FPM, Level);
716 
717  // Finally, do an expensive DCE pass to catch all the dead code exposed by
718  // the simplifications and basic cleanup after all the simplifications.
719  // TODO: Investigate if this is too expensive.
720  FPM.addPass(ADCEPass());
721  FPM.addPass(SimplifyCFGPass());
722  FPM.addPass(InstCombinePass());
723  invokePeepholeEPCallbacks(FPM, Level);
724 
725  if (EnableCHR && Level == OptimizationLevel::O3 && PGOOpt &&
726  (PGOOpt->Action == PGOOptions::IRUse ||
727  PGOOpt->Action == PGOOptions::SampleUse))
729 
730  return FPM;
731 }
732 
733 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
735  bool RunProfileGen, bool IsCS,
736  std::string ProfileFile,
737  std::string ProfileRemappingFile) {
738  assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!");
739  // Generally running simplification passes and the inliner with an high
740  // threshold results in smaller executables, but there may be cases where
741  // the size grows, so let's be conservative here and skip this simplification
742  // at -Os/Oz. We will not do this inline for context sensistive PGO (when
743  // IsCS is true).
744  if (!Level.isOptimizingForSize() && !IsCS) {
745  InlineParams IP;
746 
748 
749  // FIXME: The hint threshold has the same value used by the regular inliner.
750  // This should probably be lowered after performance testing.
751  // FIXME: this comment is cargo culted from the old pass manager, revisit).
752  IP.HintThreshold = 325;
753  ModuleInlinerWrapperPass MIWP(IP, DebugLogging);
754  CGSCCPassManager &CGPipeline = MIWP.getPM();
755 
757  FPM.addPass(SROA());
758  FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
759  FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
760  FPM.addPass(InstCombinePass()); // Combine silly sequences.
761  invokePeepholeEPCallbacks(FPM, Level);
762 
763  CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
764 
765  MPM.addPass(std::move(MIWP));
766 
767  // Delete anything that is now dead to make sure that we don't instrument
768  // dead code. Instrumentation can end up keeping dead code around and
769  // dramatically increase code size.
770  MPM.addPass(GlobalDCEPass());
771  }
772 
773  if (!RunProfileGen) {
774  assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
775  MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS));
776  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
777  // RequireAnalysisPass for PSI before subsequent non-module passes.
779  return;
780  }
781 
782  // Perform PGO instrumentation.
783  MPM.addPass(PGOInstrumentationGen(IsCS));
784 
787  LoopRotatePass(), EnableMSSALoopDependency, DebugLogging));
788  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
789 
790  // Add the profile lowering pass.
791  InstrProfOptions Options;
792  if (!ProfileFile.empty())
793  Options.InstrProfileOutput = ProfileFile;
794  // Do counter promotion at Level greater than O0.
795  Options.DoCounterPromotion = true;
796  Options.UseBFIInPromotion = IsCS;
797  MPM.addPass(InstrProfiling(Options, IsCS));
798 }
799 
801  bool DebugLogging, bool RunProfileGen,
802  bool IsCS, std::string ProfileFile,
803  std::string ProfileRemappingFile) {
804  if (!RunProfileGen) {
805  assert(!ProfileFile.empty() && "Profile use expecting a profile file!");
806  MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS));
807  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
808  // RequireAnalysisPass for PSI before subsequent non-module passes.
810  return;
811  }
812 
813  // Perform PGO instrumentation.
814  MPM.addPass(PGOInstrumentationGen(IsCS));
815  // Add the profile lowering pass.
816  InstrProfOptions Options;
817  if (!ProfileFile.empty())
818  Options.InstrProfileOutput = ProfileFile;
819  // Do not do counter promotion at O0.
820  Options.DoCounterPromotion = false;
821  Options.UseBFIInPromotion = IsCS;
822  MPM.addPass(InstrProfiling(Options, IsCS));
823 }
824 
825 static InlineParams
827  return getInlineParams(Level.getSpeedupLevel(), Level.getSizeLevel());
828 }
829 
832  bool DebugLogging) {
834  if (Phase == PassBuilder::ThinLTOPhase::PreLink && PGOOpt &&
835  PGOOpt->Action == PGOOptions::SampleUse)
836  IP.HotCallSiteThreshold = 0;
837 
838  if (PGOOpt)
840 
841  ModuleInlinerWrapperPass MIWP(IP, DebugLogging, UseInlineAdvisor,
843 
844  // Require the GlobalsAA analysis for the module so we can query it within
845  // the CGSCC pipeline.
847 
848  // Require the ProfileSummaryAnalysis for the module so we can query it within
849  // the inliner pass.
851 
852  // Now begin the main postorder CGSCC pipeline.
853  // FIXME: The current CGSCC pipeline has its origins in the legacy pass
854  // manager and trying to emulate its precise behavior. Much of this doesn't
855  // make a lot of sense and we should revisit the core CGSCC structure.
856  CGSCCPassManager &MainCGPipeline = MIWP.getPM();
857 
858  // Note: historically, the PruneEH pass was run first to deduce nounwind and
859  // generally clean up exception handling overhead. It isn't clear this is
860  // valuable as the inliner doesn't currently care whether it is inlining an
861  // invoke or a call.
862 
863  if (AttributorRun & AttributorRunOption::CGSCC)
864  MainCGPipeline.addPass(AttributorCGSCCPass());
865 
866  if (PTO.Coroutines)
867  MainCGPipeline.addPass(CoroSplitPass());
868 
869  // Now deduce any function attributes based in the current code.
870  MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
871 
872  // When at O3 add argument promotion to the pass pipeline.
873  // FIXME: It isn't at all clear why this should be limited to O3.
874  if (Level == OptimizationLevel::O3)
875  MainCGPipeline.addPass(ArgumentPromotionPass());
876 
877  // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
878  // there are no OpenMP runtime calls present in the module.
879  if (Level == OptimizationLevel::O2 || Level == OptimizationLevel::O3)
880  MainCGPipeline.addPass(OpenMPOptPass());
881 
882  // Lastly, add the core function simplification pipeline nested inside the
883  // CGSCC walk.
884  MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
885  buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
886 
887  for (auto &C : CGSCCOptimizerLateEPCallbacks)
888  C(MainCGPipeline, Level);
889 
890  return MIWP;
891 }
892 
894  OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
895  ModulePassManager MPM(DebugLogging);
896 
897  bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
898 
899  // In ThinLTO mode, when flattened profile is used, all the available
900  // profile information will be annotated in PreLink phase so there is
901  // no need to load the profile again in PostLink.
902  bool LoadSampleProfile =
903  HasSampleProfile &&
904  !(FlattenedProfileUsed && Phase == ThinLTOPhase::PostLink);
905 
906  // During the ThinLTO backend phase we perform early indirect call promotion
907  // here, before globalopt. Otherwise imported available_externally functions
908  // look unreferenced and are removed. If we are going to load the sample
909  // profile then defer until later.
910  // TODO: See if we can move later and consolidate with the location where
911  // we perform ICP when we are loading a sample profile.
912  // TODO: We pass HasSampleProfile (whether there was a sample profile file
913  // passed to the compile) to the SamplePGO flag of ICP. This is used to
914  // determine whether the new direct calls are annotated with prof metadata.
915  // Ideally this should be determined from whether the IR is annotated with
916  // sample profile, and not whether the a sample profile was provided on the
917  // command line. E.g. for flattened profiles where we will not be reloading
918  // the sample profile in the ThinLTO backend, we ideally shouldn't have to
919  // provide the sample profile file.
920  if (Phase == ThinLTOPhase::PostLink && !LoadSampleProfile)
921  MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile));
922 
923  // Do basic inference of function attributes from known properties of system
924  // libraries and other oracles.
926 
927  // Create an early function pass manager to cleanup the output of the
928  // frontend.
929  FunctionPassManager EarlyFPM(DebugLogging);
930  EarlyFPM.addPass(SimplifyCFGPass());
931  EarlyFPM.addPass(SROA());
932  EarlyFPM.addPass(EarlyCSEPass());
933  EarlyFPM.addPass(LowerExpectIntrinsicPass());
934  if (PTO.Coroutines)
935  EarlyFPM.addPass(CoroEarlyPass());
936  if (Level == OptimizationLevel::O3)
937  EarlyFPM.addPass(CallSiteSplittingPass());
938 
939  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
940  // to convert bitcast to direct calls so that they can be inlined during the
941  // profile annotation prepration step.
942  // More details about SamplePGO design can be found in:
943  // https://research.google.com/pubs/pub45290.html
944  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
945  if (LoadSampleProfile)
946  EarlyFPM.addPass(InstCombinePass());
947  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
948 
949  if (LoadSampleProfile) {
950  // Annotate sample profile right after early FPM to ensure freshness of
951  // the debug info.
952  MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
953  PGOOpt->ProfileRemappingFile,
954  Phase == ThinLTOPhase::PreLink));
955  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
956  // RequireAnalysisPass for PSI before subsequent non-module passes.
958  // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
959  // for the profile annotation to be accurate in the ThinLTO backend.
960  if (Phase != ThinLTOPhase::PreLink)
961  // We perform early indirect call promotion here, before globalopt.
962  // This is important for the ThinLTO backend phase because otherwise
963  // imported available_externally functions look unreferenced and are
964  // removed.
965  MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
966  true /* SamplePGO */));
967  }
968 
969  if (AttributorRun & AttributorRunOption::MODULE)
970  MPM.addPass(AttributorPass());
971 
972  // Interprocedural constant propagation now that basic cleanup has occurred
973  // and prior to optimizing globals.
974  // FIXME: This position in the pipeline hasn't been carefully considered in
975  // years, it should be re-analyzed.
976  MPM.addPass(IPSCCPPass());
977 
978  // Attach metadata to indirect call sites indicating the set of functions
979  // they may target at run-time. This should follow IPSCCP.
981 
982  // Optimize globals to try and fold them into constants.
983  MPM.addPass(GlobalOptPass());
984 
985  // Promote any localized globals to SSA registers.
986  // FIXME: Should this instead by a run of SROA?
987  // FIXME: We should probably run instcombine and simplify-cfg afterward to
988  // delete control flows that are dead once globals have been folded to
989  // constants.
991 
992  // Remove any dead arguments exposed by cleanups and constant folding
993  // globals.
995 
996  // Create a small function pass pipeline to cleanup after all the global
997  // optimizations.
998  FunctionPassManager GlobalCleanupPM(DebugLogging);
999  GlobalCleanupPM.addPass(InstCombinePass());
1000  invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
1001 
1002  GlobalCleanupPM.addPass(SimplifyCFGPass());
1003  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
1004 
1005  // Add all the requested passes for instrumentation PGO, if requested.
1006  if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
1007  (PGOOpt->Action == PGOOptions::IRInstr ||
1008  PGOOpt->Action == PGOOptions::IRUse)) {
1009  addPGOInstrPasses(MPM, DebugLogging, Level,
1010  /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
1011  /* IsCS */ false, PGOOpt->ProfileFile,
1012  PGOOpt->ProfileRemappingFile);
1013  MPM.addPass(PGOIndirectCallPromotion(false, false));
1014  }
1015  if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
1016  PGOOpt->CSAction == PGOOptions::CSIRInstr)
1017  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile));
1018 
1019  // Synthesize function entry counts for non-PGO compilation.
1020  if (EnableSyntheticCounts && !PGOOpt)
1022 
1023  MPM.addPass(buildInlinerPipeline(Level, Phase, DebugLogging));
1024  return MPM;
1025 }
1026 
1028  OptimizationLevel Level, bool DebugLogging, bool LTOPreLink) {
1029  ModulePassManager MPM(DebugLogging);
1030 
1031  // Optimize globals now that the module is fully simplified.
1032  MPM.addPass(GlobalOptPass());
1033  MPM.addPass(GlobalDCEPass());
1034 
1035  // Run partial inlining pass to partially inline functions that have
1036  // large bodies.
1037  if (RunPartialInlining)
1038  MPM.addPass(PartialInlinerPass());
1039 
1040  // Remove avail extern fns and globals definitions since we aren't compiling
1041  // an object file for later LTO. For LTO we want to preserve these so they
1042  // are eligible for inlining at link-time. Note if they are unreferenced they
1043  // will be removed by GlobalDCE later, so this only impacts referenced
1044  // available externally globals. Eventually they will be suppressed during
1045  // codegen, but eliminating here enables more opportunity for GlobalDCE as it
1046  // may make globals referenced by available external functions dead and saves
1047  // running remaining passes on the eliminated functions. These should be
1048  // preserved during prelinking for link-time inlining decisions.
1049  if (!LTOPreLink)
1051 
1052  if (EnableOrderFileInstrumentation)
1053  MPM.addPass(InstrOrderFilePass());
1054 
1055  // Do RPO function attribute inference across the module to forward-propagate
1056  // attributes where applicable.
1057  // FIXME: Is this really an optimization rather than a canonicalization?
1059 
1060  // Do a post inline PGO instrumentation and use pass. This is a context
1061  // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as
1062  // cross-module inline has not been done yet. The context sensitive
1063  // instrumentation is after all the inlines are done.
1064  if (!LTOPreLink && PGOOpt) {
1065  if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1066  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
1067  /* IsCS */ true, PGOOpt->CSProfileGenFile,
1068  PGOOpt->ProfileRemappingFile);
1069  else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1070  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
1071  /* IsCS */ true, PGOOpt->ProfileFile,
1072  PGOOpt->ProfileRemappingFile);
1073  }
1074 
1075  // Re-require GloblasAA here prior to function passes. This is particularly
1076  // useful as the above will have inlined, DCE'ed, and function-attr
1077  // propagated everything. We should at this point have a reasonably minimal
1078  // and richly annotated call graph. By computing aliasing and mod/ref
1079  // information for all local globals here, the late loop passes and notably
1080  // the vectorizer will be able to use them to help recognize vectorizable
1081  // memory operations.
1083 
1084  FunctionPassManager OptimizePM(DebugLogging);
1085  OptimizePM.addPass(Float2IntPass());
1086  OptimizePM.addPass(LowerConstantIntrinsicsPass());
1087 
1088  // FIXME: We need to run some loop optimizations to re-rotate loops after
1089  // simplify-cfg and others undo their rotation.
1090 
1091  // Optimize the loop execution. These passes operate on entire loop nests
1092  // rather than on each loop in an inside-out manner, and so they are actually
1093  // function passes.
1094 
1095  for (auto &C : VectorizerStartEPCallbacks)
1096  C(OptimizePM, Level);
1097 
1098  // First rotate loops that may have been un-rotated by prior passes.
1100  LoopRotatePass(), EnableMSSALoopDependency, DebugLogging));
1101 
1102  // Distribute loops to allow partial vectorization. I.e. isolate dependences
1103  // into separate loop that would otherwise inhibit vectorization. This is
1104  // currently only performed for loops marked with the metadata
1105  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
1106  OptimizePM.addPass(LoopDistributePass());
1107 
1108  // Populates the VFABI attribute with the scalar-to-vector mappings
1109  // from the TargetLibraryInfo.
1110  OptimizePM.addPass(InjectTLIMappings());
1111 
1112  // Now run the core loop vectorizer.
1113  OptimizePM.addPass(LoopVectorizePass(
1114  LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
1115 
1116  // Eliminate loads by forwarding stores from the previous iteration to loads
1117  // of the current iteration.
1118  OptimizePM.addPass(LoopLoadEliminationPass());
1119 
1120  // Cleanup after the loop optimization passes.
1121  OptimizePM.addPass(InstCombinePass());
1122 
1123  // Now that we've formed fast to execute loop structures, we do further
1124  // optimizations. These are run afterward as they might block doing complex
1125  // analyses and transforms such as what are needed for loop vectorization.
1126 
1127  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
1128  // GVN, loop transforms, and others have already run, so it's now better to
1129  // convert to more optimized IR using more aggressive simplify CFG options.
1130  // The extra sinking transform can create larger basic blocks, so do this
1131  // before SLP vectorization.
1133  forwardSwitchCondToPhi(true).
1134  convertSwitchToLookupTable(true).
1135  needCanonicalLoops(false).
1136  sinkCommonInsts(true)));
1137 
1138  // Optimize parallel scalar instruction chains into SIMD instructions.
1139  if (PTO.SLPVectorization)
1140  OptimizePM.addPass(SLPVectorizerPass());
1141 
1142  // Enhance/cleanup vector code.
1143  OptimizePM.addPass(VectorCombinePass());
1144  OptimizePM.addPass(InstCombinePass());
1145 
1146  // Unroll small loops to hide loop backedge latency and saturate any parallel
1147  // execution resources of an out-of-order processor. We also then need to
1148  // clean up redundancies and loop invariant code.
1149  // FIXME: It would be really good to use a loop-integrated instruction
1150  // combiner for cleanup here so that the unrolling and LICM can be pipelined
1151  // across the loop nests.
1152  // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
1153  if (EnableUnrollAndJam && PTO.LoopUnrolling) {
1154  OptimizePM.addPass(LoopUnrollAndJamPass(Level.getSpeedupLevel()));
1155  }
1157  Level.getSpeedupLevel(), /*OnlyWhenForced=*/!PTO.LoopUnrolling,
1158  PTO.ForgetAllSCEVInLoopUnroll)));
1159  OptimizePM.addPass(WarnMissedTransformationsPass());
1160  OptimizePM.addPass(InstCombinePass());
1163  LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
1164  EnableMSSALoopDependency, DebugLogging));
1165 
1166  // Now that we've vectorized and unrolled loops, we may have more refined
1167  // alignment information, try to re-derive it here.
1168  OptimizePM.addPass(AlignmentFromAssumptionsPass());
1169 
1170  // Split out cold code. Splitting is done late to avoid hiding context from
1171  // other optimizations and inadvertently regressing performance. The tradeoff
1172  // is that this has a higher code size cost than splitting early.
1173  if (EnableHotColdSplit && !LTOPreLink)
1175 
1176  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
1177  // canonicalization pass that enables other optimizations. As a result,
1178  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
1179  // result too early.
1180  OptimizePM.addPass(LoopSinkPass());
1181 
1182  // And finally clean up LCSSA form before generating code.
1183  OptimizePM.addPass(InstSimplifyPass());
1184 
1185  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
1186  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
1187  // flattening of blocks.
1188  OptimizePM.addPass(DivRemPairsPass());
1189 
1190  // LoopSink (and other loop passes since the last simplifyCFG) might have
1191  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
1192  OptimizePM.addPass(SimplifyCFGPass());
1193 
1194  // Optimize PHIs by speculating around them when profitable. Note that this
1195  // pass needs to be run after any PRE or similar pass as it is essentially
1196  // inserting redundancies into the program. This even includes SimplifyCFG.
1197  OptimizePM.addPass(SpeculateAroundPHIsPass());
1198 
1199  if (PTO.Coroutines)
1200  OptimizePM.addPass(CoroCleanupPass());
1201 
1202  // Add the core optimizing pipeline.
1203  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
1204 
1205  for (auto &C : OptimizerLastEPCallbacks)
1206  C(MPM, Level);
1207 
1208  if (PTO.CallGraphProfile)
1209  MPM.addPass(CGProfilePass());
1210 
1211  // Now we need to do some global optimization transforms.
1212  // FIXME: It would seem like these should come first in the optimization
1213  // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
1214  // ordering here.
1215  MPM.addPass(GlobalDCEPass());
1216  MPM.addPass(ConstantMergePass());
1217 
1218  return MPM;
1219 }
1220 
1223  bool DebugLogging, bool LTOPreLink) {
1224  assert(Level != OptimizationLevel::O0 &&
1225  "Must request optimizations for the default pipeline!");
1226 
1227  ModulePassManager MPM(DebugLogging);
1228 
1229  // Force any function attributes we want the rest of the pipeline to observe.
1231 
1232  // Apply module pipeline start EP callback.
1233  for (auto &C : PipelineStartEPCallbacks)
1234  C(MPM);
1235 
1236  if (PGOOpt && PGOOpt->SamplePGOSupport)
1238 
1239  // Add the core simplification pipeline.
1240  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
1241  DebugLogging));
1242 
1243  // Now add the optimization pipeline.
1244  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging, LTOPreLink));
1245 
1246  return MPM;
1247 }
1248 
1251  bool DebugLogging) {
1252  assert(Level != OptimizationLevel::O0 &&
1253  "Must request optimizations for the default pipeline!");
1254 
1255  ModulePassManager MPM(DebugLogging);
1256 
1257  // Force any function attributes we want the rest of the pipeline to observe.
1259 
1260  if (PGOOpt && PGOOpt->SamplePGOSupport)
1262 
1263  // Apply module pipeline start EP callback.
1264  for (auto &C : PipelineStartEPCallbacks)
1265  C(MPM);
1266 
1267  // If we are planning to perform ThinLTO later, we don't bloat the code with
1268  // unrolling/vectorization/... now. Just simplify the module as much as we
1269  // can.
1270  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
1271  DebugLogging));
1272 
1273  // Run partial inlining pass to partially inline functions that have
1274  // large bodies.
1275  // FIXME: It isn't clear whether this is really the right place to run this
1276  // in ThinLTO. Because there is another canonicalization and simplification
1277  // phase that will run after the thin link, running this here ends up with
1278  // less information than will be available later and it may grow functions in
1279  // ways that aren't beneficial.
1280  if (RunPartialInlining)
1281  MPM.addPass(PartialInlinerPass());
1282 
1283  // Reduce the size of the IR as much as possible.
1284  MPM.addPass(GlobalOptPass());
1285 
1286  // Module simplification splits coroutines, but does not fully clean up
1287  // coroutine intrinsics. To ensure ThinLTO optimization passes don't trip up
1288  // on these, we schedule the cleanup here.
1289  if (PTO.Coroutines)
1291 
1292  return MPM;
1293 }
1294 
1296  OptimizationLevel Level, bool DebugLogging,
1297  const ModuleSummaryIndex *ImportSummary) {
1298  ModulePassManager MPM(DebugLogging);
1299 
1300  if (ImportSummary) {
1301  // These passes import type identifier resolutions for whole-program
1302  // devirtualization and CFI. They must run early because other passes may
1303  // disturb the specific instruction patterns that these passes look for,
1304  // creating dependencies on resolutions that may not appear in the summary.
1305  //
1306  // For example, GVN may transform the pattern assume(type.test) appearing in
1307  // two basic blocks into assume(phi(type.test, type.test)), which would
1308  // transform a dependency on a WPD resolution into a dependency on a type
1309  // identifier resolution for CFI.
1310  //
1311  // Also, WPD has access to more precise information than ICP and can
1312  // devirtualize more effectively, so it should operate on the IR first.
1313  //
1314  // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1315  // metadata and intrinsics.
1316  MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary));
1317  MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary));
1318  }
1319 
1320  if (Level == OptimizationLevel::O0)
1321  return MPM;
1322 
1323  // Force any function attributes we want the rest of the pipeline to observe.
1325 
1326  // Add the core simplification pipeline.
1327  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
1328  DebugLogging));
1329 
1330  // Now add the optimization pipeline.
1331  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
1332 
1333  return MPM;
1334 }
1335 
1338  bool DebugLogging) {
1339  assert(Level != OptimizationLevel::O0 &&
1340  "Must request optimizations for the default pipeline!");
1341  // FIXME: We should use a customized pre-link pipeline!
1342  return buildPerModuleDefaultPipeline(Level, DebugLogging,
1343  /* LTOPreLink */ true);
1344 }
1345 
1348  ModuleSummaryIndex *ExportSummary) {
1349  ModulePassManager MPM(DebugLogging);
1350 
1351  if (Level == OptimizationLevel::O0) {
1352  // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1353  // metadata and intrinsics.
1354  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1355  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1356  return MPM;
1357  }
1358 
1359  if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
1360  // Load sample profile before running the LTO optimization pipeline.
1361  MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
1362  PGOOpt->ProfileRemappingFile,
1363  false /* ThinLTOPhase::PreLink */));
1364  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
1365  // RequireAnalysisPass for PSI before subsequent non-module passes.
1367  }
1368 
1369  // Remove unused virtual tables to improve the quality of code generated by
1370  // whole-program devirtualization and bitset lowering.
1371  MPM.addPass(GlobalDCEPass());
1372 
1373  // Force any function attributes we want the rest of the pipeline to observe.
1375 
1376  // Do basic inference of function attributes from known properties of system
1377  // libraries and other oracles.
1379 
1380  if (Level.getSpeedupLevel() > 1) {
1381  FunctionPassManager EarlyFPM(DebugLogging);
1382  EarlyFPM.addPass(CallSiteSplittingPass());
1383  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
1384 
1385  // Indirect call promotion. This should promote all the targets that are
1386  // left by the earlier promotion pass that promotes intra-module targets.
1387  // This two-step promotion is to save the compile time. For LTO, it should
1388  // produce the same result as if we only do promotion here.
1390  true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
1391  // Propagate constants at call sites into the functions they call. This
1392  // opens opportunities for globalopt (and inlining) by substituting function
1393  // pointers passed as arguments to direct uses of functions.
1394  MPM.addPass(IPSCCPPass());
1395 
1396  // Attach metadata to indirect call sites indicating the set of functions
1397  // they may target at run-time. This should follow IPSCCP.
1399  }
1400 
1401  // Now deduce any function attributes based in the current code.
1404 
1405  // Do RPO function attribute inference across the module to forward-propagate
1406  // attributes where applicable.
1407  // FIXME: Is this really an optimization rather than a canonicalization?
1409 
1410  // Use in-range annotations on GEP indices to split globals where beneficial.
1411  MPM.addPass(GlobalSplitPass());
1412 
1413  // Run whole program optimization of virtual call when the list of callees
1414  // is fixed.
1415  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1416 
1417  // Stop here at -O1.
1418  if (Level == OptimizationLevel::O1) {
1419  // The LowerTypeTestsPass needs to run to lower type metadata and the
1420  // type.test intrinsics. The pass does nothing if CFI is disabled.
1421  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1422  return MPM;
1423  }
1424 
1425  // Optimize globals to try and fold them into constants.
1426  MPM.addPass(GlobalOptPass());
1427 
1428  // Promote any localized globals to SSA registers.
1430 
1431  // Linking modules together can lead to duplicate global constant, only
1432  // keep one copy of each constant.
1433  MPM.addPass(ConstantMergePass());
1434 
1435  // Remove unused arguments from functions.
1437 
1438  // Reduce the code after globalopt and ipsccp. Both can open up significant
1439  // simplification opportunities, and both can propagate functions through
1440  // function pointers. When this happens, we often have to resolve varargs
1441  // calls, etc, so let instcombine do this.
1442  FunctionPassManager PeepholeFPM(DebugLogging);
1443  if (Level == OptimizationLevel::O3)
1444  PeepholeFPM.addPass(AggressiveInstCombinePass());
1445  PeepholeFPM.addPass(InstCombinePass());
1446  invokePeepholeEPCallbacks(PeepholeFPM, Level);
1447 
1448  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
1449 
1450  // Note: historically, the PruneEH pass was run first to deduce nounwind and
1451  // generally clean up exception handling overhead. It isn't clear this is
1452  // valuable as the inliner doesn't currently care whether it is inlining an
1453  // invoke or a call.
1454  // Run the inliner now.
1456  DebugLogging));
1457 
1458  // Optimize globals again after we ran the inliner.
1459  MPM.addPass(GlobalOptPass());
1460 
1461  // Garbage collect dead functions.
1462  // FIXME: Add ArgumentPromotion pass after once it's ported.
1463  MPM.addPass(GlobalDCEPass());
1464 
1465  FunctionPassManager FPM(DebugLogging);
1466  // The IPO Passes may leave cruft around. Clean up after them.
1467  FPM.addPass(InstCombinePass());
1468  invokePeepholeEPCallbacks(FPM, Level);
1469 
1470  FPM.addPass(JumpThreadingPass());
1471 
1472  // Do a post inline PGO instrumentation and use pass. This is a context
1473  // sensitive PGO pass.
1474  if (PGOOpt) {
1475  if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1476  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
1477  /* IsCS */ true, PGOOpt->CSProfileGenFile,
1478  PGOOpt->ProfileRemappingFile);
1479  else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1480  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
1481  /* IsCS */ true, PGOOpt->ProfileFile,
1482  PGOOpt->ProfileRemappingFile);
1483  }
1484 
1485  // Break up allocas
1486  FPM.addPass(SROA());
1487 
1488  // LTO provides additional opportunities for tailcall elimination due to
1489  // link-time inlining, and visibility of nocapture attribute.
1490  FPM.addPass(TailCallElimPass());
1491 
1492  // Run a few AA driver optimizations here and now to cleanup the code.
1493  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1494 
1497  // FIXME: here we run IP alias analysis in the legacy PM.
1498 
1499  FunctionPassManager MainFPM;
1500 
1501  // FIXME: once we fix LoopPass Manager, add LICM here.
1502  // FIXME: once we provide support for enabling MLSM, add it here.
1503  if (RunNewGVN)
1504  MainFPM.addPass(NewGVNPass());
1505  else
1506  MainFPM.addPass(GVN());
1507 
1508  // Remove dead memcpy()'s.
1509  MainFPM.addPass(MemCpyOptPass());
1510 
1511  // Nuke dead stores.
1512  MainFPM.addPass(DSEPass());
1513 
1514  // FIXME: at this point, we run a bunch of loop passes:
1515  // indVarSimplify, loopDeletion, loopInterchange, loopUnroll,
1516  // loopVectorize. Enable them once the remaining issue with LPM
1517  // are sorted out.
1518 
1519  MainFPM.addPass(InstCombinePass());
1520  MainFPM.addPass(SimplifyCFGPass());
1521  MainFPM.addPass(SCCPPass());
1522  MainFPM.addPass(InstCombinePass());
1523  MainFPM.addPass(BDCEPass());
1524 
1525  // FIXME: We may want to run SLPVectorizer here.
1526  // After vectorization, assume intrinsics may tell us more
1527  // about pointer alignments.
1528 #if 0
1529  MainFPM.add(AlignmentFromAssumptionsPass());
1530 #endif
1531 
1532  // FIXME: Conditionally run LoadCombine here, after it's ported
1533  // (in case we still have this pass, given its questionable usefulness).
1534 
1535  MainFPM.addPass(InstCombinePass());
1536  invokePeepholeEPCallbacks(MainFPM, Level);
1537  MainFPM.addPass(JumpThreadingPass());
1538  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
1539 
1540  // Create a function that performs CFI checks for cross-DSO calls with
1541  // targets in the current module.
1542  MPM.addPass(CrossDSOCFIPass());
1543 
1544  // Lower type metadata and the type.test intrinsic. This pass supports
1545  // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
1546  // to be run at link time if CFI is enabled. This pass does nothing if
1547  // CFI is disabled.
1548  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1549 
1550  // Enable splitting late in the FullLTO post-link pipeline. This is done in
1551  // the same stage in the old pass manager (\ref addLateLTOOptimizationPasses).
1552  if (EnableHotColdSplit)
1554 
1555  // Add late LTO optimization passes.
1556  // Delete basic blocks, which optimization passes may have killed.
1558 
1559  // Drop bodies of available eternally objects to improve GlobalDCE.
1561 
1562  // Now that we have optimized the program, discard unreachable functions.
1563  MPM.addPass(GlobalDCEPass());
1564 
1565  // FIXME: Maybe enable MergeFuncs conditionally after it's ported.
1566  return MPM;
1567 }
1568 
1570  AAManager AA;
1571 
1572  // The order in which these are registered determines their priority when
1573  // being queried.
1574 
1575  // First we register the basic alias analysis that provides the majority of
1576  // per-function local AA logic. This is a stateless, on-demand local set of
1577  // AA techniques.
1579 
1580  // Next we query fast, specialized alias analyses that wrap IR-embedded
1581  // information about aliasing.
1584 
1585  // Add support for querying global aliasing information when available.
1586  // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
1587  // analysis, all that the `AAManager` can do is query for any *cached*
1588  // results from `GlobalsAA` through a readonly proxy.
1590 
1591  return AA;
1592 }
1593 
1595  if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
1596  return None;
1597  int Count;
1598  if (Name.getAsInteger(0, Count) || Count <= 0)
1599  return None;
1600  return Count;
1601 }
1602 
1604  if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
1605  return None;
1606  int Count;
1607  if (Name.getAsInteger(0, Count) || Count <= 0)
1608  return None;
1609  return Count;
1610 }
1611 
1613  if (!Name.consume_front(PassName))
1614  return false;
1615  // normal pass name w/o parameters == default parameters
1616  if (Name.empty())
1617  return true;
1618  return Name.startswith("<") && Name.endswith(">");
1619 }
1620 
1621 namespace {
1622 
1623 /// This performs customized parsing of pass name with parameters.
1624 ///
1625 /// We do not need parametrization of passes in textual pipeline very often,
1626 /// yet on a rare occasion ability to specify parameters right there can be
1627 /// useful.
1628 ///
1629 /// \p Name - parameterized specification of a pass from a textual pipeline
1630 /// is a string in a form of :
1631 /// PassName '<' parameter-list '>'
1632 ///
1633 /// Parameter list is being parsed by the parser callable argument, \p Parser,
1634 /// It takes a string-ref of parameters and returns either StringError or a
1635 /// parameter list in a form of a custom parameters type, all wrapped into
1636 /// Expected<> template class.
1637 ///
1638 template <typename ParametersParseCallableT>
1639 auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
1640  StringRef PassName) -> decltype(Parser(StringRef{})) {
1641  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1642 
1643  StringRef Params = Name;
1644  if (!Params.consume_front(PassName)) {
1645  assert(false &&
1646  "unable to strip pass name from parametrized pass specification");
1647  }
1648  if (Params.empty())
1649  return ParametersT{};
1650  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1651  assert(false && "invalid format for parametrized pass name");
1652  }
1653 
1654  Expected<ParametersT> Result = Parser(Params);
1655  assert((Result || Result.template errorIsA<StringError>()) &&
1656  "Pass parameter parser can only return StringErrors.");
1657  return Result;
1658 }
1659 
1660 /// Parser of parameters for LoopUnroll pass.
1661 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
1662  LoopUnrollOptions UnrollOpts;
1663  while (!Params.empty()) {
1664  StringRef ParamName;
1665  std::tie(ParamName, Params) = Params.split(';');
1666  int OptLevel = StringSwitch<int>(ParamName)
1667  .Case("O0", 0)
1668  .Case("O1", 1)
1669  .Case("O2", 2)
1670  .Case("O3", 3)
1671  .Default(-1);
1672  if (OptLevel >= 0) {
1673  UnrollOpts.setOptLevel(OptLevel);
1674  continue;
1675  }
1676  if (ParamName.consume_front("full-unroll-max=")) {
1677  int Count;
1678  if (ParamName.getAsInteger(0, Count))
1679  return make_error<StringError>(
1680  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
1682  UnrollOpts.setFullUnrollMaxCount(Count);
1683  continue;
1684  }
1685 
1686  bool Enable = !ParamName.consume_front("no-");
1687  if (ParamName == "partial") {
1688  UnrollOpts.setPartial(Enable);
1689  } else if (ParamName == "peeling") {
1690  UnrollOpts.setPeeling(Enable);
1691  } else if (ParamName == "profile-peeling") {
1692  UnrollOpts.setProfileBasedPeeling(Enable);
1693  } else if (ParamName == "runtime") {
1694  UnrollOpts.setRuntime(Enable);
1695  } else if (ParamName == "upperbound") {
1696  UnrollOpts.setUpperBound(Enable);
1697  } else {
1698  return make_error<StringError>(
1699  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
1701  }
1702  }
1703  return UnrollOpts;
1704 }
1705 
1706 Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
1707  MemorySanitizerOptions Result;
1708  while (!Params.empty()) {
1709  StringRef ParamName;
1710  std::tie(ParamName, Params) = Params.split(';');
1711 
1712  if (ParamName == "recover") {
1713  Result.Recover = true;
1714  } else if (ParamName == "kernel") {
1715  Result.Kernel = true;
1716  } else if (ParamName.consume_front("track-origins=")) {
1717  if (ParamName.getAsInteger(0, Result.TrackOrigins))
1718  return make_error<StringError>(
1719  formatv("invalid argument to MemorySanitizer pass track-origins "
1720  "parameter: '{0}' ",
1721  ParamName)
1722  .str(),
1724  } else {
1725  return make_error<StringError>(
1726  formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
1727  .str(),
1729  }
1730  }
1731  return Result;
1732 }
1733 
1734 /// Parser of parameters for SimplifyCFG pass.
1735 Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
1736  SimplifyCFGOptions Result;
1737  while (!Params.empty()) {
1738  StringRef ParamName;
1739  std::tie(ParamName, Params) = Params.split(';');
1740 
1741  bool Enable = !ParamName.consume_front("no-");
1742  if (ParamName == "forward-switch-cond") {
1743  Result.forwardSwitchCondToPhi(Enable);
1744  } else if (ParamName == "switch-to-lookup") {
1745  Result.convertSwitchToLookupTable(Enable);
1746  } else if (ParamName == "keep-loops") {
1747  Result.needCanonicalLoops(Enable);
1748  } else if (ParamName == "sink-common-insts") {
1749  Result.sinkCommonInsts(Enable);
1750  } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
1751  APInt BonusInstThreshold;
1752  if (ParamName.getAsInteger(0, BonusInstThreshold))
1753  return make_error<StringError>(
1754  formatv("invalid argument to SimplifyCFG pass bonus-threshold "
1755  "parameter: '{0}' ",
1756  ParamName).str(),
1758  Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
1759  } else {
1760  return make_error<StringError>(
1761  formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
1763  }
1764  }
1765  return Result;
1766 }
1767 
1768 /// Parser of parameters for LoopVectorize pass.
1769 Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
1770  LoopVectorizeOptions Opts;
1771  while (!Params.empty()) {
1772  StringRef ParamName;
1773  std::tie(ParamName, Params) = Params.split(';');
1774 
1775  bool Enable = !ParamName.consume_front("no-");
1776  if (ParamName == "interleave-forced-only") {
1777  Opts.setInterleaveOnlyWhenForced(Enable);
1778  } else if (ParamName == "vectorize-forced-only") {
1779  Opts.setVectorizeOnlyWhenForced(Enable);
1780  } else {
1781  return make_error<StringError>(
1782  formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
1784  }
1785  }
1786  return Opts;
1787 }
1788 
1789 Expected<bool> parseLoopUnswitchOptions(StringRef Params) {
1790  bool Result = false;
1791  while (!Params.empty()) {
1792  StringRef ParamName;
1793  std::tie(ParamName, Params) = Params.split(';');
1794 
1795  bool Enable = !ParamName.consume_front("no-");
1796  if (ParamName == "nontrivial") {
1797  Result = Enable;
1798  } else {
1799  return make_error<StringError>(
1800  formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
1801  .str(),
1803  }
1804  }
1805  return Result;
1806 }
1807 
1808 Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
1809  bool Result = false;
1810  while (!Params.empty()) {
1811  StringRef ParamName;
1812  std::tie(ParamName, Params) = Params.split(';');
1813 
1814  bool Enable = !ParamName.consume_front("no-");
1815  if (ParamName == "split-footer-bb") {
1816  Result = Enable;
1817  } else {
1818  return make_error<StringError>(
1819  formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ",
1820  ParamName)
1821  .str(),
1823  }
1824  }
1825  return Result;
1826 }
1827 
1828 Expected<GVNOptions> parseGVNOptions(StringRef Params) {
1829  GVNOptions Result;
1830  while (!Params.empty()) {
1831  StringRef ParamName;
1832  std::tie(ParamName, Params) = Params.split(';');
1833 
1834  bool Enable = !ParamName.consume_front("no-");
1835  if (ParamName == "pre") {
1836  Result.setPRE(Enable);
1837  } else if (ParamName == "load-pre") {
1838  Result.setLoadPRE(Enable);
1839  } else if (ParamName == "memdep") {
1840  Result.setMemDep(Enable);
1841  } else {
1842  return make_error<StringError>(
1843  formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
1845  }
1846  }
1847  return Result;
1848 }
1849 
1851 parseStackLifetimeOptions(StringRef Params) {
1853  while (!Params.empty()) {
1854  StringRef ParamName;
1855  std::tie(ParamName, Params) = Params.split(';');
1856 
1857  if (ParamName == "may") {
1859  } else if (ParamName == "must") {
1861  } else {
1862  return make_error<StringError>(
1863  formatv("invalid StackLifetime parameter '{0}' ", ParamName).str(),
1865  }
1866  }
1867  return Result;
1868 }
1869 
1870 } // namespace
1871 
1872 /// Tests whether a pass name starts with a valid prefix for a default pipeline
1873 /// alias.
1875  return Name.startswith("default") || Name.startswith("thinlto") ||
1876  Name.startswith("lto");
1877 }
1878 
1879 /// Tests whether registered callbacks will accept a given pass name.
1880 ///
1881 /// When parsing a pipeline text, the type of the outermost pipeline may be
1882 /// omitted, in which case the type is automatically determined from the first
1883 /// pass name in the text. This may be a name that is handled through one of the
1884 /// callbacks. We check this through the oridinary parsing callbacks by setting
1885 /// up a dummy PassManager in order to not force the client to also handle this
1886 /// type of query.
1887 template <typename PassManagerT, typename CallbacksT>
1888 static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1889  if (!Callbacks.empty()) {
1890  PassManagerT DummyPM;
1891  for (auto &CB : Callbacks)
1892  if (CB(Name, DummyPM, {}))
1893  return true;
1894  }
1895  return false;
1896 }
1897 
1898 template <typename CallbacksT>
1899 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1900  // Manually handle aliases for pre-configured pipeline fragments.
1902  return DefaultAliasRegex.match(Name);
1903 
1904  // Explicitly handle pass manager names.
1905  if (Name == "module")
1906  return true;
1907  if (Name == "cgscc")
1908  return true;
1909  if (Name == "function")
1910  return true;
1911 
1912  // Explicitly handle custom-parsed pass names.
1913  if (parseRepeatPassName(Name))
1914  return true;
1915 
1916 #define MODULE_PASS(NAME, CREATE_PASS) \
1917  if (Name == NAME) \
1918  return true;
1919 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1920  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1921  return true;
1922 #include "PassRegistry.def"
1923 
1924  return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1925 }
1926 
1927 template <typename CallbacksT>
1928 static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1929  // Explicitly handle pass manager names.
1930  if (Name == "cgscc")
1931  return true;
1932  if (Name == "function")
1933  return true;
1934 
1935  // Explicitly handle custom-parsed pass names.
1936  if (parseRepeatPassName(Name))
1937  return true;
1938  if (parseDevirtPassName(Name))
1939  return true;
1940 
1941 #define CGSCC_PASS(NAME, CREATE_PASS) \
1942  if (Name == NAME) \
1943  return true;
1944 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1945  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1946  return true;
1947 #include "PassRegistry.def"
1948 
1949  return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1950 }
1951 
1952 template <typename CallbacksT>
1953 static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1954  // Explicitly handle pass manager names.
1955  if (Name == "function")
1956  return true;
1957  if (Name == "loop" || Name == "loop-mssa")
1958  return true;
1959 
1960  // Explicitly handle custom-parsed pass names.
1961  if (parseRepeatPassName(Name))
1962  return true;
1963 
1964 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1965  if (Name == NAME) \
1966  return true;
1967 #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1968  if (checkParametrizedPassName(Name, NAME)) \
1969  return true;
1970 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1971  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1972  return true;
1973 #include "PassRegistry.def"
1974 
1975  return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1976 }
1977 
1978 template <typename CallbacksT>
1979 static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
1980  // Explicitly handle pass manager names.
1981  if (Name == "loop" || Name == "loop-mssa")
1982  return true;
1983 
1984  // Explicitly handle custom-parsed pass names.
1985  if (parseRepeatPassName(Name))
1986  return true;
1987 
1988 #define LOOP_PASS(NAME, CREATE_PASS) \
1989  if (Name == NAME) \
1990  return true;
1991 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1992  if (checkParametrizedPassName(Name, NAME)) \
1993  return true;
1994 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1995  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1996  return true;
1997 #include "PassRegistry.def"
1998 
1999  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
2000 }
2001 
2003 PassBuilder::parsePipelineText(StringRef Text) {
2004  std::vector<PipelineElement> ResultPipeline;
2005 
2006  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
2007  &ResultPipeline};
2008  for (;;) {
2009  std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
2010  size_t Pos = Text.find_first_of(",()");
2011  Pipeline.push_back({Text.substr(0, Pos), {}});
2012 
2013  // If we have a single terminating name, we're done.
2014  if (Pos == Text.npos)
2015  break;
2016 
2017  char Sep = Text[Pos];
2018  Text = Text.substr(Pos + 1);
2019  if (Sep == ',')
2020  // Just a name ending in a comma, continue.
2021  continue;
2022 
2023  if (Sep == '(') {
2024  // Push the inner pipeline onto the stack to continue processing.
2025  PipelineStack.push_back(&Pipeline.back().InnerPipeline);
2026  continue;
2027  }
2028 
2029  assert(Sep == ')' && "Bogus separator!");
2030  // When handling the close parenthesis, we greedily consume them to avoid
2031  // empty strings in the pipeline.
2032  do {
2033  // If we try to pop the outer pipeline we have unbalanced parentheses.
2034  if (PipelineStack.size() == 1)
2035  return None;
2036 
2037  PipelineStack.pop_back();
2038  } while (Text.consume_front(")"));
2039 
2040  // Check if we've finished parsing.
2041  if (Text.empty())
2042  break;
2043 
2044  // Otherwise, the end of an inner pipeline always has to be followed by
2045  // a comma, and then we can continue.
2046  if (!Text.consume_front(","))
2047  return None;
2048  }
2049 
2050  if (PipelineStack.size() > 1)
2051  // Unbalanced paretheses.
2052  return None;
2053 
2054  assert(PipelineStack.back() == &ResultPipeline &&
2055  "Wrong pipeline at the bottom of the stack!");
2056  return {std::move(ResultPipeline)};
2057 }
2058 
2059 Error PassBuilder::parseModulePass(ModulePassManager &MPM,
2060  const PipelineElement &E,
2061  bool VerifyEachPass, bool DebugLogging) {
2062  auto &Name = E.Name;
2063  auto &InnerPipeline = E.InnerPipeline;
2064 
2065  // First handle complex passes like the pass managers which carry pipelines.
2066  if (!InnerPipeline.empty()) {
2067  if (Name == "module") {
2068  ModulePassManager NestedMPM(DebugLogging);
2069  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
2070  VerifyEachPass, DebugLogging))
2071  return Err;
2072  MPM.addPass(std::move(NestedMPM));
2073  return Error::success();
2074  }
2075  if (Name == "cgscc") {
2076  CGSCCPassManager CGPM(DebugLogging);
2077  if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
2078  DebugLogging))
2079  return Err;
2080  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
2081  return Error::success();
2082  }
2083  if (Name == "function") {
2084  FunctionPassManager FPM(DebugLogging);
2085  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
2086  VerifyEachPass, DebugLogging))
2087  return Err;
2088  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
2089  return Error::success();
2090  }
2091  if (auto Count = parseRepeatPassName(Name)) {
2092  ModulePassManager NestedMPM(DebugLogging);
2093  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
2094  VerifyEachPass, DebugLogging))
2095  return Err;
2096  MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
2097  return Error::success();
2098  }
2099 
2100  for (auto &C : ModulePipelineParsingCallbacks)
2101  if (C(Name, MPM, InnerPipeline))
2102  return Error::success();
2103 
2104  // Normal passes can't have pipelines.
2105  return make_error<StringError>(
2106  formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
2108  ;
2109  }
2110 
2111  // Manually handle aliases for pre-configured pipeline fragments.
2113  SmallVector<StringRef, 3> Matches;
2114  if (!DefaultAliasRegex.match(Name, &Matches))
2115  return make_error<StringError>(
2116  formatv("unknown default pipeline alias '{0}'", Name).str(),
2118 
2119  assert(Matches.size() == 3 && "Must capture two matched strings!");
2120 
2121  OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
2122  .Case("O0", OptimizationLevel::O0)
2123  .Case("O1", OptimizationLevel::O1)
2124  .Case("O2", OptimizationLevel::O2)
2125  .Case("O3", OptimizationLevel::O3)
2126  .Case("Os", OptimizationLevel::Os)
2127  .Case("Oz", OptimizationLevel::Oz);
2128  if (L == OptimizationLevel::O0) {
2129  // Add instrumentation PGO passes -- at O0 we can still do PGO.
2130  if (PGOOpt && Matches[1] != "thinlto" &&
2131  (PGOOpt->Action == PGOOptions::IRInstr ||
2132  PGOOpt->Action == PGOOptions::IRUse))
2133  addPGOInstrPassesForO0(
2134  MPM, DebugLogging,
2135  /* RunProfileGen */ (PGOOpt->Action == PGOOptions::IRInstr),
2136  /* IsCS */ false, PGOOpt->ProfileFile,
2137  PGOOpt->ProfileRemappingFile);
2138 
2139  // For IR that makes use of coroutines intrinsics, coroutine passes must
2140  // be run, even at -O0.
2141  if (PTO.Coroutines) {
2143 
2144  CGSCCPassManager CGPM(DebugLogging);
2145  CGPM.addPass(CoroSplitPass());
2147  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
2148 
2150  }
2151 
2152  // Do nothing else at all!
2153  return Error::success();
2154  }
2155 
2156  // This is consistent with old pass manager invoked via opt, but
2157  // inconsistent with clang. Clang doesn't enable loop vectorization
2158  // but does enable slp vectorization at Oz.
2159  PTO.LoopVectorization =
2160  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
2161  PTO.SLPVectorization =
2162  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
2163 
2164  if (Matches[1] == "default") {
2165  MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
2166  } else if (Matches[1] == "thinlto-pre-link") {
2167  MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
2168  } else if (Matches[1] == "thinlto") {
2169  MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr));
2170  } else if (Matches[1] == "lto-pre-link") {
2171  MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
2172  } else {
2173  assert(Matches[1] == "lto" && "Not one of the matched options!");
2174  MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr));
2175  }
2176  return Error::success();
2177  }
2178 
2179  // Finally expand the basic registered passes from the .inc file.
2180 #define MODULE_PASS(NAME, CREATE_PASS) \
2181  if (Name == NAME) { \
2182  MPM.addPass(CREATE_PASS); \
2183  return Error::success(); \
2184  }
2185 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
2186  if (Name == "require<" NAME ">") { \
2187  MPM.addPass( \
2188  RequireAnalysisPass< \
2189  std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
2190  return Error::success(); \
2191  } \
2192  if (Name == "invalidate<" NAME ">") { \
2193  MPM.addPass(InvalidateAnalysisPass< \
2194  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
2195  return Error::success(); \
2196  }
2197 #include "PassRegistry.def"
2198 
2199  for (auto &C : ModulePipelineParsingCallbacks)
2200  if (C(Name, MPM, InnerPipeline))
2201  return Error::success();
2202  return make_error<StringError>(
2203  formatv("unknown module pass '{0}'", Name).str(),
2205 }
2206 
2207 Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
2208  const PipelineElement &E, bool VerifyEachPass,
2209  bool DebugLogging) {
2210  auto &Name = E.Name;
2211  auto &InnerPipeline = E.InnerPipeline;
2212 
2213  // First handle complex passes like the pass managers which carry pipelines.
2214  if (!InnerPipeline.empty()) {
2215  if (Name == "cgscc") {
2216  CGSCCPassManager NestedCGPM(DebugLogging);
2217  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
2218  VerifyEachPass, DebugLogging))
2219  return Err;
2220  // Add the nested pass manager with the appropriate adaptor.
2221  CGPM.addPass(std::move(NestedCGPM));
2222  return Error::success();
2223  }
2224  if (Name == "function") {
2225  FunctionPassManager FPM(DebugLogging);
2226  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
2227  VerifyEachPass, DebugLogging))
2228  return Err;
2229  // Add the nested pass manager with the appropriate adaptor.
2230  CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
2231  return Error::success();
2232  }
2233  if (auto Count = parseRepeatPassName(Name)) {
2234  CGSCCPassManager NestedCGPM(DebugLogging);
2235  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
2236  VerifyEachPass, DebugLogging))
2237  return Err;
2238  CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
2239  return Error::success();
2240  }
2241  if (auto MaxRepetitions = parseDevirtPassName(Name)) {
2242  CGSCCPassManager NestedCGPM(DebugLogging);
2243  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
2244  VerifyEachPass, DebugLogging))
2245  return Err;
2246  CGPM.addPass(
2247  createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
2248  return Error::success();
2249  }
2250 
2251  for (auto &C : CGSCCPipelineParsingCallbacks)
2252  if (C(Name, CGPM, InnerPipeline))
2253  return Error::success();
2254 
2255  // Normal passes can't have pipelines.
2256  return make_error<StringError>(
2257  formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
2259  }
2260 
2261 // Now expand the basic registered passes from the .inc file.
2262 #define CGSCC_PASS(NAME, CREATE_PASS) \
2263  if (Name == NAME) { \
2264  CGPM.addPass(CREATE_PASS); \
2265  return Error::success(); \
2266  }
2267 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
2268  if (Name == "require<" NAME ">") { \
2269  CGPM.addPass(RequireAnalysisPass< \
2270  std::remove_reference<decltype(CREATE_PASS)>::type, \
2271  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
2272  CGSCCUpdateResult &>()); \
2273  return Error::success(); \
2274  } \
2275  if (Name == "invalidate<" NAME ">") { \
2276  CGPM.addPass(InvalidateAnalysisPass< \
2277  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
2278  return Error::success(); \
2279  }
2280 #include "PassRegistry.def"
2281 
2282  for (auto &C : CGSCCPipelineParsingCallbacks)
2283  if (C(Name, CGPM, InnerPipeline))
2284  return Error::success();
2285  return make_error<StringError>(
2286  formatv("unknown cgscc pass '{0}'", Name).str(),
2288 }
2289 
2290 Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
2291  const PipelineElement &E,
2292  bool VerifyEachPass, bool DebugLogging) {
2293  auto &Name = E.Name;
2294  auto &InnerPipeline = E.InnerPipeline;
2295 
2296  // First handle complex passes like the pass managers which carry pipelines.
2297  if (!InnerPipeline.empty()) {
2298  if (Name == "function") {
2299  FunctionPassManager NestedFPM(DebugLogging);
2300  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
2301  VerifyEachPass, DebugLogging))
2302  return Err;
2303  // Add the nested pass manager with the appropriate adaptor.
2304  FPM.addPass(std::move(NestedFPM));
2305  return Error::success();
2306  }
2307  if (Name == "loop" || Name == "loop-mssa") {
2308  LoopPassManager LPM(DebugLogging);
2309  if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
2310  DebugLogging))
2311  return Err;
2312  // Add the nested pass manager with the appropriate adaptor.
2313  bool UseMemorySSA = (Name == "loop-mssa");
2314  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
2315  DebugLogging));
2316  return Error::success();
2317  }
2318  if (auto Count = parseRepeatPassName(Name)) {
2319  FunctionPassManager NestedFPM(DebugLogging);
2320  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
2321  VerifyEachPass, DebugLogging))
2322  return Err;
2323  FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
2324  return Error::success();
2325  }
2326 
2327  for (auto &C : FunctionPipelineParsingCallbacks)
2328  if (C(Name, FPM, InnerPipeline))
2329  return Error::success();
2330 
2331  // Normal passes can't have pipelines.
2332  return make_error<StringError>(
2333  formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
2335  }
2336 
2337 // Now expand the basic registered passes from the .inc file.
2338 #define FUNCTION_PASS(NAME, CREATE_PASS) \
2339  if (Name == NAME) { \
2340  FPM.addPass(CREATE_PASS); \
2341  return Error::success(); \
2342  }
2343 #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
2344  if (checkParametrizedPassName(Name, NAME)) { \
2345  auto Params = parsePassParameters(PARSER, Name, NAME); \
2346  if (!Params) \
2347  return Params.takeError(); \
2348  FPM.addPass(CREATE_PASS(Params.get())); \
2349  return Error::success(); \
2350  }
2351 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
2352  if (Name == "require<" NAME ">") { \
2353  FPM.addPass( \
2354  RequireAnalysisPass< \
2355  std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
2356  return Error::success(); \
2357  } \
2358  if (Name == "invalidate<" NAME ">") { \
2359  FPM.addPass(InvalidateAnalysisPass< \
2360  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
2361  return Error::success(); \
2362  }
2363 #include "PassRegistry.def"
2364 
2365  for (auto &C : FunctionPipelineParsingCallbacks)
2366  if (C(Name, FPM, InnerPipeline))
2367  return Error::success();
2368  return make_error<StringError>(
2369  formatv("unknown function pass '{0}'", Name).str(),
2371 }
2372 
2373 Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
2374  bool VerifyEachPass, bool DebugLogging) {
2375  StringRef Name = E.Name;
2376  auto &InnerPipeline = E.InnerPipeline;
2377 
2378  // First handle complex passes like the pass managers which carry pipelines.
2379  if (!InnerPipeline.empty()) {
2380  if (Name == "loop") {
2381  LoopPassManager NestedLPM(DebugLogging);
2382  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2383  VerifyEachPass, DebugLogging))
2384  return Err;
2385  // Add the nested pass manager with the appropriate adaptor.
2386  LPM.addPass(std::move(NestedLPM));
2387  return Error::success();
2388  }
2389  if (auto Count = parseRepeatPassName(Name)) {
2390  LoopPassManager NestedLPM(DebugLogging);
2391  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2392  VerifyEachPass, DebugLogging))
2393  return Err;
2394  LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
2395  return Error::success();
2396  }
2397 
2398  for (auto &C : LoopPipelineParsingCallbacks)
2399  if (C(Name, LPM, InnerPipeline))
2400  return Error::success();
2401 
2402  // Normal passes can't have pipelines.
2403  return make_error<StringError>(
2404  formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
2406  }
2407 
2408 // Now expand the basic registered passes from the .inc file.
2409 #define LOOP_PASS(NAME, CREATE_PASS) \
2410  if (Name == NAME) { \
2411  LPM.addPass(CREATE_PASS); \
2412  return Error::success(); \
2413  }
2414 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
2415  if (checkParametrizedPassName(Name, NAME)) { \
2416  auto Params = parsePassParameters(PARSER, Name, NAME); \
2417  if (!Params) \
2418  return Params.takeError(); \
2419  LPM.addPass(CREATE_PASS(Params.get())); \
2420  return Error::success(); \
2421  }
2422 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
2423  if (Name == "require<" NAME ">") { \
2424  LPM.addPass(RequireAnalysisPass< \
2425  std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
2426  LoopAnalysisManager, LoopStandardAnalysisResults &, \
2427  LPMUpdater &>()); \
2428  return Error::success(); \
2429  } \
2430  if (Name == "invalidate<" NAME ">") { \
2431  LPM.addPass(InvalidateAnalysisPass< \
2432  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
2433  return Error::success(); \
2434  }
2435 #include "PassRegistry.def"
2436 
2437  for (auto &C : LoopPipelineParsingCallbacks)
2438  if (C(Name, LPM, InnerPipeline))
2439  return Error::success();
2440  return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
2442 }
2443 
2444 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
2445 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2446  if (Name == NAME) { \
2447  AA.registerModuleAnalysis< \
2448  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
2449  return true; \
2450  }
2451 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2452  if (Name == NAME) { \
2453  AA.registerFunctionAnalysis< \
2454  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
2455  return true; \
2456  }
2457 #include "PassRegistry.def"
2458 
2459  for (auto &C : AAParsingCallbacks)
2460  if (C(Name, AA))
2461  return true;
2462  return false;
2463 }
2464 
2465 Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2466  ArrayRef<PipelineElement> Pipeline,
2467  bool VerifyEachPass,
2468  bool DebugLogging) {
2469  for (const auto &Element : Pipeline) {
2470  if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
2471  return Err;
2472  // FIXME: No verifier support for Loop passes!
2473  }
2474  return Error::success();
2475 }
2476 
2477 Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
2478  ArrayRef<PipelineElement> Pipeline,
2479  bool VerifyEachPass,
2480  bool DebugLogging) {
2481  for (const auto &Element : Pipeline) {
2482  if (auto Err =
2483  parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
2484  return Err;
2485  if (VerifyEachPass)
2486  FPM.addPass(VerifierPass());
2487  }
2488  return Error::success();
2489 }
2490 
2491 Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2492  ArrayRef<PipelineElement> Pipeline,
2493  bool VerifyEachPass,
2494  bool DebugLogging) {
2495  for (const auto &Element : Pipeline) {
2496  if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
2497  return Err;
2498  // FIXME: No verifier support for CGSCC passes!
2499  }
2500  return Error::success();
2501 }
2502 
2505  CGSCCAnalysisManager &CGAM,
2506  ModuleAnalysisManager &MAM) {
2507  MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
2508  MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
2509  CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
2510  FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
2511  FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
2512  FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
2513  LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
2514 }
2515 
2516 Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2517  ArrayRef<PipelineElement> Pipeline,
2518  bool VerifyEachPass,
2519  bool DebugLogging) {
2520  for (const auto &Element : Pipeline) {
2521  if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
2522  return Err;
2523  if (VerifyEachPass)
2524  MPM.addPass(VerifierPass());
2525  }
2526  return Error::success();
2527 }
2528 
2529 // Primary pass pipeline description parsing routine for a \c ModulePassManager
2530 // FIXME: Should this routine accept a TargetMachine or require the caller to
2531 // pre-populate the analysis managers with target-specific stuff?
2533  StringRef PipelineText,
2534  bool VerifyEachPass, bool DebugLogging) {
2535  auto Pipeline = parsePipelineText(PipelineText);
2536  if (!Pipeline || Pipeline->empty())
2537  return make_error<StringError>(
2538  formatv("invalid pipeline '{0}'", PipelineText).str(),
2540 
2541  // If the first name isn't at the module layer, wrap the pipeline up
2542  // automatically.
2543  StringRef FirstName = Pipeline->front().Name;
2544 
2545  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2546  if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2547  Pipeline = {{"cgscc", std::move(*Pipeline)}};
2548  } else if (isFunctionPassName(FirstName,
2549  FunctionPipelineParsingCallbacks)) {
2550  Pipeline = {{"function", std::move(*Pipeline)}};
2551  } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) {
2552  Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
2553  } else {
2554  for (auto &C : TopLevelPipelineParsingCallbacks)
2555  if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2556  return Error::success();
2557 
2558  // Unknown pass or pipeline name!
2559  auto &InnerPipeline = Pipeline->front().InnerPipeline;
2560  return make_error<StringError>(
2561  formatv("unknown {0} name '{1}'",
2562  (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2563  .str(),
2565  }
2566  }
2567 
2568  if (auto Err =
2569  parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2570  return Err;
2571  return Error::success();
2572 }
2573 
2574 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2576  StringRef PipelineText,
2577  bool VerifyEachPass, bool DebugLogging) {
2578  auto Pipeline = parsePipelineText(PipelineText);
2579  if (!Pipeline || Pipeline->empty())
2580  return make_error<StringError>(
2581  formatv("invalid pipeline '{0}'", PipelineText).str(),
2583 
2584  StringRef FirstName = Pipeline->front().Name;
2585  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2586  return make_error<StringError>(
2587  formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
2588  PipelineText)
2589  .str(),
2591 
2592  if (auto Err =
2593  parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2594  return Err;
2595  return Error::success();
2596 }
2597 
2598 // Primary pass pipeline description parsing routine for a \c
2599 // FunctionPassManager
2601  StringRef PipelineText,
2602  bool VerifyEachPass, bool DebugLogging) {
2603  auto Pipeline = parsePipelineText(PipelineText);
2604  if (!Pipeline || Pipeline->empty())
2605  return make_error<StringError>(
2606  formatv("invalid pipeline '{0}'", PipelineText).str(),
2608 
2609  StringRef FirstName = Pipeline->front().Name;
2610  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2611  return make_error<StringError>(
2612  formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
2613  PipelineText)
2614  .str(),
2616 
2617  if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
2618  DebugLogging))
2619  return Err;
2620  return Error::success();
2621 }
2622 
2623 // Primary pass pipeline description parsing routine for a \c LoopPassManager
2625  StringRef PipelineText,
2626  bool VerifyEachPass, bool DebugLogging) {
2627  auto Pipeline = parsePipelineText(PipelineText);
2628  if (!Pipeline || Pipeline->empty())
2629  return make_error<StringError>(
2630  formatv("invalid pipeline '{0}'", PipelineText).str(),
2632 
2633  if (auto Err =
2634  parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2635  return Err;
2636 
2637  return Error::success();
2638 }
2639 
2641  // If the pipeline just consists of the word 'default' just replace the AA
2642  // manager with our default one.
2643  if (PipelineText == "default") {
2644  AA = buildDefaultAAPipeline();
2645  return Error::success();
2646  }
2647 
2648  while (!PipelineText.empty()) {
2649  StringRef Name;
2650  std::tie(Name, PipelineText) = PipelineText.split(',');
2651  if (!parseAAPassName(AA, Name))
2652  return make_error<StringError>(
2653  formatv("unknown alias analysis name '{0}'", Name).str(),
2655  }
2656 
2657  return Error::success();
2658 }
2659 
2661 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2662  if (PassName == NAME) \
2663  return true;
2664 #include "PassRegistry.def"
2665  return false;
2666 }
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Defines passes for running instruction simplification across chunks of IR.
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
const T & front() const
front - Get the first element.
Definition: ArrayRef.h:159
Analysis pass providing a never-invalidated alias analysis result.
static cl::opt< int > PreInlineThreshold("npm-preinline-threshold", cl::Hidden, cl::init(75), cl::ZeroOrMore, cl::desc("Control the amount of inlining in pre-instrumentation inliner " "(default = 75)"))
A set of parameters used to control various transforms performed by the LoopUnroll pass...
static cl::opt< bool > EnableCallGraphProfile("enable-npm-call-graph-profile", cl::init(true), cl::Hidden, cl::desc("Enable call graph profile pass for the new PM (default = on)"))
uint64_t CallInst * C
Computes function attributes in post-order over the call graph.
Definition: FunctionAttrs.h:50
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false, bool LTOPreLink=false)
Build a per-module default optimization pipeline.
A simple loop rotation transformation.
Definition: LoopRotation.h:23
A simple and fast domtree-based CSE pass.
Definition: EarlyCSE.h:30
The profile annotation (profile-instr-use) pass for IR based PGO.
Thresholds to tune inline cost analysis.
Definition: InlineCost.h:160
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:82
Interfaces for registering analysis passes, producing common pass manager configurations, and parsing of pass pipelines.
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Eliminate dead arguments (and return values) from functions.
LLVM_NODISCARD bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:300
This is the interface for LLVM&#39;s inclusion-based alias analysis implemented with CFL graph reachabili...
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static Optional< int > parseRepeatPassName(StringRef Name)
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
cl::opt< bool > ForgetSCEVInLoopUnroll
This is the interface for a simple mod/ref and alias analysis over globals.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
bool Coroutines
Tuning option to enable/disable coroutine intrinsic lowering.
Definition: PassBuilder.h:99
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
This is the interface to build a ModuleSummaryIndex for a module.
OpenMP optimizations pass.
Definition: OpenMPOpt.h:43
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:289
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition: GVN.h:357
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Performs basic CFG simplifications to assist other loop passes.
static const OptimizationLevel Os
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
Definition: PassBuilder.h:234
This file provides the interface for LLVM&#39;s Scalar Replacement of Aggregates pass.
This file implements a simple N^2 alias analysis accuracy evaluator.
InnerAnalysisManagerProxy< CGSCCAnalysisManager, Module > CGSCCAnalysisManagerModuleProxy
A proxy from a CGSCCAnalysisManager to a Module.
Implements a lazy call graph analysis and related passes for the new pass manager.
RepeatedPass< PassT > createRepeatedPass(int Count, PassT P)
Definition: PassManager.h:1375
This file implements the Loop Fusion pass.
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:683
This is the interface for a metadata-based scoped no-alias analysis.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:93
SimplifyCFGOptions & sinkCommonInsts(bool B)
Definition: Local.h:109
void registerModuleAnalysis()
Register a specific AA result.
LoopUnrollOptions & setFullUnrollMaxCount(unsigned O)
The instrumentation pass for recording function order.
ModulePassManager buildModuleOptimizationPipeline(OptimizationLevel Level, bool DebugLogging=false, bool LTOPreLink=false)
Construct the core LLVM module optimization pipeline.
LoopUnrollOptions & setUpperBound(bool UpperBound)
Enables or disables the use of trip count upper bound in loop unrolling.
ModuleToPostOrderCGSCCPassAdaptor< CGSCCPassT > createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
CGSCCToFunctionPassAdaptor< FunctionPassT > createCGSCCToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Pass to remove unused function declarations.
This file defines the interface for the loop nest analysis.
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
This file provides the interface for LLVM&#39;s PGO Instrumentation lowering pass.
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
F(f)
Loop unroll pass that only does full loop unrolling.
Loop unroll pass that will support both full and partial unrolling.
static const char * name
Pass to perform split of global variables.
Definition: GlobalSplit.h:26
This pass transforms loops that contain branches or switches on loop- invariant conditions to have mu...
A DCE pass that assumes instructions are dead until proven otherwise.
Definition: ADCE.h:31
static cl::opt< bool > EnableSyntheticCounts("enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run synthetic function entry count generation " "pass"))
A utility pass template to force an analysis result to be available.
Definition: PassManager.h:1287
static cl::opt< bool > EnableGVNHoist("enable-npm-gvn-hoist", cl::init(false), cl::Hidden, cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"))
Reassociate commutative expressions.
Definition: Reassociate.h:71
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
cl::opt< bool > EnableHotColdSplit
Optional< bool > EnableDeferral
Indicate whether we should allow inline deferral.
Definition: InlineCost.h:190
Run instruction simplification across each instruction in the function.
Pass to forward loads in a loop around the backedge to subsequent iterations.
SimplifyCFGOptions & forwardSwitchCondToPhi(bool B)
Definition: Local.h:97
static cl::opt< bool > EnablePGOInlineDeferral("enable-npm-pgo-inline-deferral", cl::init(true), cl::Hidden, cl::desc("Enable inline deferral during PGO"))
Flag to enable inline deferral during PGO.
A pass that transforms external global definitions into declarations.
This pass handles simple speculating of instructions around PHIs when doing so is profitable for a pa...
A simple and fast domtree-based GVN pass to hoist common expressions from sibling branches...
Definition: GVN.h:350
This is the interface for a SCEV-based alias analysis.
ModulePassManager buildModuleSimplificationPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the core LLVM module canonicalization and simplification pipeline.
A pass to do RPO deduction and propagation of function attributes.
Definition: FunctionAttrs.h:69
GVNOptions & setMemDep(bool MemDep)
Enables or disables use of MemDepAnalysis.
Definition: GVN.h:97
Optional< int > HintThreshold
Threshold to use for callees with inline hint.
Definition: InlineCost.h:165
Instrumentation based profiling lowering pass.
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:223
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:831
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
static cl::opt< bool > EnableGVNSink("enable-npm-gvn-sink", cl::init(false), cl::Hidden, cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"))
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1036
Hoist/decompose integer division and remainder instructions to enable CFG improvements and better cod...
Definition: DivRemPairs.h:23
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:612
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
static constexpr size_t npos
Definition: StringRef.h:59
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Optimize scalar/vector interactions in IR using target cost models.
Definition: VectorCombine.h:23
The instrumentation (profile-instr-gen) pass for IR based PGO.
Key
PAL metadata keys.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
The sample profiler data loader pass.
Definition: SampleProfile.h:25
This file provides the interface for IR based instrumentation passes ( (profile-gen, and profile-use).
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition: Regex.cpp:83
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1635
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks)
falkor hwpf fix Falkor HW Prefetch Fix Late Phase
This file provides the interface for a simple, fast CSE pass.
This file provides the interface for the GCOV style profiler pass.
Performs Loop Invariant Code Motion Pass.
Definition: LICM.h:46
The core GVN pass object.
Definition: GVN.h:107
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Pass to remove unused function declarations.
Definition: GlobalDCE.h:29
A lazily constructed view of the call graph of a module.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
A pass that does profile-guided sinking of instructions into loops.
Definition: LoopSink.h:33
void registerFunctionAnalysis()
Register a specific AA result.
cl::opt< bool > EnableOrderFileInstrumentation
This class implements a trivial dead store elimination.
SimplifyCFGOptions & convertSwitchToLookupTable(bool B)
Definition: Local.h:101
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Argument promotion pass.
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
LoopUnrollOptions & setPartial(bool Partial)
Enables or disables partial unrolling.
Pass to perform interprocedural constant propagation.
Definition: SCCP.h:30
A pass which infers function attributes from the names and signatures of function declarations in a m...
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:511
cl::opt< bool > FlattenedProfileUsed
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
static cl::opt< unsigned > MaxDevirtIterations("pm-max-devirt-iterations", cl::ReallyHidden, cl::init(4))
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
This is the interface for LLVM&#39;s unification-based alias analysis implemented with CFL graph reachabi...
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:434
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:154
This is the interface for a metadata-based TBAA.
ModuleToFunctionPassAdaptor< FunctionPassT > createModuleToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1271
void addPGOInstrPassesForO0(ModulePassManager &MPM, bool DebugLogging, bool RunProfileGen, bool IsCS, std::string ProfileFile, std::string ProfileRemappingFile)
Add PGOInstrumenation passes for O0 only.
bool isAAPassName(StringRef PassName)
Returns true if the pass name is the name of an alias analysis pass.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
This file provides the interface for LLVM&#39;s Global Value Numbering pass which eliminates fully redund...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:690
This file provides the primary interface to the instcombine pass.
FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the core LLVM function canonicalization and simplification pipeline.
A manager for alias analyses.
This pass attempts to minimize the number of assume without loosing any information.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level, bool DebugLogging=false)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:390
A set of parameters to control various transforms performed by GVN pass.
Definition: GVN.h:71
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition: PassBuilder.h:93
cl::opt< unsigned > SetLicmMssaOptCap
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
GVNOptions & setLoadPRE(bool LoadPRE)
Enables or disables PRE of loads in GVN.
Definition: GVN.h:86
Analysis pass providing a never-invalidated alias analysis result.
This file provides the interface for LLVM&#39;s Global Value Numbering pass.
ThinLTOPhase
ThinLTO phase.
Definition: PassBuilder.h:143
void addRequiredModuleAnalysis()
Allow adding module-level analyses benefiting the contained CGSCC passes.
Definition: Inliner.h:135
static cl::opt< bool > EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden, cl::desc("Enable control height reduction optimization (CHR)"))
DevirtSCCRepeatedPass< PassT > createDevirtSCCRepeatedPass(PassT Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
A simple loop rotation transformation.
LoopUnrollOptions & setProfileBasedPeeling(int O)
static const OptimizationLevel Oz
A very specialized mode that will optimize for code size at any and all costs.
Definition: PassBuilder.h:242
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks)
Tests whether registered callbacks will accept a given pass name.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:160
std::string InstrProfileOutput
Create a verifier pass.
Definition: Verifier.h:136
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
static cl::opt< bool > EnableUnrollAndJam("enable-npm-unroll-and-jam", cl::init(false), cl::Hidden, cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"))
This file provides the interface for LLVM&#39;s Loop Data Prefetching Pass.
Provides passes to inlining "always_inline" functions.
This file provides the primary interface to the aggressive instcombine pass.
LoopUnrollOptions & setOptLevel(int O)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
static const OptimizationLevel O0
Disable as many optimizations as possible.
Definition: PassBuilder.h:175
This header defines the LoopLoadEliminationPass object.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:332
bool LoopInterleaving
Tuning option to set loop interleaving on/off, set based on opt level.
Definition: PassBuilder.h:78
CGSCCPassManager & getPM()
Allow adding more CGSCC passes, besides inlining.
Definition: Inliner.h:132
LoopVectorizeOptions & setVectorizeOnlyWhenForced(bool Value)
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
static Optional< int > parseDevirtPassName(StringRef Name)
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:883
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:730
This pass performs &#39;jump threading&#39;, which looks at blocks that have multiple predecessors and multip...
Definition: JumpThreading.h:77
A pass to simplify and canonicalize the CFG of a function.
Definition: SimplifyCFG.h:29
static const Regex DefaultAliasRegex("^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$")
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:105
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText, bool VerifyEachPass=true, bool DebugLogging=false)
Parse a textual pass pipeline description into a ModulePassManager.
static InlineParams getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level)
PipelineTuningOptions()
Constructor sets pipeline tuning defaults based on cl::opts.
Module pass, wrapping the inliner pass.
Definition: Inliner.h:119
The instrumentation (profile-instr-gen) pass for IR based PGO.
This pass converts vector operations into scalar operations, in order to expose optimization opportun...
Class for arbitrary precision integers.
Definition: APInt.h:69
FunctionToLoopPassAdaptor< LoopPassT > createFunctionToLoopPassAdaptor(LoopPassT Pass, bool UseMemorySSA=false, bool DebugLogging=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
cl::opt< bool > EnableKnowledgeRetention
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA, in LICM.
Definition: PassBuilder.h:103
A pass that merges duplicate global constants into a single constant.
Definition: ConstantMerge.h:29
Analysis pass providing a never-invalidated alias analysis result.
bool LoopUnrolling
Tuning option to enable/disable loop unrolling. Its default value is true.
Definition: PassBuilder.h:89
Options for the frontend instrumentation based profiling pass.
This pass performs merges of loads and stores on both sides of a.
The indirect function call promotion pass.
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Definition: CommandLine.h:665
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
Analysis pass providing a never-invalidated alias analysis result.
LoopUnrollOptions & setRuntime(bool Runtime)
Enables or disables unrolling of loops with runtime trip count.
cl::opt< unsigned > SetLicmMssaNoAccForPromotionCap
static cl::opt< InliningAdvisorMode > UseInlineAdvisor("enable-ml-inliner", cl::init(InliningAdvisorMode::Default), cl::Hidden, cl::desc("Enable ML policy for inliner. Currently trained for -Oz only"), cl::values(clEnumValN(InliningAdvisorMode::Default, "default", "Heuristics-based inliner version."), clEnumValN(InliningAdvisorMode::Development, "development", "Use development mode (runtime-loadable model)."), clEnumValN(InliningAdvisorMode::Release, "release", "Use release mode (AOT-compiled model).")))
ThinLTO prelink (summary) phase.
cl::opt< bool > EnableMSSALoopDependency
Enables memory ssa as a dependency for loop passes.
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:516
static const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:208
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition: PassBuilder.h:107
Pass which forces specific function attributes into the IR, primarily as a debugging tool...
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:413
cl::opt< AttributorRunOption > AttributorRun
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
Pass to outline cold regions.
Provides passes for computing function attributes based on interprocedural analyses.
This file defines the interface for the loop cache analysis.
bool CallGraphProfile
Tuning option to enable/disable call graph profile.
Definition: PassBuilder.h:111
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1183
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:693
This header provides classes for managing passes over SCCs of the call graph.
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:191
This file defines passes to print out IR in various granularities.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name)
Tests whether a pass name starts with a valid prefix for a default pipeline alias.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the interface for LLVM&#39;s Call Graph Profile pass.
The profile size based optimization pass for memory intrinsics.
See the comments on JumpThreadingPass.
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:156
An SCC of the call graph.
Performs Loop Inst Simplify Pass.
The LoopVectorize Pass.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks)
PassManager< LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, CGSCCUpdateResult & > CGSCCPassManager
The CGSCC pass manager.
An optimization pass providing Scalar Replacement of Aggregates.
Definition: SROA.h:64
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
static cl::opt< bool > RunPartialInlining("enable-npm-partial-inlining", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run Partial inlinining pass"))
A set of parameters used to control the transforms in the SimplifyCFG pass.
Definition: Local.h:65
void addPass(PassT Pass)
Definition: PassManager.h:554
This pass exposes codegen information to IR-level passes.
This pass performs function-level constant propagation and merging.
Definition: SCCP.h:36
This header defines various interfaces for pass management in LLVM.
ModuleInlinerWrapperPass buildInlinerPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the module pipeline that performs inlining as well as the inlining-driven cleanups...
LoopUnrollOptions & setPeeling(bool Peeling)
Enables or disables loop peeling.
static cl::opt< bool > RunNewGVN("enable-npm-newgvn", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Run NewGVN instead of GVN"))
GVNOptions & setPRE(bool PRE)
Enables or disables PRE in GVN.
Definition: GVN.h:80
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:71
The header file for the LowerConstantIntrinsics pass as used by the new pass manager.
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:86
This file provides the interface for the sampled PGO loader pass.
Optional< int > HotCallSiteThreshold
Threshold to use when the callsite is considered hot.
Definition: InlineCost.h:177
int DefaultThreshold
The default threshold to start with for a callee.
Definition: InlineCost.h:162
Optimize globals that never have their address taken.
Definition: GlobalOpt.h:25
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:151
Performs Loop Idiom Recognize Pass.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
Level
Definition: Debugify.cpp:33
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks)