LLVM  9.0.0svn
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"
34 #include "llvm/Analysis/IVUsers.h"
38 #include "llvm/Analysis/LoopInfo.h"
56 #include "llvm/IR/Dominators.h"
58 #include "llvm/IR/PassManager.h"
60 #include "llvm/IR/Verifier.h"
61 #include "llvm/Support/Debug.h"
63 #include "llvm/Support/Regex.h"
175 
176 using namespace llvm;
177 
178 static cl::opt<unsigned> MaxDevirtIterations("pm-max-devirt-iterations",
180 static cl::opt<bool>
181  RunPartialInlining("enable-npm-partial-inlining", cl::init(false),
183  cl::desc("Run Partial inlinining pass"));
184 
185 static cl::opt<bool>
186  RunNewGVN("enable-npm-newgvn", cl::init(false),
188  cl::desc("Run NewGVN instead of GVN"));
189 
191  "enable-npm-gvn-hoist", cl::init(false), cl::Hidden,
192  cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
193 
195  "enable-npm-gvn-sink", cl::init(false), cl::Hidden,
196  cl::desc("Enable the GVN hoisting pass for the new PM (default = off)"));
197 
199  "enable-npm-unroll-and-jam", cl::init(false), cl::Hidden,
200  cl::desc("Enable the Unroll and Jam pass for the new PM (default = off)"));
201 
203  "enable-npm-synthetic-counts", cl::init(false), cl::Hidden, cl::ZeroOrMore,
204  cl::desc("Run synthetic function entry count generation "
205  "pass"));
206 
207 static Regex DefaultAliasRegex(
208  "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
209 
210 // This option is used in simplifying testing SampleFDO optimizations for
211 // profile loading.
212 static cl::opt<bool>
213  EnableCHR("enable-chr-npm", cl::init(true), cl::Hidden,
214  cl::desc("Enable control height reduction optimization (CHR)"));
215 
220  LoopUnrolling = true;
224 }
225 
228 
230 
232  switch (Level) {
233  case PassBuilder::O0:
234  case PassBuilder::O1:
235  case PassBuilder::O2:
236  case PassBuilder::O3:
237  return false;
238 
239  case PassBuilder::Os:
240  case PassBuilder::Oz:
241  return true;
242  }
243  llvm_unreachable("Invalid optimization level!");
244 }
245 
246 namespace {
247 
248 /// No-op module pass which does nothing.
249 struct NoOpModulePass {
251  return PreservedAnalyses::all();
252  }
253  static StringRef name() { return "NoOpModulePass"; }
254 };
255 
256 /// No-op module analysis.
257 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
259  static AnalysisKey Key;
260 
261 public:
262  struct Result {};
263  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
264  static StringRef name() { return "NoOpModuleAnalysis"; }
265 };
266 
267 /// No-op CGSCC pass which does nothing.
268 struct NoOpCGSCCPass {
271  return PreservedAnalyses::all();
272  }
273  static StringRef name() { return "NoOpCGSCCPass"; }
274 };
275 
276 /// No-op CGSCC analysis.
277 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
279  static AnalysisKey Key;
280 
281 public:
282  struct Result {};
284  return Result();
285  }
286  static StringRef name() { return "NoOpCGSCCAnalysis"; }
287 };
288 
289 /// No-op function pass which does nothing.
290 struct NoOpFunctionPass {
292  return PreservedAnalyses::all();
293  }
294  static StringRef name() { return "NoOpFunctionPass"; }
295 };
296 
297 /// No-op function analysis.
298 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
300  static AnalysisKey Key;
301 
302 public:
303  struct Result {};
304  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
305  static StringRef name() { return "NoOpFunctionAnalysis"; }
306 };
307 
308 /// No-op loop pass which does nothing.
309 struct NoOpLoopPass {
312  return PreservedAnalyses::all();
313  }
314  static StringRef name() { return "NoOpLoopPass"; }
315 };
316 
317 /// No-op loop analysis.
318 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
320  static AnalysisKey Key;
321 
322 public:
323  struct Result {};
325  return Result();
326  }
327  static StringRef name() { return "NoOpLoopAnalysis"; }
328 };
329 
334 
335 } // End anonymous namespace.
336 
337 void PassBuilder::invokePeepholeEPCallbacks(
339  for (auto &C : PeepholeEPCallbacks)
340  C(FPM, Level);
341 }
342 
344 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
345  MAM.registerPass([&] { return CREATE_PASS; });
346 #include "PassRegistry.def"
347 
348  for (auto &C : ModuleAnalysisRegistrationCallbacks)
349  C(MAM);
350 }
351 
353 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
354  CGAM.registerPass([&] { return CREATE_PASS; });
355 #include "PassRegistry.def"
356 
357  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
358  C(CGAM);
359 }
360 
362 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
363  FAM.registerPass([&] { return CREATE_PASS; });
364 #include "PassRegistry.def"
365 
366  for (auto &C : FunctionAnalysisRegistrationCallbacks)
367  C(FAM);
368 }
369 
371 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
372  LAM.registerPass([&] { return CREATE_PASS; });
373 #include "PassRegistry.def"
374 
375  for (auto &C : LoopAnalysisRegistrationCallbacks)
376  C(LAM);
377 }
378 
382  bool DebugLogging) {
383  assert(Level != O0 && "Must request optimizations!");
384  FunctionPassManager FPM(DebugLogging);
385 
386  // Form SSA out of local memory accesses after breaking apart aggregates into
387  // scalars.
388  FPM.addPass(SROA());
389 
390  // Catch trivial redundancies
391  FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
392 
393  // Hoisting of scalars and load expressions.
394  if (EnableGVNHoist)
395  FPM.addPass(GVNHoistPass());
396 
397  // Global value numbering based sinking.
398  if (EnableGVNSink) {
399  FPM.addPass(GVNSinkPass());
400  FPM.addPass(SimplifyCFGPass());
401  }
402 
403  // Speculative execution if the target has divergent branches; otherwise nop.
405 
406  // Optimize based on known information about branches, and cleanup afterward.
407  FPM.addPass(JumpThreadingPass());
409  FPM.addPass(SimplifyCFGPass());
410  if (Level == O3)
412  FPM.addPass(InstCombinePass());
413 
414  if (!isOptimizingForSize(Level))
416 
417  invokePeepholeEPCallbacks(FPM, Level);
418 
419  // For PGO use pipeline, try to optimize memory intrinsics such as memcpy
420  // using the size value profile. Don't perform this when optimizing for size.
421  if (PGOOpt && PGOOpt->Action == PGOOptions::IRUse &&
422  !isOptimizingForSize(Level))
423  FPM.addPass(PGOMemOPSizeOpt());
424 
425  FPM.addPass(TailCallElimPass());
426  FPM.addPass(SimplifyCFGPass());
427 
428  // Form canonically associated expression trees, and simplify the trees using
429  // basic mathematical properties. For example, this will form (nearly)
430  // minimal multiplication trees.
431  FPM.addPass(ReassociatePass());
432 
433  // Add the primary loop simplification pipeline.
434  // FIXME: Currently this is split into two loop pass pipelines because we run
435  // some function passes in between them. These can and should be removed
436  // and/or replaced by scheduling the loop pass equivalents in the correct
437  // positions. But those equivalent passes aren't powerful enough yet.
438  // Specifically, `SimplifyCFGPass` and `InstCombinePass` are currently still
439  // used. We have `LoopSimplifyCFGPass` which isn't yet powerful enough yet to
440  // fully replace `SimplifyCFGPass`, and the closest to the other we have is
441  // `LoopInstSimplify`.
442  LoopPassManager LPM1(DebugLogging), LPM2(DebugLogging);
443 
444  // Simplify the loop body. We do this initially to clean up after other loop
445  // passes run, either when iterating on a loop or on inner loops with
446  // implications on the outer loop.
447  LPM1.addPass(LoopInstSimplifyPass());
448  LPM1.addPass(LoopSimplifyCFGPass());
449 
450  // Rotate Loop - disable header duplication at -Oz
451  LPM1.addPass(LoopRotatePass(Level != Oz));
452  LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap));
453  LPM1.addPass(SimpleLoopUnswitchPass());
454  LPM2.addPass(IndVarSimplifyPass());
456 
457  for (auto &C : LateLoopOptimizationsEPCallbacks)
458  C(LPM2, Level);
459 
460  LPM2.addPass(LoopDeletionPass());
461  // Do not enable unrolling in PreLinkThinLTO phase during sample PGO
462  // because it changes IR to makes profile annotation in back compile
463  // inaccurate.
464  if ((Phase != ThinLTOPhase::PreLink || !PGOOpt ||
465  PGOOpt->Action != PGOOptions::SampleUse) &&
466  PTO.LoopUnrolling)
467  LPM2.addPass(
468  LoopFullUnrollPass(Level, false, PTO.ForgetAllSCEVInLoopUnroll));
469 
470  for (auto &C : LoopOptimizerEndEPCallbacks)
471  C(LPM2, Level);
472 
473  // We provide the opt remark emitter pass for LICM to use. We only need to do
474  // this once as it is immutable.
476  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM1), DebugLogging));
477  FPM.addPass(SimplifyCFGPass());
478  FPM.addPass(InstCombinePass());
479  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM2), DebugLogging));
480 
481  // Eliminate redundancies.
482  if (Level != O1) {
483  // These passes add substantial compile time so skip them at O1.
485  if (RunNewGVN)
486  FPM.addPass(NewGVNPass());
487  else
488  FPM.addPass(GVN());
489  }
490 
491  // Specially optimize memory movement as it doesn't look like dataflow in SSA.
492  FPM.addPass(MemCpyOptPass());
493 
494  // Sparse conditional constant propagation.
495  // FIXME: It isn't clear why we do this *after* loop passes rather than
496  // before...
497  FPM.addPass(SCCPPass());
498 
499  // Delete dead bit computations (instcombine runs after to fold away the dead
500  // computations, and then ADCE will run later to exploit any new DCE
501  // opportunities that creates).
502  FPM.addPass(BDCEPass());
503 
504  // Run instcombine after redundancy and dead bit elimination to exploit
505  // opportunities opened up by them.
506  FPM.addPass(InstCombinePass());
507  invokePeepholeEPCallbacks(FPM, Level);
508 
509  // Re-consider control flow based optimizations after redundancy elimination,
510  // redo DCE, etc.
511  FPM.addPass(JumpThreadingPass());
513  FPM.addPass(DSEPass());
515  LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
516  DebugLogging));
517 
518  for (auto &C : ScalarOptimizerLateEPCallbacks)
519  C(FPM, Level);
520 
521  // Finally, do an expensive DCE pass to catch all the dead code exposed by
522  // the simplifications and basic cleanup after all the simplifications.
523  FPM.addPass(ADCEPass());
524  FPM.addPass(SimplifyCFGPass());
525  FPM.addPass(InstCombinePass());
526  invokePeepholeEPCallbacks(FPM, Level);
527 
528  if (EnableCHR && Level == O3 && PGOOpt &&
529  (PGOOpt->Action == PGOOptions::IRUse ||
530  PGOOpt->Action == PGOOptions::SampleUse))
532 
533  return FPM;
534 }
535 
536 void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
538  bool RunProfileGen, bool IsCS,
539  std::string ProfileFile,
540  std::string ProfileRemappingFile) {
541  // Generally running simplification passes and the inliner with an high
542  // threshold results in smaller executables, but there may be cases where
543  // the size grows, so let's be conservative here and skip this simplification
544  // at -Os/Oz. We will not do this inline for context sensistive PGO (when
545  // IsCS is true).
546  if (!isOptimizingForSize(Level) && !IsCS) {
547  InlineParams IP;
548 
549  // In the old pass manager, this is a cl::opt. Should still this be one?
550  IP.DefaultThreshold = 75;
551 
552  // FIXME: The hint threshold has the same value used by the regular inliner.
553  // This should probably be lowered after performance testing.
554  // FIXME: this comment is cargo culted from the old pass manager, revisit).
555  IP.HintThreshold = 325;
556 
557  CGSCCPassManager CGPipeline(DebugLogging);
558 
559  CGPipeline.addPass(InlinerPass(IP));
560 
562  FPM.addPass(SROA());
563  FPM.addPass(EarlyCSEPass()); // Catch trivial redundancies.
564  FPM.addPass(SimplifyCFGPass()); // Merge & remove basic blocks.
565  FPM.addPass(InstCombinePass()); // Combine silly sequences.
566  invokePeepholeEPCallbacks(FPM, Level);
567 
568  CGPipeline.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
569 
570  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPipeline)));
571  }
572 
573  // Delete anything that is now dead to make sure that we don't instrument
574  // dead code. Instrumentation can end up keeping dead code around and
575  // dramatically increase code size.
576  MPM.addPass(GlobalDCEPass());
577 
578  if (RunProfileGen) {
579  MPM.addPass(PGOInstrumentationGen(IsCS));
580 
582  FPM.addPass(
584  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
585 
586  // Add the profile lowering pass.
587  InstrProfOptions Options;
588  if (!ProfileFile.empty())
589  Options.InstrProfileOutput = ProfileFile;
590  Options.DoCounterPromotion = true;
591  Options.UseBFIInPromotion = IsCS;
592  MPM.addPass(InstrProfiling(Options, IsCS));
593  } else if (!ProfileFile.empty()) {
594  MPM.addPass(PGOInstrumentationUse(ProfileFile, ProfileRemappingFile, IsCS));
595  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
596  // RequireAnalysisPass for PSI before subsequent non-module passes.
598  }
599 }
600 
601 static InlineParams
603  auto O3 = PassBuilder::O3;
604  unsigned OptLevel = Level > O3 ? 2 : Level;
605  unsigned SizeLevel = Level > O3 ? Level - O3 : 0;
606  return getInlineParams(OptLevel, SizeLevel);
607 }
608 
612  bool DebugLogging) {
613  ModulePassManager MPM(DebugLogging);
614 
615  bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
616 
617  // In ThinLTO mode, when flattened profile is used, all the available
618  // profile information will be annotated in PreLink phase so there is
619  // no need to load the profile again in PostLink.
620  bool LoadSampleProfile =
621  HasSampleProfile &&
622  !(FlattenedProfileUsed && Phase == ThinLTOPhase::PostLink);
623 
624  // During the ThinLTO backend phase we perform early indirect call promotion
625  // here, before globalopt. Otherwise imported available_externally functions
626  // look unreferenced and are removed. If we are going to load the sample
627  // profile then defer until later.
628  // TODO: See if we can move later and consolidate with the location where
629  // we perform ICP when we are loading a sample profile.
630  // TODO: We pass HasSampleProfile (whether there was a sample profile file
631  // passed to the compile) to the SamplePGO flag of ICP. This is used to
632  // determine whether the new direct calls are annotated with prof metadata.
633  // Ideally this should be determined from whether the IR is annotated with
634  // sample profile, and not whether the a sample profile was provided on the
635  // command line. E.g. for flattened profiles where we will not be reloading
636  // the sample profile in the ThinLTO backend, we ideally shouldn't have to
637  // provide the sample profile file.
638  if (Phase == ThinLTOPhase::PostLink && !LoadSampleProfile)
639  MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile));
640 
641  // Do basic inference of function attributes from known properties of system
642  // libraries and other oracles.
644 
645  // Create an early function pass manager to cleanup the output of the
646  // frontend.
647  FunctionPassManager EarlyFPM(DebugLogging);
648  EarlyFPM.addPass(SimplifyCFGPass());
649  EarlyFPM.addPass(SROA());
650  EarlyFPM.addPass(EarlyCSEPass());
651  EarlyFPM.addPass(LowerExpectIntrinsicPass());
652  if (Level == O3)
653  EarlyFPM.addPass(CallSiteSplittingPass());
654 
655  // In SamplePGO ThinLTO backend, we need instcombine before profile annotation
656  // to convert bitcast to direct calls so that they can be inlined during the
657  // profile annotation prepration step.
658  // More details about SamplePGO design can be found in:
659  // https://research.google.com/pubs/pub45290.html
660  // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured.
661  if (LoadSampleProfile)
662  EarlyFPM.addPass(InstCombinePass());
663  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
664 
665  if (LoadSampleProfile) {
666  // Annotate sample profile right after early FPM to ensure freshness of
667  // the debug info.
668  MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
669  PGOOpt->ProfileRemappingFile,
670  Phase == ThinLTOPhase::PreLink));
671  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
672  // RequireAnalysisPass for PSI before subsequent non-module passes.
674  // Do not invoke ICP in the ThinLTOPrelink phase as it makes it hard
675  // for the profile annotation to be accurate in the ThinLTO backend.
676  if (Phase != ThinLTOPhase::PreLink)
677  // We perform early indirect call promotion here, before globalopt.
678  // This is important for the ThinLTO backend phase because otherwise
679  // imported available_externally functions look unreferenced and are
680  // removed.
681  MPM.addPass(PGOIndirectCallPromotion(Phase == ThinLTOPhase::PostLink,
682  true /* SamplePGO */));
683  }
684 
685  // Interprocedural constant propagation now that basic cleanup has occurred
686  // and prior to optimizing globals.
687  // FIXME: This position in the pipeline hasn't been carefully considered in
688  // years, it should be re-analyzed.
689  MPM.addPass(IPSCCPPass());
690 
691  // Attach metadata to indirect call sites indicating the set of functions
692  // they may target at run-time. This should follow IPSCCP.
694 
695  // Optimize globals to try and fold them into constants.
696  MPM.addPass(GlobalOptPass());
697 
698  // Promote any localized globals to SSA registers.
699  // FIXME: Should this instead by a run of SROA?
700  // FIXME: We should probably run instcombine and simplify-cfg afterward to
701  // delete control flows that are dead once globals have been folded to
702  // constants.
704 
705  // Remove any dead arguments exposed by cleanups and constand folding
706  // globals.
708 
709  // Create a small function pass pipeline to cleanup after all the global
710  // optimizations.
711  FunctionPassManager GlobalCleanupPM(DebugLogging);
712  GlobalCleanupPM.addPass(InstCombinePass());
713  invokePeepholeEPCallbacks(GlobalCleanupPM, Level);
714 
715  GlobalCleanupPM.addPass(SimplifyCFGPass());
716  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(GlobalCleanupPM)));
717 
718  // Add all the requested passes for instrumentation PGO, if requested.
719  if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
720  (PGOOpt->Action == PGOOptions::IRInstr ||
721  PGOOpt->Action == PGOOptions::IRUse)) {
722  addPGOInstrPasses(MPM, DebugLogging, Level,
723  /* RunProfileGen */ PGOOpt->Action == PGOOptions::IRInstr,
724  /* IsCS */ false, PGOOpt->ProfileFile,
725  PGOOpt->ProfileRemappingFile);
726  MPM.addPass(PGOIndirectCallPromotion(false, false));
727  }
728  if (PGOOpt && Phase != ThinLTOPhase::PostLink &&
729  PGOOpt->CSAction == PGOOptions::CSIRInstr)
730  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->CSProfileGenFile));
731 
732  // Synthesize function entry counts for non-PGO compilation.
733  if (EnableSyntheticCounts && !PGOOpt)
735 
736  // Require the GlobalsAA analysis for the module so we can query it within
737  // the CGSCC pipeline.
739 
740  // Require the ProfileSummaryAnalysis for the module so we can query it within
741  // the inliner pass.
743 
744  // Now begin the main postorder CGSCC pipeline.
745  // FIXME: The current CGSCC pipeline has its origins in the legacy pass
746  // manager and trying to emulate its precise behavior. Much of this doesn't
747  // make a lot of sense and we should revisit the core CGSCC structure.
748  CGSCCPassManager MainCGPipeline(DebugLogging);
749 
750  // Note: historically, the PruneEH pass was run first to deduce nounwind and
751  // generally clean up exception handling overhead. It isn't clear this is
752  // valuable as the inliner doesn't currently care whether it is inlining an
753  // invoke or a call.
754 
755  // Run the inliner first. The theory is that we are walking bottom-up and so
756  // the callees have already been fully optimized, and we want to inline them
757  // into the callers so that our optimizations can reflect that.
758  // For PreLinkThinLTO pass, we disable hot-caller heuristic for sample PGO
759  // because it makes profile annotation in the backend inaccurate.
761  if (Phase == ThinLTOPhase::PreLink && PGOOpt &&
762  PGOOpt->Action == PGOOptions::SampleUse)
763  IP.HotCallSiteThreshold = 0;
764  MainCGPipeline.addPass(InlinerPass(IP));
765 
766  // Now deduce any function attributes based in the current code.
767  MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
768 
769  // When at O3 add argument promotion to the pass pipeline.
770  // FIXME: It isn't at all clear why this should be limited to O3.
771  if (Level == O3)
772  MainCGPipeline.addPass(ArgumentPromotionPass());
773 
774  // Lastly, add the core function simplification pipeline nested inside the
775  // CGSCC walk.
777  buildFunctionSimplificationPipeline(Level, Phase, DebugLogging)));
778 
779  for (auto &C : CGSCCOptimizerLateEPCallbacks)
780  C(MainCGPipeline, Level);
781 
782  // We wrap the CGSCC pipeline in a devirtualization repeater. This will try
783  // to detect when we devirtualize indirect calls and iterate the SCC passes
784  // in that case to try and catch knock-on inlining or function attrs
785  // opportunities. Then we add it to the module pipeline by walking the SCCs
786  // in postorder (or bottom-up).
787  MPM.addPass(
789  std::move(MainCGPipeline), MaxDevirtIterations)));
790 
791  return MPM;
792 }
793 
795  OptimizationLevel Level, bool DebugLogging, bool LTOPreLink) {
796  ModulePassManager MPM(DebugLogging);
797 
798  // Optimize globals now that the module is fully simplified.
799  MPM.addPass(GlobalOptPass());
800  MPM.addPass(GlobalDCEPass());
801 
802  // Run partial inlining pass to partially inline functions that have
803  // large bodies.
804  if (RunPartialInlining)
806 
807  // Remove avail extern fns and globals definitions since we aren't compiling
808  // an object file for later LTO. For LTO we want to preserve these so they
809  // are eligible for inlining at link-time. Note if they are unreferenced they
810  // will be removed by GlobalDCE later, so this only impacts referenced
811  // available externally globals. Eventually they will be suppressed during
812  // codegen, but eliminating here enables more opportunity for GlobalDCE as it
813  // may make globals referenced by available external functions dead and saves
814  // running remaining passes on the eliminated functions.
816 
817  if (EnableOrderFileInstrumentation)
819 
820  // Do RPO function attribute inference across the module to forward-propagate
821  // attributes where applicable.
822  // FIXME: Is this really an optimization rather than a canonicalization?
824 
825  // Do a post inline PGO instrumentation and use pass. This is a context
826  // sensitive PGO pass. We don't want to do this in LTOPreLink phrase as
827  // cross-module inline has not been done yet. The context sensitive
828  // instrumentation is after all the inlines are done.
829  if (!LTOPreLink && PGOOpt) {
830  if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
831  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
832  /* IsCS */ true, PGOOpt->CSProfileGenFile,
833  PGOOpt->ProfileRemappingFile);
834  else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
835  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
836  /* IsCS */ true, PGOOpt->ProfileFile,
837  PGOOpt->ProfileRemappingFile);
838  }
839 
840  // Re-require GloblasAA here prior to function passes. This is particularly
841  // useful as the above will have inlined, DCE'ed, and function-attr
842  // propagated everything. We should at this point have a reasonably minimal
843  // and richly annotated call graph. By computing aliasing and mod/ref
844  // information for all local globals here, the late loop passes and notably
845  // the vectorizer will be able to use them to help recognize vectorizable
846  // memory operations.
848 
849  FunctionPassManager OptimizePM(DebugLogging);
850  OptimizePM.addPass(Float2IntPass());
851  // FIXME: We need to run some loop optimizations to re-rotate loops after
852  // simplify-cfg and others undo their rotation.
853 
854  // Optimize the loop execution. These passes operate on entire loop nests
855  // rather than on each loop in an inside-out manner, and so they are actually
856  // function passes.
857 
858  for (auto &C : VectorizerStartEPCallbacks)
859  C(OptimizePM, Level);
860 
861  // First rotate loops that may have been un-rotated by prior passes.
862  OptimizePM.addPass(
864 
865  // Distribute loops to allow partial vectorization. I.e. isolate dependences
866  // into separate loop that would otherwise inhibit vectorization. This is
867  // currently only performed for loops marked with the metadata
868  // llvm.loop.distribute=true or when -enable-loop-distribute is specified.
869  OptimizePM.addPass(LoopDistributePass());
870 
871  // Now run the core loop vectorizer.
872  OptimizePM.addPass(LoopVectorizePass(
873  LoopVectorizeOptions(!PTO.LoopInterleaving, !PTO.LoopVectorization)));
874 
875  // Eliminate loads by forwarding stores from the previous iteration to loads
876  // of the current iteration.
877  OptimizePM.addPass(LoopLoadEliminationPass());
878 
879  // Cleanup after the loop optimization passes.
880  OptimizePM.addPass(InstCombinePass());
881 
882  // Now that we've formed fast to execute loop structures, we do further
883  // optimizations. These are run afterward as they might block doing complex
884  // analyses and transforms such as what are needed for loop vectorization.
885 
886  // Cleanup after loop vectorization, etc. Simplification passes like CVP and
887  // GVN, loop transforms, and others have already run, so it's now better to
888  // convert to more optimized IR using more aggressive simplify CFG options.
889  // The extra sinking transform can create larger basic blocks, so do this
890  // before SLP vectorization.
892  forwardSwitchCondToPhi(true).
893  convertSwitchToLookupTable(true).
894  needCanonicalLoops(false).
895  sinkCommonInsts(true)));
896 
897  // Optimize parallel scalar instruction chains into SIMD instructions.
898  if (PTO.SLPVectorization)
899  OptimizePM.addPass(SLPVectorizerPass());
900 
901  OptimizePM.addPass(InstCombinePass());
902 
903  // Unroll small loops to hide loop backedge latency and saturate any parallel
904  // execution resources of an out-of-order processor. We also then need to
905  // clean up redundancies and loop invariant code.
906  // FIXME: It would be really good to use a loop-integrated instruction
907  // combiner for cleanup here so that the unrolling and LICM can be pipelined
908  // across the loop nests.
909  // We do UnrollAndJam in a separate LPM to ensure it happens before unroll
910  if (EnableUnrollAndJam) {
911  OptimizePM.addPass(
913  }
914  if (PTO.LoopUnrolling)
915  OptimizePM.addPass(LoopUnrollPass(
916  LoopUnrollOptions(Level, false, PTO.ForgetAllSCEVInLoopUnroll)));
918  OptimizePM.addPass(InstCombinePass());
921  LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap),
922  DebugLogging));
923 
924  // Now that we've vectorized and unrolled loops, we may have more refined
925  // alignment information, try to re-derive it here.
927 
928  // Split out cold code. Splitting is done late to avoid hiding context from
929  // other optimizations and inadvertently regressing performance. The tradeoff
930  // is that this has a higher code size cost than splitting early.
931  if (EnableHotColdSplit && !LTOPreLink)
933 
934  // LoopSink pass sinks instructions hoisted by LICM, which serves as a
935  // canonicalization pass that enables other optimizations. As a result,
936  // LoopSink pass needs to be a very late IR pass to avoid undoing LICM
937  // result too early.
938  OptimizePM.addPass(LoopSinkPass());
939 
940  // And finally clean up LCSSA form before generating code.
941  OptimizePM.addPass(InstSimplifyPass());
942 
943  // This hoists/decomposes div/rem ops. It should run after other sink/hoist
944  // passes to avoid re-sinking, but before SimplifyCFG because it can allow
945  // flattening of blocks.
946  OptimizePM.addPass(DivRemPairsPass());
947 
948  // LoopSink (and other loop passes since the last simplifyCFG) might have
949  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
950  OptimizePM.addPass(SimplifyCFGPass());
951 
952  // Optimize PHIs by speculating around them when profitable. Note that this
953  // pass needs to be run after any PRE or similar pass as it is essentially
954  // inserting redundancies into the program. This even includes SimplifyCFG.
955  OptimizePM.addPass(SpeculateAroundPHIsPass());
956 
957  for (auto &C : OptimizerLastEPCallbacks)
958  C(OptimizePM, Level);
959 
960  // Add the core optimizing pipeline.
961  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM)));
962 
963  MPM.addPass(CGProfilePass());
964 
965  // Now we need to do some global optimization transforms.
966  // FIXME: It would seem like these should come first in the optimization
967  // pipeline and maybe be the bottom of the canonicalization pipeline? Weird
968  // ordering here.
969  MPM.addPass(GlobalDCEPass());
970  MPM.addPass(ConstantMergePass());
971 
972  return MPM;
973 }
974 
977  bool DebugLogging, bool LTOPreLink) {
978  assert(Level != O0 && "Must request optimizations for the default pipeline!");
979 
980  ModulePassManager MPM(DebugLogging);
981 
982  // Force any function attributes we want the rest of the pipeline to observe.
984 
985  // Apply module pipeline start EP callback.
986  for (auto &C : PipelineStartEPCallbacks)
987  C(MPM);
988 
989  if (PGOOpt && PGOOpt->SamplePGOSupport)
991 
992  // Add the core simplification pipeline.
993  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::None,
994  DebugLogging));
995 
996  // Now add the optimization pipeline.
997  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging, LTOPreLink));
998 
999  return MPM;
1000 }
1001 
1004  bool DebugLogging) {
1005  assert(Level != O0 && "Must request optimizations for the default pipeline!");
1006 
1007  ModulePassManager MPM(DebugLogging);
1008 
1009  // Force any function attributes we want the rest of the pipeline to observe.
1011 
1012  if (PGOOpt && PGOOpt->SamplePGOSupport)
1014 
1015  // Apply module pipeline start EP callback.
1016  for (auto &C : PipelineStartEPCallbacks)
1017  C(MPM);
1018 
1019  // If we are planning to perform ThinLTO later, we don't bloat the code with
1020  // unrolling/vectorization/... now. Just simplify the module as much as we
1021  // can.
1022  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PreLink,
1023  DebugLogging));
1024 
1025  // Run partial inlining pass to partially inline functions that have
1026  // large bodies.
1027  // FIXME: It isn't clear whether this is really the right place to run this
1028  // in ThinLTO. Because there is another canonicalization and simplification
1029  // phase that will run after the thin link, running this here ends up with
1030  // less information than will be available later and it may grow functions in
1031  // ways that aren't beneficial.
1032  if (RunPartialInlining)
1033  MPM.addPass(PartialInlinerPass());
1034 
1035  // Reduce the size of the IR as much as possible.
1036  MPM.addPass(GlobalOptPass());
1037 
1038  return MPM;
1039 }
1040 
1042  OptimizationLevel Level, bool DebugLogging,
1043  const ModuleSummaryIndex *ImportSummary) {
1044  ModulePassManager MPM(DebugLogging);
1045 
1046  if (ImportSummary) {
1047  // These passes import type identifier resolutions for whole-program
1048  // devirtualization and CFI. They must run early because other passes may
1049  // disturb the specific instruction patterns that these passes look for,
1050  // creating dependencies on resolutions that may not appear in the summary.
1051  //
1052  // For example, GVN may transform the pattern assume(type.test) appearing in
1053  // two basic blocks into assume(phi(type.test, type.test)), which would
1054  // transform a dependency on a WPD resolution into a dependency on a type
1055  // identifier resolution for CFI.
1056  //
1057  // Also, WPD has access to more precise information than ICP and can
1058  // devirtualize more effectively, so it should operate on the IR first.
1059  //
1060  // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1061  // metadata and intrinsics.
1062  MPM.addPass(WholeProgramDevirtPass(nullptr, ImportSummary));
1063  MPM.addPass(LowerTypeTestsPass(nullptr, ImportSummary));
1064  }
1065 
1066  if (Level == O0)
1067  return MPM;
1068 
1069  // Force any function attributes we want the rest of the pipeline to observe.
1071 
1072  // Add the core simplification pipeline.
1073  MPM.addPass(buildModuleSimplificationPipeline(Level, ThinLTOPhase::PostLink,
1074  DebugLogging));
1075 
1076  // Now add the optimization pipeline.
1077  MPM.addPass(buildModuleOptimizationPipeline(Level, DebugLogging));
1078 
1079  return MPM;
1080 }
1081 
1084  bool DebugLogging) {
1085  assert(Level != O0 && "Must request optimizations for the default pipeline!");
1086  // FIXME: We should use a customized pre-link pipeline!
1087  return buildPerModuleDefaultPipeline(Level, DebugLogging,
1088  /* LTOPreLink */true);
1089 }
1090 
1093  ModuleSummaryIndex *ExportSummary) {
1094  ModulePassManager MPM(DebugLogging);
1095 
1096  if (Level == O0) {
1097  // The WPD and LowerTypeTest passes need to run at -O0 to lower type
1098  // metadata and intrinsics.
1099  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1100  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1101  return MPM;
1102  }
1103 
1104  if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) {
1105  // Load sample profile before running the LTO optimization pipeline.
1106  MPM.addPass(SampleProfileLoaderPass(PGOOpt->ProfileFile,
1107  PGOOpt->ProfileRemappingFile,
1108  false /* ThinLTOPhase::PreLink */));
1109  // Cache ProfileSummaryAnalysis once to avoid the potential need to insert
1110  // RequireAnalysisPass for PSI before subsequent non-module passes.
1112  }
1113 
1114  // Remove unused virtual tables to improve the quality of code generated by
1115  // whole-program devirtualization and bitset lowering.
1116  MPM.addPass(GlobalDCEPass());
1117 
1118  // Force any function attributes we want the rest of the pipeline to observe.
1120 
1121  // Do basic inference of function attributes from known properties of system
1122  // libraries and other oracles.
1124 
1125  if (Level > 1) {
1126  FunctionPassManager EarlyFPM(DebugLogging);
1127  EarlyFPM.addPass(CallSiteSplittingPass());
1128  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM)));
1129 
1130  // Indirect call promotion. This should promote all the targets that are
1131  // left by the earlier promotion pass that promotes intra-module targets.
1132  // This two-step promotion is to save the compile time. For LTO, it should
1133  // produce the same result as if we only do promotion here.
1135  true /* InLTO */, PGOOpt && PGOOpt->Action == PGOOptions::SampleUse));
1136  // Propagate constants at call sites into the functions they call. This
1137  // opens opportunities for globalopt (and inlining) by substituting function
1138  // pointers passed as arguments to direct uses of functions.
1139  MPM.addPass(IPSCCPPass());
1140 
1141  // Attach metadata to indirect call sites indicating the set of functions
1142  // they may target at run-time. This should follow IPSCCP.
1144  }
1145 
1146  // Now deduce any function attributes based in the current code.
1149 
1150  // Do RPO function attribute inference across the module to forward-propagate
1151  // attributes where applicable.
1152  // FIXME: Is this really an optimization rather than a canonicalization?
1154 
1155  // Use in-range annotations on GEP indices to split globals where beneficial.
1156  MPM.addPass(GlobalSplitPass());
1157 
1158  // Run whole program optimization of virtual call when the list of callees
1159  // is fixed.
1160  MPM.addPass(WholeProgramDevirtPass(ExportSummary, nullptr));
1161 
1162  // Stop here at -O1.
1163  if (Level == 1) {
1164  // The LowerTypeTestsPass needs to run to lower type metadata and the
1165  // type.test intrinsics. The pass does nothing if CFI is disabled.
1166  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1167  return MPM;
1168  }
1169 
1170  // Optimize globals to try and fold them into constants.
1171  MPM.addPass(GlobalOptPass());
1172 
1173  // Promote any localized globals to SSA registers.
1175 
1176  // Linking modules together can lead to duplicate global constant, only
1177  // keep one copy of each constant.
1178  MPM.addPass(ConstantMergePass());
1179 
1180  // Remove unused arguments from functions.
1182 
1183  // Reduce the code after globalopt and ipsccp. Both can open up significant
1184  // simplification opportunities, and both can propagate functions through
1185  // function pointers. When this happens, we often have to resolve varargs
1186  // calls, etc, so let instcombine do this.
1187  FunctionPassManager PeepholeFPM(DebugLogging);
1188  if (Level == O3)
1189  PeepholeFPM.addPass(AggressiveInstCombinePass());
1190  PeepholeFPM.addPass(InstCombinePass());
1191  invokePeepholeEPCallbacks(PeepholeFPM, Level);
1192 
1193  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(PeepholeFPM)));
1194 
1195  // Note: historically, the PruneEH pass was run first to deduce nounwind and
1196  // generally clean up exception handling overhead. It isn't clear this is
1197  // valuable as the inliner doesn't currently care whether it is inlining an
1198  // invoke or a call.
1199  // Run the inliner now.
1202 
1203  // Optimize globals again after we ran the inliner.
1204  MPM.addPass(GlobalOptPass());
1205 
1206  // Garbage collect dead functions.
1207  // FIXME: Add ArgumentPromotion pass after once it's ported.
1208  MPM.addPass(GlobalDCEPass());
1209 
1210  FunctionPassManager FPM(DebugLogging);
1211  // The IPO Passes may leave cruft around. Clean up after them.
1212  FPM.addPass(InstCombinePass());
1213  invokePeepholeEPCallbacks(FPM, Level);
1214 
1215  FPM.addPass(JumpThreadingPass());
1216 
1217  // Do a post inline PGO instrumentation and use pass. This is a context
1218  // sensitive PGO pass.
1219  if (PGOOpt) {
1220  if (PGOOpt->CSAction == PGOOptions::CSIRInstr)
1221  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ true,
1222  /* IsCS */ true, PGOOpt->CSProfileGenFile,
1223  PGOOpt->ProfileRemappingFile);
1224  else if (PGOOpt->CSAction == PGOOptions::CSIRUse)
1225  addPGOInstrPasses(MPM, DebugLogging, Level, /* RunProfileGen */ false,
1226  /* IsCS */ true, PGOOpt->ProfileFile,
1227  PGOOpt->ProfileRemappingFile);
1228  }
1229 
1230  // Break up allocas
1231  FPM.addPass(SROA());
1232 
1233  // LTO provides additional opportunities for tailcall elimination due to
1234  // link-time inlining, and visibility of nocapture attribute.
1235  FPM.addPass(TailCallElimPass());
1236 
1237  // Run a few AA driver optimizations here and now to cleanup the code.
1238  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1239 
1242  // FIXME: here we run IP alias analysis in the legacy PM.
1243 
1244  FunctionPassManager MainFPM;
1245 
1246  // FIXME: once we fix LoopPass Manager, add LICM here.
1247  // FIXME: once we provide support for enabling MLSM, add it here.
1248  if (RunNewGVN)
1249  MainFPM.addPass(NewGVNPass());
1250  else
1251  MainFPM.addPass(GVN());
1252 
1253  // Remove dead memcpy()'s.
1254  MainFPM.addPass(MemCpyOptPass());
1255 
1256  // Nuke dead stores.
1257  MainFPM.addPass(DSEPass());
1258 
1259  // FIXME: at this point, we run a bunch of loop passes:
1260  // indVarSimplify, loopDeletion, loopInterchange, loopUnroll,
1261  // loopVectorize. Enable them once the remaining issue with LPM
1262  // are sorted out.
1263 
1264  MainFPM.addPass(InstCombinePass());
1265  MainFPM.addPass(SimplifyCFGPass());
1266  MainFPM.addPass(SCCPPass());
1267  MainFPM.addPass(InstCombinePass());
1268  MainFPM.addPass(BDCEPass());
1269 
1270  // FIXME: We may want to run SLPVectorizer here.
1271  // After vectorization, assume intrinsics may tell us more
1272  // about pointer alignments.
1273 #if 0
1274  MainFPM.add(AlignmentFromAssumptionsPass());
1275 #endif
1276 
1277  // FIXME: Conditionally run LoadCombine here, after it's ported
1278  // (in case we still have this pass, given its questionable usefulness).
1279 
1280  MainFPM.addPass(InstCombinePass());
1281  invokePeepholeEPCallbacks(MainFPM, Level);
1282  MainFPM.addPass(JumpThreadingPass());
1283  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(MainFPM)));
1284 
1285  // Create a function that performs CFI checks for cross-DSO calls with
1286  // targets in the current module.
1287  MPM.addPass(CrossDSOCFIPass());
1288 
1289  // Lower type metadata and the type.test intrinsic. This pass supports
1290  // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs
1291  // to be run at link time if CFI is enabled. This pass does nothing if
1292  // CFI is disabled.
1293  MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr));
1294 
1295  // Enable splitting late in the FullLTO post-link pipeline. This is done in
1296  // the same stage in the old pass manager (\ref addLateLTOOptimizationPasses).
1297  if (EnableHotColdSplit)
1299 
1300  // Add late LTO optimization passes.
1301  // Delete basic blocks, which optimization passes may have killed.
1303 
1304  // Drop bodies of available eternally objects to improve GlobalDCE.
1306 
1307  // Now that we have optimized the program, discard unreachable functions.
1308  MPM.addPass(GlobalDCEPass());
1309 
1310  // FIXME: Maybe enable MergeFuncs conditionally after it's ported.
1311  return MPM;
1312 }
1313 
1315  AAManager AA;
1316 
1317  // The order in which these are registered determines their priority when
1318  // being queried.
1319 
1320  // First we register the basic alias analysis that provides the majority of
1321  // per-function local AA logic. This is a stateless, on-demand local set of
1322  // AA techniques.
1324 
1325  // Next we query fast, specialized alias analyses that wrap IR-embedded
1326  // information about aliasing.
1329 
1330  // Add support for querying global aliasing information when available.
1331  // Because the `AAManager` is a function analysis and `GlobalsAA` is a module
1332  // analysis, all that the `AAManager` can do is query for any *cached*
1333  // results from `GlobalsAA` through a readonly proxy.
1335 
1336  return AA;
1337 }
1338 
1340  if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
1341  return None;
1342  int Count;
1343  if (Name.getAsInteger(0, Count) || Count <= 0)
1344  return None;
1345  return Count;
1346 }
1347 
1349  if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
1350  return None;
1351  int Count;
1352  if (Name.getAsInteger(0, Count) || Count <= 0)
1353  return None;
1354  return Count;
1355 }
1356 
1358  if (!Name.consume_front(PassName))
1359  return false;
1360  // normal pass name w/o parameters == default parameters
1361  if (Name.empty())
1362  return true;
1363  return Name.startswith("<") && Name.endswith(">");
1364 }
1365 
1366 namespace {
1367 
1368 /// This performs customized parsing of pass name with parameters.
1369 ///
1370 /// We do not need parametrization of passes in textual pipeline very often,
1371 /// yet on a rare occasion ability to specify parameters right there can be
1372 /// useful.
1373 ///
1374 /// \p Name - parameterized specification of a pass from a textual pipeline
1375 /// is a string in a form of :
1376 /// PassName '<' parameter-list '>'
1377 ///
1378 /// Parameter list is being parsed by the parser callable argument, \p Parser,
1379 /// It takes a string-ref of parameters and returns either StringError or a
1380 /// parameter list in a form of a custom parameters type, all wrapped into
1381 /// Expected<> template class.
1382 ///
1383 template <typename ParametersParseCallableT>
1384 auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
1385  StringRef PassName) -> decltype(Parser(StringRef{})) {
1386  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
1387 
1388  StringRef Params = Name;
1389  if (!Params.consume_front(PassName)) {
1390  assert(false &&
1391  "unable to strip pass name from parametrized pass specification");
1392  }
1393  if (Params.empty())
1394  return ParametersT{};
1395  if (!Params.consume_front("<") || !Params.consume_back(">")) {
1396  assert(false && "invalid format for parametrized pass name");
1397  }
1398 
1399  Expected<ParametersT> Result = Parser(Params);
1400  assert((Result || Result.template errorIsA<StringError>()) &&
1401  "Pass parameter parser can only return StringErrors.");
1402  return std::move(Result);
1403 }
1404 
1405 /// Parser of parameters for LoopUnroll pass.
1406 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
1407  LoopUnrollOptions UnrollOpts;
1408  while (!Params.empty()) {
1409  StringRef ParamName;
1410  std::tie(ParamName, Params) = Params.split(';');
1411  int OptLevel = StringSwitch<int>(ParamName)
1412  .Case("O0", 0)
1413  .Case("O1", 1)
1414  .Case("O2", 2)
1415  .Case("O3", 3)
1416  .Default(-1);
1417  if (OptLevel >= 0) {
1418  UnrollOpts.setOptLevel(OptLevel);
1419  continue;
1420  }
1421 
1422  bool Enable = !ParamName.consume_front("no-");
1423  if (ParamName == "partial") {
1424  UnrollOpts.setPartial(Enable);
1425  } else if (ParamName == "peeling") {
1426  UnrollOpts.setPeeling(Enable);
1427  } else if (ParamName == "runtime") {
1428  UnrollOpts.setRuntime(Enable);
1429  } else if (ParamName == "upperbound") {
1430  UnrollOpts.setUpperBound(Enable);
1431  } else {
1432  return make_error<StringError>(
1433  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
1435  }
1436  }
1437  return UnrollOpts;
1438 }
1439 
1440 Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
1441  MemorySanitizerOptions Result;
1442  while (!Params.empty()) {
1443  StringRef ParamName;
1444  std::tie(ParamName, Params) = Params.split(';');
1445 
1446  if (ParamName == "recover") {
1447  Result.Recover = true;
1448  } else if (ParamName == "kernel") {
1449  Result.Kernel = true;
1450  } else if (ParamName.consume_front("track-origins=")) {
1451  if (ParamName.getAsInteger(0, Result.TrackOrigins))
1452  return make_error<StringError>(
1453  formatv("invalid argument to MemorySanitizer pass track-origins "
1454  "parameter: '{0}' ",
1455  ParamName)
1456  .str(),
1458  } else {
1459  return make_error<StringError>(
1460  formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
1461  .str(),
1463  }
1464  }
1465  return Result;
1466 }
1467 
1468 /// Parser of parameters for SimplifyCFG pass.
1469 Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
1470  SimplifyCFGOptions Result;
1471  while (!Params.empty()) {
1472  StringRef ParamName;
1473  std::tie(ParamName, Params) = Params.split(';');
1474 
1475  bool Enable = !ParamName.consume_front("no-");
1476  if (ParamName == "forward-switch-cond") {
1477  Result.forwardSwitchCondToPhi(Enable);
1478  } else if (ParamName == "switch-to-lookup") {
1479  Result.convertSwitchToLookupTable(Enable);
1480  } else if (ParamName == "keep-loops") {
1481  Result.needCanonicalLoops(Enable);
1482  } else if (ParamName == "sink-common-insts") {
1483  Result.sinkCommonInsts(Enable);
1484  } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
1485  APInt BonusInstThreshold;
1486  if (ParamName.getAsInteger(0, BonusInstThreshold))
1487  return make_error<StringError>(
1488  formatv("invalid argument to SimplifyCFG pass bonus-threshold "
1489  "parameter: '{0}' ",
1490  ParamName).str(),
1492  Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
1493  } else {
1494  return make_error<StringError>(
1495  formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
1497  }
1498  }
1499  return Result;
1500 }
1501 
1502 /// Parser of parameters for LoopVectorize pass.
1503 Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
1504  LoopVectorizeOptions Opts;
1505  while (!Params.empty()) {
1506  StringRef ParamName;
1507  std::tie(ParamName, Params) = Params.split(';');
1508 
1509  bool Enable = !ParamName.consume_front("no-");
1510  if (ParamName == "interleave-forced-only") {
1511  Opts.setInterleaveOnlyWhenForced(Enable);
1512  } else if (ParamName == "vectorize-forced-only") {
1513  Opts.setVectorizeOnlyWhenForced(Enable);
1514  } else {
1515  return make_error<StringError>(
1516  formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
1518  }
1519  }
1520  return Opts;
1521 }
1522 
1523 Expected<bool> parseLoopUnswitchOptions(StringRef Params) {
1524  bool Result = false;
1525  while (!Params.empty()) {
1526  StringRef ParamName;
1527  std::tie(ParamName, Params) = Params.split(';');
1528 
1529  bool Enable = !ParamName.consume_front("no-");
1530  if (ParamName == "nontrivial") {
1531  Result = Enable;
1532  } else {
1533  return make_error<StringError>(
1534  formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
1535  .str(),
1537  }
1538  }
1539  return Result;
1540 }
1541 } // namespace
1542 
1543 /// Tests whether a pass name starts with a valid prefix for a default pipeline
1544 /// alias.
1546  return Name.startswith("default") || Name.startswith("thinlto") ||
1547  Name.startswith("lto");
1548 }
1549 
1550 /// Tests whether registered callbacks will accept a given pass name.
1551 ///
1552 /// When parsing a pipeline text, the type of the outermost pipeline may be
1553 /// omitted, in which case the type is automatically determined from the first
1554 /// pass name in the text. This may be a name that is handled through one of the
1555 /// callbacks. We check this through the oridinary parsing callbacks by setting
1556 /// up a dummy PassManager in order to not force the client to also handle this
1557 /// type of query.
1558 template <typename PassManagerT, typename CallbacksT>
1559 static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1560  if (!Callbacks.empty()) {
1561  PassManagerT DummyPM;
1562  for (auto &CB : Callbacks)
1563  if (CB(Name, DummyPM, {}))
1564  return true;
1565  }
1566  return false;
1567 }
1568 
1569 template <typename CallbacksT>
1570 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1571  // Manually handle aliases for pre-configured pipeline fragments.
1573  return DefaultAliasRegex.match(Name);
1574 
1575  // Explicitly handle pass manager names.
1576  if (Name == "module")
1577  return true;
1578  if (Name == "cgscc")
1579  return true;
1580  if (Name == "function")
1581  return true;
1582 
1583  // Explicitly handle custom-parsed pass names.
1584  if (parseRepeatPassName(Name))
1585  return true;
1586 
1587 #define MODULE_PASS(NAME, CREATE_PASS) \
1588  if (Name == NAME) \
1589  return true;
1590 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1591  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1592  return true;
1593 #include "PassRegistry.def"
1594 
1595  return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1596 }
1597 
1598 template <typename CallbacksT>
1599 static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1600  // Explicitly handle pass manager names.
1601  if (Name == "cgscc")
1602  return true;
1603  if (Name == "function")
1604  return true;
1605 
1606  // Explicitly handle custom-parsed pass names.
1607  if (parseRepeatPassName(Name))
1608  return true;
1609  if (parseDevirtPassName(Name))
1610  return true;
1611 
1612 #define CGSCC_PASS(NAME, CREATE_PASS) \
1613  if (Name == NAME) \
1614  return true;
1615 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1616  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1617  return true;
1618 #include "PassRegistry.def"
1619 
1620  return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1621 }
1622 
1623 template <typename CallbacksT>
1624 static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1625  // Explicitly handle pass manager names.
1626  if (Name == "function")
1627  return true;
1628  if (Name == "loop")
1629  return true;
1630 
1631  // Explicitly handle custom-parsed pass names.
1632  if (parseRepeatPassName(Name))
1633  return true;
1634 
1635 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1636  if (Name == NAME) \
1637  return true;
1638 #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1639  if (checkParametrizedPassName(Name, NAME)) \
1640  return true;
1641 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1642  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1643  return true;
1644 #include "PassRegistry.def"
1645 
1646  return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1647 }
1648 
1649 template <typename CallbacksT>
1650 static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks) {
1651  // Explicitly handle pass manager names.
1652  if (Name == "loop")
1653  return true;
1654 
1655  // Explicitly handle custom-parsed pass names.
1656  if (parseRepeatPassName(Name))
1657  return true;
1658 
1659 #define LOOP_PASS(NAME, CREATE_PASS) \
1660  if (Name == NAME) \
1661  return true;
1662 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1663  if (checkParametrizedPassName(Name, NAME)) \
1664  return true;
1665 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1666  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1667  return true;
1668 #include "PassRegistry.def"
1669 
1670  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1671 }
1672 
1674 PassBuilder::parsePipelineText(StringRef Text) {
1675  std::vector<PipelineElement> ResultPipeline;
1676 
1677  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1678  &ResultPipeline};
1679  for (;;) {
1680  std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1681  size_t Pos = Text.find_first_of(",()");
1682  Pipeline.push_back({Text.substr(0, Pos), {}});
1683 
1684  // If we have a single terminating name, we're done.
1685  if (Pos == Text.npos)
1686  break;
1687 
1688  char Sep = Text[Pos];
1689  Text = Text.substr(Pos + 1);
1690  if (Sep == ',')
1691  // Just a name ending in a comma, continue.
1692  continue;
1693 
1694  if (Sep == '(') {
1695  // Push the inner pipeline onto the stack to continue processing.
1696  PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1697  continue;
1698  }
1699 
1700  assert(Sep == ')' && "Bogus separator!");
1701  // When handling the close parenthesis, we greedily consume them to avoid
1702  // empty strings in the pipeline.
1703  do {
1704  // If we try to pop the outer pipeline we have unbalanced parentheses.
1705  if (PipelineStack.size() == 1)
1706  return None;
1707 
1708  PipelineStack.pop_back();
1709  } while (Text.consume_front(")"));
1710 
1711  // Check if we've finished parsing.
1712  if (Text.empty())
1713  break;
1714 
1715  // Otherwise, the end of an inner pipeline always has to be followed by
1716  // a comma, and then we can continue.
1717  if (!Text.consume_front(","))
1718  return None;
1719  }
1720 
1721  if (PipelineStack.size() > 1)
1722  // Unbalanced paretheses.
1723  return None;
1724 
1725  assert(PipelineStack.back() == &ResultPipeline &&
1726  "Wrong pipeline at the bottom of the stack!");
1727  return {std::move(ResultPipeline)};
1728 }
1729 
1730 Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1731  const PipelineElement &E,
1732  bool VerifyEachPass, bool DebugLogging) {
1733  auto &Name = E.Name;
1734  auto &InnerPipeline = E.InnerPipeline;
1735 
1736  // First handle complex passes like the pass managers which carry pipelines.
1737  if (!InnerPipeline.empty()) {
1738  if (Name == "module") {
1739  ModulePassManager NestedMPM(DebugLogging);
1740  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1741  VerifyEachPass, DebugLogging))
1742  return Err;
1743  MPM.addPass(std::move(NestedMPM));
1744  return Error::success();
1745  }
1746  if (Name == "cgscc") {
1747  CGSCCPassManager CGPM(DebugLogging);
1748  if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1749  DebugLogging))
1750  return Err;
1751  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
1752  return Error::success();
1753  }
1754  if (Name == "function") {
1755  FunctionPassManager FPM(DebugLogging);
1756  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1757  VerifyEachPass, DebugLogging))
1758  return Err;
1759  MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1760  return Error::success();
1761  }
1762  if (auto Count = parseRepeatPassName(Name)) {
1763  ModulePassManager NestedMPM(DebugLogging);
1764  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1765  VerifyEachPass, DebugLogging))
1766  return Err;
1767  MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1768  return Error::success();
1769  }
1770 
1771  for (auto &C : ModulePipelineParsingCallbacks)
1772  if (C(Name, MPM, InnerPipeline))
1773  return Error::success();
1774 
1775  // Normal passes can't have pipelines.
1776  return make_error<StringError>(
1777  formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1779  ;
1780  }
1781 
1782  // Manually handle aliases for pre-configured pipeline fragments.
1784  SmallVector<StringRef, 3> Matches;
1785  if (!DefaultAliasRegex.match(Name, &Matches))
1786  return make_error<StringError>(
1787  formatv("unknown default pipeline alias '{0}'", Name).str(),
1789 
1790  assert(Matches.size() == 3 && "Must capture two matched strings!");
1791 
1792  OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
1793  .Case("O0", O0)
1794  .Case("O1", O1)
1795  .Case("O2", O2)
1796  .Case("O3", O3)
1797  .Case("Os", Os)
1798  .Case("Oz", Oz);
1799  if (L == O0)
1800  // At O0 we do nothing at all!
1801  return Error::success();
1802 
1803  if (Matches[1] == "default") {
1804  MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
1805  } else if (Matches[1] == "thinlto-pre-link") {
1806  MPM.addPass(buildThinLTOPreLinkDefaultPipeline(L, DebugLogging));
1807  } else if (Matches[1] == "thinlto") {
1808  MPM.addPass(buildThinLTODefaultPipeline(L, DebugLogging, nullptr));
1809  } else if (Matches[1] == "lto-pre-link") {
1810  MPM.addPass(buildLTOPreLinkDefaultPipeline(L, DebugLogging));
1811  } else {
1812  assert(Matches[1] == "lto" && "Not one of the matched options!");
1813  MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr));
1814  }
1815  return Error::success();
1816  }
1817 
1818  // Finally expand the basic registered passes from the .inc file.
1819 #define MODULE_PASS(NAME, CREATE_PASS) \
1820  if (Name == NAME) { \
1821  MPM.addPass(CREATE_PASS); \
1822  return Error::success(); \
1823  }
1824 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1825  if (Name == "require<" NAME ">") { \
1826  MPM.addPass( \
1827  RequireAnalysisPass< \
1828  std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
1829  return Error::success(); \
1830  } \
1831  if (Name == "invalidate<" NAME ">") { \
1832  MPM.addPass(InvalidateAnalysisPass< \
1833  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1834  return Error::success(); \
1835  }
1836 #include "PassRegistry.def"
1837 
1838  for (auto &C : ModulePipelineParsingCallbacks)
1839  if (C(Name, MPM, InnerPipeline))
1840  return Error::success();
1841  return make_error<StringError>(
1842  formatv("unknown module pass '{0}'", Name).str(),
1844 }
1845 
1846 Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1847  const PipelineElement &E, bool VerifyEachPass,
1848  bool DebugLogging) {
1849  auto &Name = E.Name;
1850  auto &InnerPipeline = E.InnerPipeline;
1851 
1852  // First handle complex passes like the pass managers which carry pipelines.
1853  if (!InnerPipeline.empty()) {
1854  if (Name == "cgscc") {
1855  CGSCCPassManager NestedCGPM(DebugLogging);
1856  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1857  VerifyEachPass, DebugLogging))
1858  return Err;
1859  // Add the nested pass manager with the appropriate adaptor.
1860  CGPM.addPass(std::move(NestedCGPM));
1861  return Error::success();
1862  }
1863  if (Name == "function") {
1864  FunctionPassManager FPM(DebugLogging);
1865  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1866  VerifyEachPass, DebugLogging))
1867  return Err;
1868  // Add the nested pass manager with the appropriate adaptor.
1869  CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1870  return Error::success();
1871  }
1872  if (auto Count = parseRepeatPassName(Name)) {
1873  CGSCCPassManager NestedCGPM(DebugLogging);
1874  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1875  VerifyEachPass, DebugLogging))
1876  return Err;
1877  CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1878  return Error::success();
1879  }
1880  if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1881  CGSCCPassManager NestedCGPM(DebugLogging);
1882  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1883  VerifyEachPass, DebugLogging))
1884  return Err;
1885  CGPM.addPass(
1886  createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1887  return Error::success();
1888  }
1889 
1890  for (auto &C : CGSCCPipelineParsingCallbacks)
1891  if (C(Name, CGPM, InnerPipeline))
1892  return Error::success();
1893 
1894  // Normal passes can't have pipelines.
1895  return make_error<StringError>(
1896  formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1898  }
1899 
1900 // Now expand the basic registered passes from the .inc file.
1901 #define CGSCC_PASS(NAME, CREATE_PASS) \
1902  if (Name == NAME) { \
1903  CGPM.addPass(CREATE_PASS); \
1904  return Error::success(); \
1905  }
1906 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1907  if (Name == "require<" NAME ">") { \
1908  CGPM.addPass(RequireAnalysisPass< \
1909  std::remove_reference<decltype(CREATE_PASS)>::type, \
1910  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1911  CGSCCUpdateResult &>()); \
1912  return Error::success(); \
1913  } \
1914  if (Name == "invalidate<" NAME ">") { \
1915  CGPM.addPass(InvalidateAnalysisPass< \
1916  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1917  return Error::success(); \
1918  }
1919 #include "PassRegistry.def"
1920 
1921  for (auto &C : CGSCCPipelineParsingCallbacks)
1922  if (C(Name, CGPM, InnerPipeline))
1923  return Error::success();
1924  return make_error<StringError>(
1925  formatv("unknown cgscc pass '{0}'", Name).str(),
1927 }
1928 
1929 Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1930  const PipelineElement &E,
1931  bool VerifyEachPass, bool DebugLogging) {
1932  auto &Name = E.Name;
1933  auto &InnerPipeline = E.InnerPipeline;
1934 
1935  // First handle complex passes like the pass managers which carry pipelines.
1936  if (!InnerPipeline.empty()) {
1937  if (Name == "function") {
1938  FunctionPassManager NestedFPM(DebugLogging);
1939  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1940  VerifyEachPass, DebugLogging))
1941  return Err;
1942  // Add the nested pass manager with the appropriate adaptor.
1943  FPM.addPass(std::move(NestedFPM));
1944  return Error::success();
1945  }
1946  if (Name == "loop") {
1947  LoopPassManager LPM(DebugLogging);
1948  if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1949  DebugLogging))
1950  return Err;
1951  // Add the nested pass manager with the appropriate adaptor.
1952  FPM.addPass(
1953  createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
1954  return Error::success();
1955  }
1956  if (auto Count = parseRepeatPassName(Name)) {
1957  FunctionPassManager NestedFPM(DebugLogging);
1958  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1959  VerifyEachPass, DebugLogging))
1960  return Err;
1961  FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1962  return Error::success();
1963  }
1964 
1965  for (auto &C : FunctionPipelineParsingCallbacks)
1966  if (C(Name, FPM, InnerPipeline))
1967  return Error::success();
1968 
1969  // Normal passes can't have pipelines.
1970  return make_error<StringError>(
1971  formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1973  }
1974 
1975 // Now expand the basic registered passes from the .inc file.
1976 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1977  if (Name == NAME) { \
1978  FPM.addPass(CREATE_PASS); \
1979  return Error::success(); \
1980  }
1981 #define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
1982  if (checkParametrizedPassName(Name, NAME)) { \
1983  auto Params = parsePassParameters(PARSER, Name, NAME); \
1984  if (!Params) \
1985  return Params.takeError(); \
1986  FPM.addPass(CREATE_PASS(Params.get())); \
1987  return Error::success(); \
1988  }
1989 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1990  if (Name == "require<" NAME ">") { \
1991  FPM.addPass( \
1992  RequireAnalysisPass< \
1993  std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
1994  return Error::success(); \
1995  } \
1996  if (Name == "invalidate<" NAME ">") { \
1997  FPM.addPass(InvalidateAnalysisPass< \
1998  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1999  return Error::success(); \
2000  }
2001 #include "PassRegistry.def"
2002 
2003  for (auto &C : FunctionPipelineParsingCallbacks)
2004  if (C(Name, FPM, InnerPipeline))
2005  return Error::success();
2006  return make_error<StringError>(
2007  formatv("unknown function pass '{0}'", Name).str(),
2009 }
2010 
2011 Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
2012  bool VerifyEachPass, bool DebugLogging) {
2013  StringRef Name = E.Name;
2014  auto &InnerPipeline = E.InnerPipeline;
2015 
2016  // First handle complex passes like the pass managers which carry pipelines.
2017  if (!InnerPipeline.empty()) {
2018  if (Name == "loop") {
2019  LoopPassManager NestedLPM(DebugLogging);
2020  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2021  VerifyEachPass, DebugLogging))
2022  return Err;
2023  // Add the nested pass manager with the appropriate adaptor.
2024  LPM.addPass(std::move(NestedLPM));
2025  return Error::success();
2026  }
2027  if (auto Count = parseRepeatPassName(Name)) {
2028  LoopPassManager NestedLPM(DebugLogging);
2029  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
2030  VerifyEachPass, DebugLogging))
2031  return Err;
2032  LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
2033  return Error::success();
2034  }
2035 
2036  for (auto &C : LoopPipelineParsingCallbacks)
2037  if (C(Name, LPM, InnerPipeline))
2038  return Error::success();
2039 
2040  // Normal passes can't have pipelines.
2041  return make_error<StringError>(
2042  formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
2044  }
2045 
2046 // Now expand the basic registered passes from the .inc file.
2047 #define LOOP_PASS(NAME, CREATE_PASS) \
2048  if (Name == NAME) { \
2049  LPM.addPass(CREATE_PASS); \
2050  return Error::success(); \
2051  }
2052 #define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER) \
2053  if (checkParametrizedPassName(Name, NAME)) { \
2054  auto Params = parsePassParameters(PARSER, Name, NAME); \
2055  if (!Params) \
2056  return Params.takeError(); \
2057  LPM.addPass(CREATE_PASS(Params.get())); \
2058  return Error::success(); \
2059  }
2060 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
2061  if (Name == "require<" NAME ">") { \
2062  LPM.addPass(RequireAnalysisPass< \
2063  std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
2064  LoopAnalysisManager, LoopStandardAnalysisResults &, \
2065  LPMUpdater &>()); \
2066  return Error::success(); \
2067  } \
2068  if (Name == "invalidate<" NAME ">") { \
2069  LPM.addPass(InvalidateAnalysisPass< \
2070  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
2071  return Error::success(); \
2072  }
2073 #include "PassRegistry.def"
2074 
2075  for (auto &C : LoopPipelineParsingCallbacks)
2076  if (C(Name, LPM, InnerPipeline))
2077  return Error::success();
2078  return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
2080 }
2081 
2082 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
2083 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2084  if (Name == NAME) { \
2085  AA.registerModuleAnalysis< \
2086  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
2087  return true; \
2088  }
2089 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2090  if (Name == NAME) { \
2091  AA.registerFunctionAnalysis< \
2092  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
2093  return true; \
2094  }
2095 #include "PassRegistry.def"
2096 
2097  for (auto &C : AAParsingCallbacks)
2098  if (C(Name, AA))
2099  return true;
2100  return false;
2101 }
2102 
2103 Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2104  ArrayRef<PipelineElement> Pipeline,
2105  bool VerifyEachPass,
2106  bool DebugLogging) {
2107  for (const auto &Element : Pipeline) {
2108  if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
2109  return Err;
2110  // FIXME: No verifier support for Loop passes!
2111  }
2112  return Error::success();
2113 }
2114 
2115 Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
2116  ArrayRef<PipelineElement> Pipeline,
2117  bool VerifyEachPass,
2118  bool DebugLogging) {
2119  for (const auto &Element : Pipeline) {
2120  if (auto Err =
2121  parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
2122  return Err;
2123  if (VerifyEachPass)
2124  FPM.addPass(VerifierPass());
2125  }
2126  return Error::success();
2127 }
2128 
2129 Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2130  ArrayRef<PipelineElement> Pipeline,
2131  bool VerifyEachPass,
2132  bool DebugLogging) {
2133  for (const auto &Element : Pipeline) {
2134  if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
2135  return Err;
2136  // FIXME: No verifier support for CGSCC passes!
2137  }
2138  return Error::success();
2139 }
2140 
2143  CGSCCAnalysisManager &CGAM,
2144  ModuleAnalysisManager &MAM) {
2145  MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
2146  MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
2147  CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
2148  FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
2149  FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
2150  FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
2151  LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
2152 }
2153 
2154 Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2155  ArrayRef<PipelineElement> Pipeline,
2156  bool VerifyEachPass,
2157  bool DebugLogging) {
2158  for (const auto &Element : Pipeline) {
2159  if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
2160  return Err;
2161  if (VerifyEachPass)
2162  MPM.addPass(VerifierPass());
2163  }
2164  return Error::success();
2165 }
2166 
2167 // Primary pass pipeline description parsing routine for a \c ModulePassManager
2168 // FIXME: Should this routine accept a TargetMachine or require the caller to
2169 // pre-populate the analysis managers with target-specific stuff?
2171  StringRef PipelineText,
2172  bool VerifyEachPass, bool DebugLogging) {
2173  auto Pipeline = parsePipelineText(PipelineText);
2174  if (!Pipeline || Pipeline->empty())
2175  return make_error<StringError>(
2176  formatv("invalid pipeline '{0}'", PipelineText).str(),
2178 
2179  // If the first name isn't at the module layer, wrap the pipeline up
2180  // automatically.
2181  StringRef FirstName = Pipeline->front().Name;
2182 
2183  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2184  if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2185  Pipeline = {{"cgscc", std::move(*Pipeline)}};
2186  } else if (isFunctionPassName(FirstName,
2187  FunctionPipelineParsingCallbacks)) {
2188  Pipeline = {{"function", std::move(*Pipeline)}};
2189  } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks)) {
2190  Pipeline = {{"function", {{"loop", std::move(*Pipeline)}}}};
2191  } else {
2192  for (auto &C : TopLevelPipelineParsingCallbacks)
2193  if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2194  return Error::success();
2195 
2196  // Unknown pass or pipeline name!
2197  auto &InnerPipeline = Pipeline->front().InnerPipeline;
2198  return make_error<StringError>(
2199  formatv("unknown {0} name '{1}'",
2200  (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2201  .str(),
2203  }
2204  }
2205 
2206  if (auto Err =
2207  parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging))
2208  return Err;
2209  return Error::success();
2210 }
2211 
2212 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2214  StringRef PipelineText,
2215  bool VerifyEachPass, bool DebugLogging) {
2216  auto Pipeline = parsePipelineText(PipelineText);
2217  if (!Pipeline || Pipeline->empty())
2218  return make_error<StringError>(
2219  formatv("invalid pipeline '{0}'", PipelineText).str(),
2221 
2222  StringRef FirstName = Pipeline->front().Name;
2223  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2224  return make_error<StringError>(
2225  formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
2226  PipelineText)
2227  .str(),
2229 
2230  if (auto Err =
2231  parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2232  return Err;
2233  return Error::success();
2234 }
2235 
2236 // Primary pass pipeline description parsing routine for a \c
2237 // FunctionPassManager
2239  StringRef PipelineText,
2240  bool VerifyEachPass, bool DebugLogging) {
2241  auto Pipeline = parsePipelineText(PipelineText);
2242  if (!Pipeline || Pipeline->empty())
2243  return make_error<StringError>(
2244  formatv("invalid pipeline '{0}'", PipelineText).str(),
2246 
2247  StringRef FirstName = Pipeline->front().Name;
2248  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2249  return make_error<StringError>(
2250  formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
2251  PipelineText)
2252  .str(),
2254 
2255  if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
2256  DebugLogging))
2257  return Err;
2258  return Error::success();
2259 }
2260 
2261 // Primary pass pipeline description parsing routine for a \c LoopPassManager
2263  StringRef PipelineText,
2264  bool VerifyEachPass, bool DebugLogging) {
2265  auto Pipeline = parsePipelineText(PipelineText);
2266  if (!Pipeline || Pipeline->empty())
2267  return make_error<StringError>(
2268  formatv("invalid pipeline '{0}'", PipelineText).str(),
2270 
2271  if (auto Err =
2272  parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
2273  return Err;
2274 
2275  return Error::success();
2276 }
2277 
2279  // If the pipeline just consists of the word 'default' just replace the AA
2280  // manager with our default one.
2281  if (PipelineText == "default") {
2282  AA = buildDefaultAAPipeline();
2283  return Error::success();
2284  }
2285 
2286  while (!PipelineText.empty()) {
2287  StringRef Name;
2288  std::tie(Name, PipelineText) = PipelineText.split(',');
2289  if (!parseAAPassName(AA, Name))
2290  return make_error<StringError>(
2291  formatv("unknown alias analysis name '{0}'", Name).str(),
2293  }
2294 
2295  return Error::success();
2296 }
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:151
Analysis pass providing a never-invalidated alias analysis result.
A set of parameters used to control various transforms performed by the LoopUnroll pass...
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:153
bool LoopVectorization
Tuning option to enable/disable loop vectorization.
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:267
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:65
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.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
Uses an "inverted" value numbering to decide the similarity of expressions and sinks similar expressi...
Definition: GVN.h:305
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Performs basic CFG simplifications to assist other loop passes.
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:1443
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:649
This is the interface for a metadata-based scoped no-alias analysis.
SimplifyCFGOptions & bonusInstThreshold(int I)
Definition: Local.h:84
SimplifyCFGOptions & sinkCommonInsts(bool B)
Definition: Local.h:100
void registerModuleAnalysis()
Register a specific AA result.
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.
OptimizationLevel
LLVM-provided high-level optimization levels.
Definition: PassBuilder.h:146
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.
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:1355
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
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:88
cl::opt< bool > EnableLoopInterleaving
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:298
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
Optional< int > HintThreshold
Threshold to use for callees with inline hint.
Definition: InlineCost.h:158
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
Definition: PassBuilder.h:216
Instrumentation based profiling lowering pass.
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:828
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:1127
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: CachePruning.h:22
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:578
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
The instrumentation (profile-instr-gen) pass for IR based PGO.
Key
PAL metadata keys.
A very specialized mode that will optimize for code size at any and all costs.
Definition: PassBuilder.h:225
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
FunctionToLoopPassAdaptor< LoopPassT > createFunctionToLoopPassAdaptor(LoopPassT Pass, bool DebugLogging=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
This file provides the interface for IR based instrumentation passes ( (profile-gen, and profile-use).
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1574
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:45
The core GVN pass object.
Definition: GVN.h:68
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:92
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...
cl::opt< bool > FlattenedProfileUsed
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
static cl::opt< unsigned > MaxDevirtIterations("pm-max-devirt-iterations", cl::ReallyHidden, cl::init(4))
cl::opt< bool > RunSLPVectorization
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:432
static bool isOptimizingForSize(PassBuilder::OptimizationLevel Level)
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
This is the interface for a metadata-based TBAA.
static Regex DefaultAliasRegex("^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$")
ModuleToFunctionPassAdaptor< FunctionPassT > createModuleToFunctionPassAdaptor(FunctionPassT Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1339
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")
This file provides the primary interface to the instcombine pass.
Disable as many optimizations as possible.
Definition: PassBuilder.h:150
FunctionPassManager buildFunctionSimplificationPipeline(OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging=false)
Construct the core LLVM function canonicalization and simplification pipeline.
A manager for alias analyses.
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:389
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
bool ForgetAllSCEVInLoopUnroll
Tuning option to forget all SCEV loops in LoopUnroll.
Definition: PassBuilder.h:93
The inliner pass for the new pass manager.
Definition: Inliner.h:94
cl::opt< unsigned > SetLicmMssaOptCap
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
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:133
Optimize for fast execution as much as possible.
Definition: PassBuilder.h:204
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.
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:159
std::string InstrProfileOutput
size_t size() const
Definition: SmallVector.h:52
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)"))
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:478
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...
This header defines the LoopLoadEliminationPass object.
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
bool LoopInterleaving
Tuning option to set loop interleaving on/off.
Definition: PassBuilder.h:78
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:841
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: PassBuilder.h:188
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:696
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
SimplifyCFGOptions & needCanonicalLoops(bool B)
Definition: Local.h:96
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.
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
unsigned LicmMssaOptCap
Tuning option to cap the number of calls to retrive clobbering accesses in MemorySSA, in LICM.
Definition: PassBuilder.h:97
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.
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 const size_t npos
Definition: StringRef.h:50
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:465
unsigned LicmMssaNoAccForPromotionCap
Tuning option to disable promotion to scalars in LICM with MemorySSA, if the number of access is too ...
Definition: PassBuilder.h:101
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:380
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.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1256
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:659
This header provides classes for managing passes over SCCs of the call graph.
This file defines passes to print out IR in various granularities.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
cl::opt< bool > EnableLoopVectorization
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.
Optimize quickly without destroying debuggability.
Definition: PassBuilder.h:170
The profile size based optimization pass for memory intrinsics.
See the comments on JumpThreadingPass.
An SCC of the call graph.
static const char * name
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)
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr)
matches - Match the regex against a given String.
Definition: Regex.cpp:72
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:48
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:63
void addPass(PassT Pass)
Definition: PassManager.h:548
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.
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"))
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:70
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization.
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:170
int DefaultThreshold
The default threshold to start with for a callee.
Definition: InlineCost.h:155
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:143
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
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks)