LLVM  16.0.0git
PassBuilder.cpp
Go to the documentation of this file.
1 //===- Parsing and selection 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/DDG.h"
45 #include "llvm/Analysis/IVUsers.h"
51 #include "llvm/Analysis/Lint.h"
54 #include "llvm/Analysis/LoopInfo.h"
76 #include "llvm/IR/DebugInfo.h"
77 #include "llvm/IR/Dominators.h"
78 #include "llvm/IR/PassManager.h"
79 #include "llvm/IR/PrintPasses.h"
81 #include "llvm/IR/Verifier.h"
84 #include "llvm/Support/Debug.h"
87 #include "llvm/Support/Regex.h"
148 #include "llvm/Transforms/ObjCARC.h"
256 #include <optional>
257 
258 using namespace llvm;
259 
260 static const Regex DefaultAliasRegex(
261  "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
262 
263 namespace llvm {
265  "print-pipeline-passes",
266  cl::desc("Print a '-passes' compatible string describing the pipeline "
267  "(best-effort only)."));
268 } // namespace llvm
269 
270 namespace {
271 
272 // The following passes/analyses have custom names, otherwise their name will
273 // include `(anonymous namespace)`. These are special since they are only for
274 // testing purposes and don't live in a header file.
275 
276 /// No-op module pass which does nothing.
277 struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
279  return PreservedAnalyses::all();
280  }
281 
282  static StringRef name() { return "NoOpModulePass"; }
283 };
284 
285 /// No-op module analysis.
286 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
288  static AnalysisKey Key;
289 
290 public:
291  struct Result {};
292  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
293  static StringRef name() { return "NoOpModuleAnalysis"; }
294 };
295 
296 /// No-op CGSCC pass which does nothing.
297 struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
300  return PreservedAnalyses::all();
301  }
302  static StringRef name() { return "NoOpCGSCCPass"; }
303 };
304 
305 /// No-op CGSCC analysis.
306 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
308  static AnalysisKey Key;
309 
310 public:
311  struct Result {};
313  return Result();
314  }
315  static StringRef name() { return "NoOpCGSCCAnalysis"; }
316 };
317 
318 /// No-op function pass which does nothing.
319 struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
321  return PreservedAnalyses::all();
322  }
323  static StringRef name() { return "NoOpFunctionPass"; }
324 };
325 
326 /// No-op function analysis.
327 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
329  static AnalysisKey Key;
330 
331 public:
332  struct Result {};
333  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
334  static StringRef name() { return "NoOpFunctionAnalysis"; }
335 };
336 
337 /// No-op loop nest pass which does nothing.
338 struct NoOpLoopNestPass : PassInfoMixin<NoOpLoopNestPass> {
341  return PreservedAnalyses::all();
342  }
343  static StringRef name() { return "NoOpLoopNestPass"; }
344 };
345 
346 /// No-op loop pass which does nothing.
347 struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
350  return PreservedAnalyses::all();
351  }
352  static StringRef name() { return "NoOpLoopPass"; }
353 };
354 
355 /// No-op loop analysis.
356 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
358  static AnalysisKey Key;
359 
360 public:
361  struct Result {};
363  return Result();
364  }
365  static StringRef name() { return "NoOpLoopAnalysis"; }
366 };
367 
372 
373 /// Whether or not we should populate a PassInstrumentationCallbacks's class to
374 /// pass name map.
375 ///
376 /// This is for optimization purposes so we don't populate it if we never use
377 /// it. This should be updated if new pass instrumentation wants to use the map.
378 /// We currently only use this for --print-before/after.
379 bool shouldPopulateClassToPassNames() {
380  return PrintPipelinePasses || !printBeforePasses().empty() ||
381  !printAfterPasses().empty() || !isFilterPassesEmpty();
382 }
383 
384 // A pass for testing -print-on-crash.
385 // DO NOT USE THIS EXCEPT FOR TESTING!
386 class TriggerCrashPass : public PassInfoMixin<TriggerCrashPass> {
387 public:
389  abort();
390  return PreservedAnalyses::all();
391  }
392  static StringRef name() { return "TriggerCrashPass"; }
393 };
394 
395 } // namespace
396 
398  std::optional<PGOOptions> PGOOpt,
400  : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
401  if (TM)
402  TM->registerPassBuilderCallbacks(*this);
403  if (PIC && shouldPopulateClassToPassNames()) {
404 #define MODULE_PASS(NAME, CREATE_PASS) \
405  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
406 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
407  PIC->addClassToPassName(CLASS, NAME);
408 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
409  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
410 #define FUNCTION_PASS(NAME, CREATE_PASS) \
411  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
412 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
413  PIC->addClassToPassName(CLASS, NAME);
414 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
415  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
416 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
417  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
418 #define LOOP_PASS(NAME, CREATE_PASS) \
419  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
420 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
421  PIC->addClassToPassName(CLASS, NAME);
422 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
423  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
424 #define CGSCC_PASS(NAME, CREATE_PASS) \
425  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
426 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
427  PIC->addClassToPassName(CLASS, NAME);
428 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
429  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
430 #include "PassRegistry.def"
431  }
432 }
433 
435 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
436  MAM.registerPass([&] { return CREATE_PASS; });
437 #include "PassRegistry.def"
438 
439  for (auto &C : ModuleAnalysisRegistrationCallbacks)
440  C(MAM);
441 }
442 
444 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
445  CGAM.registerPass([&] { return CREATE_PASS; });
446 #include "PassRegistry.def"
447 
448  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
449  C(CGAM);
450 }
451 
453  // We almost always want the default alias analysis pipeline.
454  // If a user wants a different one, they can register their own before calling
455  // registerFunctionAnalyses().
456  FAM.registerPass([&] { return buildDefaultAAPipeline(); });
457 
458 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
459  FAM.registerPass([&] { return CREATE_PASS; });
460 #include "PassRegistry.def"
461 
462  for (auto &C : FunctionAnalysisRegistrationCallbacks)
463  C(FAM);
464 }
465 
467 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
468  LAM.registerPass([&] { return CREATE_PASS; });
469 #include "PassRegistry.def"
470 
471  for (auto &C : LoopAnalysisRegistrationCallbacks)
472  C(LAM);
473 }
474 
475 static std::optional<int> parseRepeatPassName(StringRef Name) {
476  if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
477  return std::nullopt;
478  int Count;
479  if (Name.getAsInteger(0, Count) || Count <= 0)
480  return std::nullopt;
481  return Count;
482 }
483 
484 static std::optional<int> parseDevirtPassName(StringRef Name) {
485  if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
486  return std::nullopt;
487  int Count;
488  if (Name.getAsInteger(0, Count) || Count < 0)
489  return std::nullopt;
490  return Count;
491 }
492 
494  if (!Name.consume_front(PassName))
495  return false;
496  // normal pass name w/o parameters == default parameters
497  if (Name.empty())
498  return true;
499  return Name.startswith("<") && Name.endswith(">");
500 }
501 
502 namespace {
503 
504 /// This performs customized parsing of pass name with parameters.
505 ///
506 /// We do not need parametrization of passes in textual pipeline very often,
507 /// yet on a rare occasion ability to specify parameters right there can be
508 /// useful.
509 ///
510 /// \p Name - parameterized specification of a pass from a textual pipeline
511 /// is a string in a form of :
512 /// PassName '<' parameter-list '>'
513 ///
514 /// Parameter list is being parsed by the parser callable argument, \p Parser,
515 /// It takes a string-ref of parameters and returns either StringError or a
516 /// parameter list in a form of a custom parameters type, all wrapped into
517 /// Expected<> template class.
518 ///
519 template <typename ParametersParseCallableT>
520 auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
521  StringRef PassName) -> decltype(Parser(StringRef{})) {
522  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
523 
524  StringRef Params = Name;
525  if (!Params.consume_front(PassName)) {
526  assert(false &&
527  "unable to strip pass name from parametrized pass specification");
528  }
529  if (!Params.empty() &&
530  (!Params.consume_front("<") || !Params.consume_back(">"))) {
531  assert(false && "invalid format for parametrized pass name");
532  }
533 
534  Expected<ParametersT> Result = Parser(Params);
535  assert((Result || Result.template errorIsA<StringError>()) &&
536  "Pass parameter parser can only return StringErrors.");
537  return Result;
538 }
539 
540 /// Parser of parameters for LoopUnroll pass.
541 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
542  LoopUnrollOptions UnrollOpts;
543  while (!Params.empty()) {
544  StringRef ParamName;
545  std::tie(ParamName, Params) = Params.split(';');
546  int OptLevel = StringSwitch<int>(ParamName)
547  .Case("O0", 0)
548  .Case("O1", 1)
549  .Case("O2", 2)
550  .Case("O3", 3)
551  .Default(-1);
552  if (OptLevel >= 0) {
553  UnrollOpts.setOptLevel(OptLevel);
554  continue;
555  }
556  if (ParamName.consume_front("full-unroll-max=")) {
557  int Count;
558  if (ParamName.getAsInteger(0, Count))
559  return make_error<StringError>(
560  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
562  UnrollOpts.setFullUnrollMaxCount(Count);
563  continue;
564  }
565 
566  bool Enable = !ParamName.consume_front("no-");
567  if (ParamName == "partial") {
568  UnrollOpts.setPartial(Enable);
569  } else if (ParamName == "peeling") {
570  UnrollOpts.setPeeling(Enable);
571  } else if (ParamName == "profile-peeling") {
572  UnrollOpts.setProfileBasedPeeling(Enable);
573  } else if (ParamName == "runtime") {
574  UnrollOpts.setRuntime(Enable);
575  } else if (ParamName == "upperbound") {
576  UnrollOpts.setUpperBound(Enable);
577  } else {
578  return make_error<StringError>(
579  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
581  }
582  }
583  return UnrollOpts;
584 }
585 
586 Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
588  bool Result = false;
589  while (!Params.empty()) {
590  StringRef ParamName;
591  std::tie(ParamName, Params) = Params.split(';');
592 
593  if (ParamName == OptionName) {
594  Result = true;
595  } else {
596  return make_error<StringError>(
597  formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
598  .str(),
600  }
601  }
602  return Result;
603 }
604 
605 Expected<bool> parseInlinerPassOptions(StringRef Params) {
606  return parseSinglePassOption(Params, "only-mandatory", "InlinerPass");
607 }
608 
609 Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
610  return parseSinglePassOption(Params, "reuse-storage", "CoroSplitPass");
611 }
612 
613 Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
614  return parseSinglePassOption(Params, "memssa", "EarlyCSE");
615 }
616 
617 Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
618  return parseSinglePassOption(Params, "post-inline", "EntryExitInstrumenter");
619 }
620 
621 Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
622  return parseSinglePassOption(Params, "single", "LoopExtractor");
623 }
624 
625 Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
626  return parseSinglePassOption(Params, "minimal", "LowerMatrixIntrinsics");
627 }
628 
629 Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
631  while (!Params.empty()) {
632  StringRef ParamName;
633  std::tie(ParamName, Params) = Params.split(';');
634 
635  if (ParamName == "kernel") {
636  Result.CompileKernel = true;
637  } else {
638  return make_error<StringError>(
639  formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName)
640  .str(),
642  }
643  }
644  return Result;
645 }
646 
647 Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
649  while (!Params.empty()) {
650  StringRef ParamName;
651  std::tie(ParamName, Params) = Params.split(';');
652 
653  if (ParamName == "recover") {
654  Result.Recover = true;
655  } else if (ParamName == "kernel") {
656  Result.CompileKernel = true;
657  } else {
658  return make_error<StringError>(
659  formatv("invalid HWAddressSanitizer pass parameter '{0}' ", ParamName)
660  .str(),
662  }
663  }
664  return Result;
665 }
666 
667 Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
669  while (!Params.empty()) {
670  StringRef ParamName;
671  std::tie(ParamName, Params) = Params.split(';');
672 
673  if (ParamName == "recover") {
674  Result.Recover = true;
675  } else if (ParamName == "kernel") {
676  Result.Kernel = true;
677  } else if (ParamName.consume_front("track-origins=")) {
678  if (ParamName.getAsInteger(0, Result.TrackOrigins))
679  return make_error<StringError>(
680  formatv("invalid argument to MemorySanitizer pass track-origins "
681  "parameter: '{0}' ",
682  ParamName)
683  .str(),
685  } else if (ParamName == "eager-checks") {
686  Result.EagerChecks = true;
687  } else {
688  return make_error<StringError>(
689  formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
690  .str(),
692  }
693  }
694  return Result;
695 }
696 
697 /// Parser of parameters for SimplifyCFG pass.
698 Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
700  while (!Params.empty()) {
701  StringRef ParamName;
702  std::tie(ParamName, Params) = Params.split(';');
703 
704  bool Enable = !ParamName.consume_front("no-");
705  if (ParamName == "forward-switch-cond") {
706  Result.forwardSwitchCondToPhi(Enable);
707  } else if (ParamName == "switch-range-to-icmp") {
708  Result.convertSwitchRangeToICmp(Enable);
709  } else if (ParamName == "switch-to-lookup") {
710  Result.convertSwitchToLookupTable(Enable);
711  } else if (ParamName == "keep-loops") {
712  Result.needCanonicalLoops(Enable);
713  } else if (ParamName == "hoist-common-insts") {
714  Result.hoistCommonInsts(Enable);
715  } else if (ParamName == "sink-common-insts") {
716  Result.sinkCommonInsts(Enable);
717  } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
718  APInt BonusInstThreshold;
719  if (ParamName.getAsInteger(0, BonusInstThreshold))
720  return make_error<StringError>(
721  formatv("invalid argument to SimplifyCFG pass bonus-threshold "
722  "parameter: '{0}' ",
723  ParamName).str(),
725  Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
726  } else {
727  return make_error<StringError>(
728  formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
730  }
731  }
732  return Result;
733 }
734 
735 /// Parser of parameters for LoopVectorize pass.
736 Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
738  while (!Params.empty()) {
739  StringRef ParamName;
740  std::tie(ParamName, Params) = Params.split(';');
741 
742  bool Enable = !ParamName.consume_front("no-");
743  if (ParamName == "interleave-forced-only") {
744  Opts.setInterleaveOnlyWhenForced(Enable);
745  } else if (ParamName == "vectorize-forced-only") {
746  Opts.setVectorizeOnlyWhenForced(Enable);
747  } else {
748  return make_error<StringError>(
749  formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
751  }
752  }
753  return Opts;
754 }
755 
756 Expected<std::pair<bool, bool>> parseLoopUnswitchOptions(StringRef Params) {
757  std::pair<bool, bool> Result = {false, true};
758  while (!Params.empty()) {
759  StringRef ParamName;
760  std::tie(ParamName, Params) = Params.split(';');
761 
762  bool Enable = !ParamName.consume_front("no-");
763  if (ParamName == "nontrivial") {
764  Result.first = Enable;
765  } else if (ParamName == "trivial") {
766  Result.second = Enable;
767  } else {
768  return make_error<StringError>(
769  formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
770  .str(),
772  }
773  }
774  return Result;
775 }
776 
777 Expected<LICMOptions> parseLICMOptions(StringRef Params) {
779  while (!Params.empty()) {
780  StringRef ParamName;
781  std::tie(ParamName, Params) = Params.split(';');
782 
783  bool Enable = !ParamName.consume_front("no-");
784  if (ParamName == "allowspeculation") {
785  Result.AllowSpeculation = Enable;
786  } else {
787  return make_error<StringError>(
788  formatv("invalid LICM pass parameter '{0}' ", ParamName).str(),
790  }
791  }
792  return Result;
793 }
794 
795 Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
796  bool Result = false;
797  while (!Params.empty()) {
798  StringRef ParamName;
799  std::tie(ParamName, Params) = Params.split(';');
800 
801  bool Enable = !ParamName.consume_front("no-");
802  if (ParamName == "split-footer-bb") {
803  Result = Enable;
804  } else {
805  return make_error<StringError>(
806  formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ",
807  ParamName)
808  .str(),
810  }
811  }
812  return Result;
813 }
814 
815 Expected<GVNOptions> parseGVNOptions(StringRef Params) {
817  while (!Params.empty()) {
818  StringRef ParamName;
819  std::tie(ParamName, Params) = Params.split(';');
820 
821  bool Enable = !ParamName.consume_front("no-");
822  if (ParamName == "pre") {
823  Result.setPRE(Enable);
824  } else if (ParamName == "load-pre") {
825  Result.setLoadPRE(Enable);
826  } else if (ParamName == "split-backedge-load-pre") {
827  Result.setLoadPRESplitBackedge(Enable);
828  } else if (ParamName == "memdep") {
829  Result.setMemDep(Enable);
830  } else {
831  return make_error<StringError>(
832  formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
834  }
835  }
836  return Result;
837 }
838 
840 parseStackLifetimeOptions(StringRef Params) {
842  while (!Params.empty()) {
843  StringRef ParamName;
844  std::tie(ParamName, Params) = Params.split(';');
845 
846  if (ParamName == "may") {
848  } else if (ParamName == "must") {
850  } else {
851  return make_error<StringError>(
852  formatv("invalid StackLifetime parameter '{0}' ", ParamName).str(),
854  }
855  }
856  return Result;
857 }
858 
859 Expected<bool> parseDependenceAnalysisPrinterOptions(StringRef Params) {
860  return parseSinglePassOption(Params, "normalized-results",
861  "DependenceAnalysisPrinter");
862 }
863 
864 } // namespace
865 
866 /// Tests whether a pass name starts with a valid prefix for a default pipeline
867 /// alias.
869  return Name.startswith("default") || Name.startswith("thinlto") ||
870  Name.startswith("lto");
871 }
872 
873 /// Tests whether registered callbacks will accept a given pass name.
874 ///
875 /// When parsing a pipeline text, the type of the outermost pipeline may be
876 /// omitted, in which case the type is automatically determined from the first
877 /// pass name in the text. This may be a name that is handled through one of the
878 /// callbacks. We check this through the oridinary parsing callbacks by setting
879 /// up a dummy PassManager in order to not force the client to also handle this
880 /// type of query.
881 template <typename PassManagerT, typename CallbacksT>
882 static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
883  if (!Callbacks.empty()) {
884  PassManagerT DummyPM;
885  for (auto &CB : Callbacks)
886  if (CB(Name, DummyPM, {}))
887  return true;
888  }
889  return false;
890 }
891 
892 template <typename CallbacksT>
893 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
894  // Manually handle aliases for pre-configured pipeline fragments.
896  return DefaultAliasRegex.match(Name);
897 
898  // Explicitly handle pass manager names.
899  if (Name == "module")
900  return true;
901  if (Name == "cgscc")
902  return true;
903  if (Name == "function" || Name == "function<eager-inv>")
904  return true;
905  if (Name == "coro-cond")
906  return true;
907 
908  // Explicitly handle custom-parsed pass names.
909  if (parseRepeatPassName(Name))
910  return true;
911 
912 #define MODULE_PASS(NAME, CREATE_PASS) \
913  if (Name == NAME) \
914  return true;
915 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
916  if (checkParametrizedPassName(Name, NAME)) \
917  return true;
918 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
919  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
920  return true;
921 #include "PassRegistry.def"
922 
923  return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
924 }
925 
926 template <typename CallbacksT>
927 static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
928  // Explicitly handle pass manager names.
929  if (Name == "cgscc")
930  return true;
931  if (Name == "function" || Name == "function<eager-inv>")
932  return true;
933 
934  // Explicitly handle custom-parsed pass names.
935  if (parseRepeatPassName(Name))
936  return true;
937  if (parseDevirtPassName(Name))
938  return true;
939 
940 #define CGSCC_PASS(NAME, CREATE_PASS) \
941  if (Name == NAME) \
942  return true;
943 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
944  if (checkParametrizedPassName(Name, NAME)) \
945  return true;
946 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
947  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
948  return true;
949 #include "PassRegistry.def"
950 
951  return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
952 }
953 
954 template <typename CallbacksT>
955 static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
956  // Explicitly handle pass manager names.
957  if (Name == "function" || Name == "function<eager-inv>")
958  return true;
959  if (Name == "loop" || Name == "loop-mssa")
960  return true;
961 
962  // Explicitly handle custom-parsed pass names.
963  if (parseRepeatPassName(Name))
964  return true;
965 
966 #define FUNCTION_PASS(NAME, CREATE_PASS) \
967  if (Name == NAME) \
968  return true;
969 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
970  if (checkParametrizedPassName(Name, NAME)) \
971  return true;
972 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
973  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
974  return true;
975 #include "PassRegistry.def"
976 
977  return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
978 }
979 
980 template <typename CallbacksT>
981 static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
982  bool &UseMemorySSA) {
983  UseMemorySSA = false;
984 
985  // Explicitly handle custom-parsed pass names.
986  if (parseRepeatPassName(Name))
987  return true;
988 
989  if (Name == "lnicm") {
990  UseMemorySSA = true;
991  return true;
992  }
993 
994 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
995  if (Name == NAME) \
996  return true;
997 #include "PassRegistry.def"
998 
999  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1000 }
1001 
1002 template <typename CallbacksT>
1003 static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
1004  bool &UseMemorySSA) {
1005  UseMemorySSA = false;
1006 
1007  // Explicitly handle custom-parsed pass names.
1008  if (parseRepeatPassName(Name))
1009  return true;
1010 
1011  if (Name == "licm") {
1012  UseMemorySSA = true;
1013  return true;
1014  }
1015 
1016 #define LOOP_PASS(NAME, CREATE_PASS) \
1017  if (Name == NAME) \
1018  return true;
1019 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1020  if (checkParametrizedPassName(Name, NAME)) \
1021  return true;
1022 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1023  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1024  return true;
1025 #include "PassRegistry.def"
1026 
1027  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1028 }
1029 
1030 std::optional<std::vector<PassBuilder::PipelineElement>>
1031 PassBuilder::parsePipelineText(StringRef Text) {
1032  std::vector<PipelineElement> ResultPipeline;
1033 
1034  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1035  &ResultPipeline};
1036  for (;;) {
1037  std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1038  size_t Pos = Text.find_first_of(",()");
1039  Pipeline.push_back({Text.substr(0, Pos), {}});
1040 
1041  // If we have a single terminating name, we're done.
1042  if (Pos == Text.npos)
1043  break;
1044 
1045  char Sep = Text[Pos];
1046  Text = Text.substr(Pos + 1);
1047  if (Sep == ',')
1048  // Just a name ending in a comma, continue.
1049  continue;
1050 
1051  if (Sep == '(') {
1052  // Push the inner pipeline onto the stack to continue processing.
1053  PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1054  continue;
1055  }
1056 
1057  assert(Sep == ')' && "Bogus separator!");
1058  // When handling the close parenthesis, we greedily consume them to avoid
1059  // empty strings in the pipeline.
1060  do {
1061  // If we try to pop the outer pipeline we have unbalanced parentheses.
1062  if (PipelineStack.size() == 1)
1063  return std::nullopt;
1064 
1065  PipelineStack.pop_back();
1066  } while (Text.consume_front(")"));
1067 
1068  // Check if we've finished parsing.
1069  if (Text.empty())
1070  break;
1071 
1072  // Otherwise, the end of an inner pipeline always has to be followed by
1073  // a comma, and then we can continue.
1074  if (!Text.consume_front(","))
1075  return std::nullopt;
1076  }
1077 
1078  if (PipelineStack.size() > 1)
1079  // Unbalanced paretheses.
1080  return std::nullopt;
1081 
1082  assert(PipelineStack.back() == &ResultPipeline &&
1083  "Wrong pipeline at the bottom of the stack!");
1084  return {std::move(ResultPipeline)};
1085 }
1086 
1087 Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1088  const PipelineElement &E) {
1089  auto &Name = E.Name;
1090  auto &InnerPipeline = E.InnerPipeline;
1091 
1092  // First handle complex passes like the pass managers which carry pipelines.
1093  if (!InnerPipeline.empty()) {
1094  if (Name == "module") {
1095  ModulePassManager NestedMPM;
1096  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1097  return Err;
1098  MPM.addPass(std::move(NestedMPM));
1099  return Error::success();
1100  }
1101  if (Name == "coro-cond") {
1102  ModulePassManager NestedMPM;
1103  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1104  return Err;
1106  return Error::success();
1107  }
1108  if (Name == "cgscc") {
1109  CGSCCPassManager CGPM;
1110  if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1111  return Err;
1113  return Error::success();
1114  }
1115  if (Name == "function" || Name == "function<eager-inv>") {
1116  FunctionPassManager FPM;
1117  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1118  return Err;
1120  Name != "function"));
1121  return Error::success();
1122  }
1123  if (auto Count = parseRepeatPassName(Name)) {
1124  ModulePassManager NestedMPM;
1125  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1126  return Err;
1127  MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1128  return Error::success();
1129  }
1130 
1131  for (auto &C : ModulePipelineParsingCallbacks)
1132  if (C(Name, MPM, InnerPipeline))
1133  return Error::success();
1134 
1135  // Normal passes can't have pipelines.
1136  return make_error<StringError>(
1137  formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1139  ;
1140  }
1141 
1142  // Manually handle aliases for pre-configured pipeline fragments.
1144  SmallVector<StringRef, 3> Matches;
1145  if (!DefaultAliasRegex.match(Name, &Matches))
1146  return make_error<StringError>(
1147  formatv("unknown default pipeline alias '{0}'", Name).str(),
1149 
1150  assert(Matches.size() == 3 && "Must capture two matched strings!");
1151 
1153  .Case("O0", OptimizationLevel::O0)
1154  .Case("O1", OptimizationLevel::O1)
1155  .Case("O2", OptimizationLevel::O2)
1156  .Case("O3", OptimizationLevel::O3)
1157  .Case("Os", OptimizationLevel::Os)
1158  .Case("Oz", OptimizationLevel::Oz);
1159  if (L == OptimizationLevel::O0 && Matches[1] != "thinlto" &&
1160  Matches[1] != "lto") {
1161  MPM.addPass(buildO0DefaultPipeline(L, Matches[1] == "thinlto-pre-link" ||
1162  Matches[1] == "lto-pre-link"));
1163  return Error::success();
1164  }
1165 
1166  // This is consistent with old pass manager invoked via opt, but
1167  // inconsistent with clang. Clang doesn't enable loop vectorization
1168  // but does enable slp vectorization at Oz.
1169  PTO.LoopVectorization =
1170  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1171  PTO.SLPVectorization =
1172  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1173 
1174  if (Matches[1] == "default") {
1176  } else if (Matches[1] == "thinlto-pre-link") {
1178  } else if (Matches[1] == "thinlto") {
1180  } else if (Matches[1] == "lto-pre-link") {
1182  } else {
1183  assert(Matches[1] == "lto" && "Not one of the matched options!");
1184  MPM.addPass(buildLTODefaultPipeline(L, nullptr));
1185  }
1186  return Error::success();
1187  }
1188 
1189  // Finally expand the basic registered passes from the .inc file.
1190 #define MODULE_PASS(NAME, CREATE_PASS) \
1191  if (Name == NAME) { \
1192  MPM.addPass(CREATE_PASS); \
1193  return Error::success(); \
1194  }
1195 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1196  if (checkParametrizedPassName(Name, NAME)) { \
1197  auto Params = parsePassParameters(PARSER, Name, NAME); \
1198  if (!Params) \
1199  return Params.takeError(); \
1200  MPM.addPass(CREATE_PASS(Params.get())); \
1201  return Error::success(); \
1202  }
1203 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1204  if (Name == "require<" NAME ">") { \
1205  MPM.addPass( \
1206  RequireAnalysisPass< \
1207  std::remove_reference_t<decltype(CREATE_PASS)>, Module>()); \
1208  return Error::success(); \
1209  } \
1210  if (Name == "invalidate<" NAME ">") { \
1211  MPM.addPass(InvalidateAnalysisPass< \
1212  std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1213  return Error::success(); \
1214  }
1215 #define CGSCC_PASS(NAME, CREATE_PASS) \
1216  if (Name == NAME) { \
1217  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1218  return Error::success(); \
1219  }
1220 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1221  if (checkParametrizedPassName(Name, NAME)) { \
1222  auto Params = parsePassParameters(PARSER, Name, NAME); \
1223  if (!Params) \
1224  return Params.takeError(); \
1225  MPM.addPass( \
1226  createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1227  return Error::success(); \
1228  }
1229 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1230  if (Name == NAME) { \
1231  MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1232  return Error::success(); \
1233  }
1234 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1235  if (checkParametrizedPassName(Name, NAME)) { \
1236  auto Params = parsePassParameters(PARSER, Name, NAME); \
1237  if (!Params) \
1238  return Params.takeError(); \
1239  MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1240  return Error::success(); \
1241  }
1242 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1243  if (Name == NAME) { \
1244  MPM.addPass(createModuleToFunctionPassAdaptor( \
1245  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1246  return Error::success(); \
1247  }
1248 #define LOOP_PASS(NAME, CREATE_PASS) \
1249  if (Name == NAME) { \
1250  MPM.addPass(createModuleToFunctionPassAdaptor( \
1251  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1252  return Error::success(); \
1253  }
1254 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1255  if (checkParametrizedPassName(Name, NAME)) { \
1256  auto Params = parsePassParameters(PARSER, Name, NAME); \
1257  if (!Params) \
1258  return Params.takeError(); \
1259  MPM.addPass( \
1260  createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1261  CREATE_PASS(Params.get()), false, false))); \
1262  return Error::success(); \
1263  }
1264 #include "PassRegistry.def"
1265 
1266  for (auto &C : ModulePipelineParsingCallbacks)
1267  if (C(Name, MPM, InnerPipeline))
1268  return Error::success();
1269  return make_error<StringError>(
1270  formatv("unknown module pass '{0}'", Name).str(),
1272 }
1273 
1274 Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1275  const PipelineElement &E) {
1276  auto &Name = E.Name;
1277  auto &InnerPipeline = E.InnerPipeline;
1278 
1279  // First handle complex passes like the pass managers which carry pipelines.
1280  if (!InnerPipeline.empty()) {
1281  if (Name == "cgscc") {
1282  CGSCCPassManager NestedCGPM;
1283  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1284  return Err;
1285  // Add the nested pass manager with the appropriate adaptor.
1286  CGPM.addPass(std::move(NestedCGPM));
1287  return Error::success();
1288  }
1289  if (Name == "function" || Name == "function<eager-inv>") {
1290  FunctionPassManager FPM;
1291  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1292  return Err;
1293  // Add the nested pass manager with the appropriate adaptor.
1294  CGPM.addPass(
1295  createCGSCCToFunctionPassAdaptor(std::move(FPM), Name != "function"));
1296  return Error::success();
1297  }
1298  if (auto Count = parseRepeatPassName(Name)) {
1299  CGSCCPassManager NestedCGPM;
1300  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1301  return Err;
1302  CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1303  return Error::success();
1304  }
1305  if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1306  CGSCCPassManager NestedCGPM;
1307  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1308  return Err;
1309  CGPM.addPass(
1310  createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1311  return Error::success();
1312  }
1313 
1314  for (auto &C : CGSCCPipelineParsingCallbacks)
1315  if (C(Name, CGPM, InnerPipeline))
1316  return Error::success();
1317 
1318  // Normal passes can't have pipelines.
1319  return make_error<StringError>(
1320  formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1322  }
1323 
1324 // Now expand the basic registered passes from the .inc file.
1325 #define CGSCC_PASS(NAME, CREATE_PASS) \
1326  if (Name == NAME) { \
1327  CGPM.addPass(CREATE_PASS); \
1328  return Error::success(); \
1329  }
1330 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1331  if (checkParametrizedPassName(Name, NAME)) { \
1332  auto Params = parsePassParameters(PARSER, Name, NAME); \
1333  if (!Params) \
1334  return Params.takeError(); \
1335  CGPM.addPass(CREATE_PASS(Params.get())); \
1336  return Error::success(); \
1337  }
1338 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1339  if (Name == "require<" NAME ">") { \
1340  CGPM.addPass(RequireAnalysisPass< \
1341  std::remove_reference_t<decltype(CREATE_PASS)>, \
1342  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1343  CGSCCUpdateResult &>()); \
1344  return Error::success(); \
1345  } \
1346  if (Name == "invalidate<" NAME ">") { \
1347  CGPM.addPass(InvalidateAnalysisPass< \
1348  std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1349  return Error::success(); \
1350  }
1351 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1352  if (Name == NAME) { \
1353  CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
1354  return Error::success(); \
1355  }
1356 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1357  if (checkParametrizedPassName(Name, NAME)) { \
1358  auto Params = parsePassParameters(PARSER, Name, NAME); \
1359  if (!Params) \
1360  return Params.takeError(); \
1361  CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1362  return Error::success(); \
1363  }
1364 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1365  if (Name == NAME) { \
1366  CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1367  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1368  return Error::success(); \
1369  }
1370 #define LOOP_PASS(NAME, CREATE_PASS) \
1371  if (Name == NAME) { \
1372  CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1373  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1374  return Error::success(); \
1375  }
1376 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1377  if (checkParametrizedPassName(Name, NAME)) { \
1378  auto Params = parsePassParameters(PARSER, Name, NAME); \
1379  if (!Params) \
1380  return Params.takeError(); \
1381  CGPM.addPass( \
1382  createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1383  CREATE_PASS(Params.get()), false, false))); \
1384  return Error::success(); \
1385  }
1386 #include "PassRegistry.def"
1387 
1388  for (auto &C : CGSCCPipelineParsingCallbacks)
1389  if (C(Name, CGPM, InnerPipeline))
1390  return Error::success();
1391  return make_error<StringError>(
1392  formatv("unknown cgscc pass '{0}'", Name).str(),
1394 }
1395 
1396 Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1397  const PipelineElement &E) {
1398  auto &Name = E.Name;
1399  auto &InnerPipeline = E.InnerPipeline;
1400 
1401  // First handle complex passes like the pass managers which carry pipelines.
1402  if (!InnerPipeline.empty()) {
1403  if (Name == "function") {
1404  FunctionPassManager NestedFPM;
1405  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1406  return Err;
1407  // Add the nested pass manager with the appropriate adaptor.
1408  FPM.addPass(std::move(NestedFPM));
1409  return Error::success();
1410  }
1411  if (Name == "loop" || Name == "loop-mssa") {
1412  LoopPassManager LPM;
1413  if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
1414  return Err;
1415  // Add the nested pass manager with the appropriate adaptor.
1416  bool UseMemorySSA = (Name == "loop-mssa");
1417  bool UseBFI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1418  return Pipeline.Name.contains("simple-loop-unswitch");
1419  });
1420  bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1421  return Pipeline.Name == "loop-predication";
1422  });
1423  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
1424  UseBFI, UseBPI));
1425  return Error::success();
1426  }
1427  if (auto Count = parseRepeatPassName(Name)) {
1428  FunctionPassManager NestedFPM;
1429  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1430  return Err;
1431  FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1432  return Error::success();
1433  }
1434 
1435  for (auto &C : FunctionPipelineParsingCallbacks)
1436  if (C(Name, FPM, InnerPipeline))
1437  return Error::success();
1438 
1439  // Normal passes can't have pipelines.
1440  return make_error<StringError>(
1441  formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1443  }
1444 
1445 // Now expand the basic registered passes from the .inc file.
1446 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1447  if (Name == NAME) { \
1448  FPM.addPass(CREATE_PASS); \
1449  return Error::success(); \
1450  }
1451 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1452  if (checkParametrizedPassName(Name, NAME)) { \
1453  auto Params = parsePassParameters(PARSER, Name, NAME); \
1454  if (!Params) \
1455  return Params.takeError(); \
1456  FPM.addPass(CREATE_PASS(Params.get())); \
1457  return Error::success(); \
1458  }
1459 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1460  if (Name == "require<" NAME ">") { \
1461  FPM.addPass( \
1462  RequireAnalysisPass< \
1463  std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
1464  return Error::success(); \
1465  } \
1466  if (Name == "invalidate<" NAME ">") { \
1467  FPM.addPass(InvalidateAnalysisPass< \
1468  std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1469  return Error::success(); \
1470  }
1471 // FIXME: UseMemorySSA is set to false. Maybe we could do things like:
1472 // bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
1473 // "guard-widening");
1474 // The risk is that it may become obsolete if we're not careful.
1475 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1476  if (Name == NAME) { \
1477  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1478  return Error::success(); \
1479  }
1480 #define LOOP_PASS(NAME, CREATE_PASS) \
1481  if (Name == NAME) { \
1482  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1483  return Error::success(); \
1484  }
1485 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1486  if (checkParametrizedPassName(Name, NAME)) { \
1487  auto Params = parsePassParameters(PARSER, Name, NAME); \
1488  if (!Params) \
1489  return Params.takeError(); \
1490  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
1491  false, false)); \
1492  return Error::success(); \
1493  }
1494 #include "PassRegistry.def"
1495 
1496  for (auto &C : FunctionPipelineParsingCallbacks)
1497  if (C(Name, FPM, InnerPipeline))
1498  return Error::success();
1499  return make_error<StringError>(
1500  formatv("unknown function pass '{0}'", Name).str(),
1502 }
1503 
1504 Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
1505  const PipelineElement &E) {
1506  StringRef Name = E.Name;
1507  auto &InnerPipeline = E.InnerPipeline;
1508 
1509  // First handle complex passes like the pass managers which carry pipelines.
1510  if (!InnerPipeline.empty()) {
1511  if (Name == "loop") {
1512  LoopPassManager NestedLPM;
1513  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1514  return Err;
1515  // Add the nested pass manager with the appropriate adaptor.
1516  LPM.addPass(std::move(NestedLPM));
1517  return Error::success();
1518  }
1519  if (auto Count = parseRepeatPassName(Name)) {
1520  LoopPassManager NestedLPM;
1521  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1522  return Err;
1523  LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
1524  return Error::success();
1525  }
1526 
1527  for (auto &C : LoopPipelineParsingCallbacks)
1528  if (C(Name, LPM, InnerPipeline))
1529  return Error::success();
1530 
1531  // Normal passes can't have pipelines.
1532  return make_error<StringError>(
1533  formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
1535  }
1536 
1537 // Now expand the basic registered passes from the .inc file.
1538 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1539  if (Name == NAME) { \
1540  LPM.addPass(CREATE_PASS); \
1541  return Error::success(); \
1542  }
1543 #define LOOP_PASS(NAME, CREATE_PASS) \
1544  if (Name == NAME) { \
1545  LPM.addPass(CREATE_PASS); \
1546  return Error::success(); \
1547  }
1548 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1549  if (checkParametrizedPassName(Name, NAME)) { \
1550  auto Params = parsePassParameters(PARSER, Name, NAME); \
1551  if (!Params) \
1552  return Params.takeError(); \
1553  LPM.addPass(CREATE_PASS(Params.get())); \
1554  return Error::success(); \
1555  }
1556 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1557  if (Name == "require<" NAME ">") { \
1558  LPM.addPass(RequireAnalysisPass< \
1559  std::remove_reference_t<decltype(CREATE_PASS)>, Loop, \
1560  LoopAnalysisManager, LoopStandardAnalysisResults &, \
1561  LPMUpdater &>()); \
1562  return Error::success(); \
1563  } \
1564  if (Name == "invalidate<" NAME ">") { \
1565  LPM.addPass(InvalidateAnalysisPass< \
1566  std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1567  return Error::success(); \
1568  }
1569 #include "PassRegistry.def"
1570 
1571  for (auto &C : LoopPipelineParsingCallbacks)
1572  if (C(Name, LPM, InnerPipeline))
1573  return Error::success();
1574  return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
1576 }
1577 
1578 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
1579 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1580  if (Name == NAME) { \
1581  AA.registerModuleAnalysis< \
1582  std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1583  return true; \
1584  }
1585 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1586  if (Name == NAME) { \
1587  AA.registerFunctionAnalysis< \
1588  std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1589  return true; \
1590  }
1591 #include "PassRegistry.def"
1592 
1593  for (auto &C : AAParsingCallbacks)
1594  if (C(Name, AA))
1595  return true;
1596  return false;
1597 }
1598 
1599 Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
1600  ArrayRef<PipelineElement> Pipeline) {
1601  for (const auto &Element : Pipeline) {
1602  if (auto Err = parseLoopPass(LPM, Element))
1603  return Err;
1604  }
1605  return Error::success();
1606 }
1607 
1608 Error PassBuilder::parseFunctionPassPipeline(
1610  for (const auto &Element : Pipeline) {
1611  if (auto Err = parseFunctionPass(FPM, Element))
1612  return Err;
1613  }
1614  return Error::success();
1615 }
1616 
1617 Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1618  ArrayRef<PipelineElement> Pipeline) {
1619  for (const auto &Element : Pipeline) {
1620  if (auto Err = parseCGSCCPass(CGPM, Element))
1621  return Err;
1622  }
1623  return Error::success();
1624 }
1625 
1637 }
1638 
1639 Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1640  ArrayRef<PipelineElement> Pipeline) {
1641  for (const auto &Element : Pipeline) {
1642  if (auto Err = parseModulePass(MPM, Element))
1643  return Err;
1644  }
1645  return Error::success();
1646 }
1647 
1648 // Primary pass pipeline description parsing routine for a \c ModulePassManager
1649 // FIXME: Should this routine accept a TargetMachine or require the caller to
1650 // pre-populate the analysis managers with target-specific stuff?
1652  StringRef PipelineText) {
1653  auto Pipeline = parsePipelineText(PipelineText);
1654  if (!Pipeline || Pipeline->empty())
1655  return make_error<StringError>(
1656  formatv("invalid pipeline '{0}'", PipelineText).str(),
1658 
1659  // If the first name isn't at the module layer, wrap the pipeline up
1660  // automatically.
1661  StringRef FirstName = Pipeline->front().Name;
1662 
1663  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
1664  bool UseMemorySSA;
1665  if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
1666  Pipeline = {{"cgscc", std::move(*Pipeline)}};
1667  } else if (isFunctionPassName(FirstName,
1668  FunctionPipelineParsingCallbacks)) {
1669  Pipeline = {{"function", std::move(*Pipeline)}};
1670  } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
1671  UseMemorySSA)) {
1672  Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
1673  std::move(*Pipeline)}}}};
1674  } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
1675  UseMemorySSA)) {
1676  Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
1677  std::move(*Pipeline)}}}};
1678  } else {
1679  for (auto &C : TopLevelPipelineParsingCallbacks)
1680  if (C(MPM, *Pipeline))
1681  return Error::success();
1682 
1683  // Unknown pass or pipeline name!
1684  auto &InnerPipeline = Pipeline->front().InnerPipeline;
1685  return make_error<StringError>(
1686  formatv("unknown {0} name '{1}'",
1687  (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
1688  .str(),
1690  }
1691  }
1692 
1693  if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
1694  return Err;
1695  return Error::success();
1696 }
1697 
1698 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
1700  StringRef PipelineText) {
1701  auto Pipeline = parsePipelineText(PipelineText);
1702  if (!Pipeline || Pipeline->empty())
1703  return make_error<StringError>(
1704  formatv("invalid pipeline '{0}'", PipelineText).str(),
1706 
1707  StringRef FirstName = Pipeline->front().Name;
1708  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
1709  return make_error<StringError>(
1710  formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
1711  PipelineText)
1712  .str(),
1714 
1715  if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
1716  return Err;
1717  return Error::success();
1718 }
1719 
1720 // Primary pass pipeline description parsing routine for a \c
1721 // FunctionPassManager
1723  StringRef PipelineText) {
1724  auto Pipeline = parsePipelineText(PipelineText);
1725  if (!Pipeline || Pipeline->empty())
1726  return make_error<StringError>(
1727  formatv("invalid pipeline '{0}'", PipelineText).str(),
1729 
1730  StringRef FirstName = Pipeline->front().Name;
1731  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
1732  return make_error<StringError>(
1733  formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
1734  PipelineText)
1735  .str(),
1737 
1738  if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
1739  return Err;
1740  return Error::success();
1741 }
1742 
1743 // Primary pass pipeline description parsing routine for a \c LoopPassManager
1745  StringRef PipelineText) {
1746  auto Pipeline = parsePipelineText(PipelineText);
1747  if (!Pipeline || Pipeline->empty())
1748  return make_error<StringError>(
1749  formatv("invalid pipeline '{0}'", PipelineText).str(),
1751 
1752  if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
1753  return Err;
1754 
1755  return Error::success();
1756 }
1757 
1759  // If the pipeline just consists of the word 'default' just replace the AA
1760  // manager with our default one.
1761  if (PipelineText == "default") {
1762  AA = buildDefaultAAPipeline();
1763  return Error::success();
1764  }
1765 
1766  while (!PipelineText.empty()) {
1767  StringRef Name;
1768  std::tie(Name, PipelineText) = PipelineText.split(',');
1769  if (!parseAAPassName(AA, Name))
1770  return make_error<StringError>(
1771  formatv("unknown alias analysis name '{0}'", Name).str(),
1773  }
1774 
1775  return Error::success();
1776 }
1777 
1779  OS << " " << PassName << "\n";
1780 }
1782  raw_ostream &OS) {
1783  OS << " " << PassName << "<" << Params << ">\n";
1784 }
1785 
1787  // TODO: print pass descriptions when they are available
1788 
1789  OS << "Module passes:\n";
1790 #define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1791 #include "PassRegistry.def"
1792 
1793  OS << "Module passes with params:\n";
1794 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1795  printPassName(NAME, PARAMS, OS);
1796 #include "PassRegistry.def"
1797 
1798  OS << "Module analyses:\n";
1799 #define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1800 #include "PassRegistry.def"
1801 
1802  OS << "Module alias analyses:\n";
1803 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1804 #include "PassRegistry.def"
1805 
1806  OS << "CGSCC passes:\n";
1807 #define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1808 #include "PassRegistry.def"
1809 
1810  OS << "CGSCC passes with params:\n";
1811 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1812  printPassName(NAME, PARAMS, OS);
1813 #include "PassRegistry.def"
1814 
1815  OS << "CGSCC analyses:\n";
1816 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1817 #include "PassRegistry.def"
1818 
1819  OS << "Function passes:\n";
1820 #define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1821 #include "PassRegistry.def"
1822 
1823  OS << "Function passes with params:\n";
1824 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1825  printPassName(NAME, PARAMS, OS);
1826 #include "PassRegistry.def"
1827 
1828  OS << "Function analyses:\n";
1829 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1830 #include "PassRegistry.def"
1831 
1832  OS << "Function alias analyses:\n";
1833 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1834 #include "PassRegistry.def"
1835 
1836  OS << "LoopNest passes:\n";
1837 #define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1838 #include "PassRegistry.def"
1839 
1840  OS << "Loop passes:\n";
1841 #define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1842 #include "PassRegistry.def"
1843 
1844  OS << "Loop passes with params:\n";
1845 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1846  printPassName(NAME, PARAMS, OS);
1847 #include "PassRegistry.def"
1848 
1849  OS << "Loop analyses:\n";
1850 #define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1851 #include "PassRegistry.def"
1852 }
1853 
1856  &C) {
1857  TopLevelPipelineParsingCallbacks.push_back(C);
1858 }
llvm::GVNOptions
A set of parameters to control various transforms performed by GVN pass.
Definition: GVN.h:74
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
AddressSanitizer.h
RegionInfo.h
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
TypeBasedAliasAnalysis.h
llvm::PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & >
Definition: LoopPassManager.h:69
Instrumentation.h
SymbolRewriter.h
AssumptionCache.h
StackSafetyAnalysis.h
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:881
startsWithDefaultPipelineAliasPrefix
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name)
Tests whether a pass name starts with a valid prefix for a default pipeline alias.
Definition: PassBuilder.cpp:868
IROutliner.h
Lint.h
LowerWidenableCondition.h
DeadArgumentElimination.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LoopSimplify.h
DominanceFrontier.h
PassBuilder.h
StripSymbols.h
Mem2Reg.h
MemorySanitizer.h
llvm::OptimizationLevel::O1
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
Definition: OptimizationLevel.h:57
OpenMPOpt.h
PredicateInfo.h
CalledValuePropagation.h
Annotation2Metadata.h
PartialInlining.h
Inliner.h
BreakCriticalEdges.h
ThreadSanitizer.h
llvm::PassInfoMixin
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371
GlobalSplit.h
llvm::ModuleAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1168
llvm::StringRef::front
char front() const
front - Get the first character in the string.
Definition: StringRef.h:140
Debugify.h
CorrelatedValuePropagation.h
llvm::Function
Definition: Function.h:60
InstructionNamer.h
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:547
NaryReassociate.h
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:544
llvm::OptimizationLevel::O2
static const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
Definition: OptimizationLevel.h:74
InferAddressSpaces.h
name
static const char * name
Definition: SMEABIPass.cpp:49
LCSSA.h
ConstantMerge.h
AlignmentFromAssumptions.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
FunctionImport.h
CycleAnalysis.h
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1498
IndVarSimplify.h
ErrorHandling.h
LoopAccessAnalysis.h
InstCount.h
SCCP.h
UnifyFunctionExitNodes.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
TailRecursionElimination.h
DivRemPairs.h
DeadStoreElimination.h
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:37
llvm::StringRef::consume_front
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:627
OptimizationRemarkEmitter.h
CoroCleanup.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
GlobalsModRef.h
VectorCombine.h
MergeFunctions.h
llvm::ModuleAnalysisManagerCGSCCProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
Definition: CGSCCPassManager.h:215
IVUsersPrinter.h
LoopFlatten.h
ScalarEvolution.h
LoopAccessAnalysisPrinter.h
ElimAvailExtern.h
llvm::LoopUnrollOptions
A set of parameters used to control various transforms performed by the LoopUnroll pass.
Definition: LoopUnrollPass.h:61
IRPrintingPasses.h
InjectTLIMappings.h
ConstraintElimination.h
Float2Int.h
llvm::LoopStandardAnalysisResults
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
Definition: LoopAnalysisManager.h:51
CGProfile.h
isModulePassName
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:893
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
MetaRenamer.h
JumpThreading.h
HotColdSplitting.h
LoopUnrollAndJamPass.h
PartiallyInlineLibCalls.h
DivergenceAnalysis.h
llvm::StackLifetime::LivenessType::Must
@ Must
FixIrreducible.h
LazyValueInfo.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::createCGSCCToFunctionPassAdaptor
CGSCCToFunctionPassAdaptor createCGSCCToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false, bool NoRerun=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: CGSCCPassManager.h:509
LoopInstSimplify.h
MemoryDependenceAnalysis.h
ModuleSummaryAnalysis.h
LoopBoundSplit.h
StripDeadPrototypes.h
llvm::OptimizationLevel::O0
static const OptimizationLevel O0
Disable as many optimizations as possible.
Definition: OptimizationLevel.h:41
BasicAliasAnalysis.h
DataFlowSanitizer.h
llvm::Regex::match
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition: Regex.cpp:86
CoroElide.h
llvm::LoopUnrollOptions::setPartial
LoopUnrollOptions & setPartial(bool Partial)
Enables or disables partial unrolling.
Definition: LoopUnrollPass.h:87
Internalize.h
MergedLoadStoreMotion.h
llvm::LoopVectorizeOptions::setInterleaveOnlyWhenForced
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
Definition: LoopVectorize.h:140
MustExecute.h
F
#define F(x, y, z)
Definition: MD5.cpp:55
isLoopNestPassName
static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks, bool &UseMemorySSA)
Definition: PassBuilder.cpp:981
Scalarizer.h
llvm::PassBuilder::parsePassPipeline
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
Definition: PassBuilder.cpp:1651
CommandLine.h
LoopRotation.h
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
Reg2Mem.h
StackLifetime.h
TargetMachine.h
llvm::PrintPipelinePasses
cl::opt< bool > PrintPipelinePasses("print-pipeline-passes", cl::desc("Print a '-passes' compatible string describing the pipeline " "(best-effort only)."))
llvm::LazyCallGraph::SCC
An SCC of the call graph.
Definition: LazyCallGraph.h:419
llvm::LoopUnrollOptions::setPeeling
LoopUnrollOptions & setPeeling(bool Peeling)
Enables or disables loop peeling.
Definition: LoopUnrollPass.h:99
AlwaysInliner.h
InstrProfiling.h
PostDominators.h
FlattenCFG.h
LoopIdiomRecognize.h
HWAddressSanitizer.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
HelloWorld.h
ArgumentPromotion.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
BlockExtractor.h
MAM
ModuleAnalysisManager MAM
Definition: PassBuilderBindings.cpp:61
llvm::CGSCCAnalysisManagerModuleProxy
InnerAnalysisManagerProxy< CGSCCAnalysisManager, Module > CGSCCAnalysisManagerModuleProxy
A proxy from a CGSCCAnalysisManager to a Module.
Definition: CGSCCPassManager.h:168
LowerInvoke.h
isFunctionPassName
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:955
AggressiveInstCombine.h
llvm::StringRef::getAsInteger
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:474
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
TargetLibraryInfo.h
RewriteStatepointsForGC.h
AssumeBundleBuilder.h
LowerSwitch.h
InlineAdvisor.h
StructurizeCFG.h
llvm::createRepeatedPass
RepeatedPass< PassT > createRepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1353
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
MemCpyOptimizer.h
llvm::createDevirtSCCRepeatedPass
DevirtSCCRepeatedPass createDevirtSCCRepeatedPass(CGSCCPassT &&Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: CGSCCPassManager.h:581
GVN.h
ConstantHoisting.h
LazyCallGraph.h
CFLAndersAliasAnalysis.h
FormatVariadic.h
llvm::PassBuilder::buildThinLTOPreLinkDefaultPipeline
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1440
TLSVariableHoist.h
PrintPasses.h
ScopedNoAliasAA.h
CanonicalizeFreezeInLoops.h
ControlHeightReduction.h
InstSimplifyPass.h
llvm::dxil::PointerTypeAnalysis::run
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
Definition: PointerTypeAnalysis.cpp:189
LoopInfo.h
LoopFuse.h
SROA.h
SampleProfile.h
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
MakeGuardsExplicit.h
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::StackLifetime::LivenessType::May
@ May
ForceFunctionAttrs.h
llvm::cl::opt< bool >
Attributor.h
LoadStoreVectorizer.h
llvm::createModuleToFunctionPassAdaptor
ModuleToFunctionPassAdaptor createModuleToFunctionPassAdaptor(FunctionPassT &&Pass, bool EagerlyInvalidate=false)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: PassManager.h:1218
LowerGlobalDtors.h
SpeculativeExecution.h
checkParametrizedPassName
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
Definition: PassBuilder.cpp:493
InlineSizeEstimatorAnalysis.h
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:452
CallPrinter.h
BranchProbabilityInfo.h
EarlyCSE.h
CrossDSOCFI.h
CFGPrinter.h
GCOVProfiler.h
ProfileSummaryInfo.h
DefaultAliasRegex
static const Regex DefaultAliasRegex("^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$")
ModuleInliner.h
llvm::LPMUpdater
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Definition: LoopPassManager.h:262
CoroSplit.h
CFGSCCPrinter.h
BoundsChecking.h
StripGCRelocates.h
llvm::PassBuilder::buildLTOPreLinkDefaultPipeline
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1555
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:434
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
PGOInstrumentation.h
CGSCCPassManager.h
llvm::AnalysisKey
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: PassManager.h:69
DebugInfo.h
llvm::PassBuilder::buildLTODefaultPipeline
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1564
UseBFI
UseBFI
Definition: MachineLICM.cpp:83
LowerExpectIntrinsic.h
DomPrinter.h
llvm::PassBuilder::buildThinLTODefaultPipeline
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1498
ADCE.h
llvm::OptimizationLevel::Oz
static const OptimizationLevel Oz
A very specialized mode that will optimize for code size at any and all costs.
Definition: OptimizationLevel.h:108
llvm::PassBuilder::buildDefaultAAPipeline
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Definition: PassBuilderPipelines.cpp:1966
InferFunctionAttrs.h
SimpleLoopUnswitch.h
Enable
@ Enable
Definition: DwarfDebug.cpp:86
llvm::createFunctionToLoopPassAdaptor
std::enable_if_t< is_detected< HasRunOnLoopT, LoopPassT >::value, FunctionToLoopPassAdaptor > createFunctionToLoopPassAdaptor(LoopPassT &&Pass, bool UseMemorySSA=false, bool UseBlockFrequencyInfo=false, bool UseBranchProbabilityInfo=false)
A function to deduce a loop pass type and wrap it in the templated adaptor.
Definition: LoopPassManager.h:481
llvm::StackLifetime::LivenessType
LivenessType
Definition: StackLifetime.h:83
SeparateConstOffsetFromGEP.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::PassBuilder::printPassNames
void printPassNames(raw_ostream &OS)
Print pass names.
Definition: PassBuilder.cpp:1786
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
Regex.h
MemDerefPrinter.h
llvm::PipelineTuningOptions::SLPVectorization
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:52
Reassociate.h
llvm::FunctionAnalysisManagerLoopProxy
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
Definition: LoopAnalysisManager.h:156
SafepointIRVerifier.h
GuardWidening.h
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
LowerAtomicPass.h
LoopNestAnalysis.h
llvm::printBeforePasses
std::vector< std::string > printBeforePasses()
Definition: PrintPasses.cpp:134
ObjCARCAliasAnalysis.h
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
SampleProfileProbe.h
LoopPassManager.h
InductiveRangeCheckElimination.h
ModuleDebugInfoPrinter.h
llvm::AnalysisInfoMixin
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:394
NameAnonGlobals.h
LowerMatrixIntrinsics.h
llvm::printAfterPasses
std::vector< std::string > printAfterPasses()
Definition: PrintPasses.cpp:138
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
LoopInterchange.h
llvm::PassBuilder::PassBuilder
PassBuilder(TargetMachine *TM=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions(), std::optional< PGOOptions > PGOOpt=std::nullopt, PassInstrumentationCallbacks *PIC=nullptr)
Definition: PassBuilder.cpp:397
LoopExtractor.h
SyntheticCountsPropagation.h
DDG.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
CanonicalizeAliases.h
LibCallsShrinkWrap.h
llvm::CoroConditionalWrapper
Definition: CoroConditionalWrapper.h:20
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1741
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
SanitizerCoverage.h
llvm::LoopAnalysisManagerFunctionProxy
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Definition: LoopAnalysisManager.h:79
GlobalDCE.h
llvm::PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & >::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
Definition: LoopPassManager.h:107
llvm::LICMOptions
Definition: LICM.h:48
llvm::OptimizationLevel::O3
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
Definition: OptimizationLevel.h:89
llvm::LoopVectorizeOptions::setVectorizeOnlyWhenForced
LoopVectorizeOptions & setVectorizeOnlyWhenForced(bool Value)
Definition: LoopVectorize.h:145
llvm::PipelineTuningOptions::LoopVectorization
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:48
NewGVN.h
KCFI.h
llvm::LoopUnrollOptions::setFullUnrollMaxCount
LoopUnrollOptions & setFullUnrollMaxCount(unsigned O)
Definition: LoopUnrollPass.h:124
LowerTypeTests.h
CoroConditionalWrapper.h
BlockFrequencyInfo.h
CallSiteSplitting.h
llvm::LoopVectorizeOptions
Definition: LoopVectorize.h:115
LoopSimplifyCFG.h
AnnotationRemarks.h
CostModel.h
LAM
LoopAnalysisManager LAM
Definition: PassBuilderBindings.cpp:58
llvm::PassBuilder::parseAAPipeline
Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
Definition: PassBuilder.cpp:1758
LoopVectorize.h
SCCP.h
DemandedBits.h
parseDevirtPassName
static std::optional< int > parseDevirtPassName(StringRef Name)
Definition: PassBuilder.cpp:484
llvm::PassManager< Module >
MergeICmps.h
LoopVersioningLICM.h
callbacksAcceptPassName
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks)
Tests whether registered callbacks will accept a given pass name.
Definition: PassBuilder.cpp:882
FunctionPropertiesAnalysis.h
PhiValues.h
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:466
StraightLineStrengthReduce.h
llvm::OptimizationLevel::getSpeedupLevel
unsigned getSpeedupLevel() const
Definition: OptimizationLevel.h:121
SLPVectorizer.h
llvm::CGSCCUpdateResult
Support structure for SCC passes to communicate updates the call graph back to the CGSCC pass manager...
Definition: CGSCCPassManager.h:232
LoopLoadElimination.h
llvm::CGSCCAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
Definition: CGSCCPassManager.h:427
Verifier.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
LoopStrengthReduce.h
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::HWAddressSanitizerOptions
Definition: HWAddressSanitizer.h:24
llvm::PassBuilder::buildPerModuleDefaultPipeline
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build a per-module default optimization pipeline.
Definition: PassBuilderPipelines.cpp:1397
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
LoopUnrollPass.h
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::OptimizationLevel::Os
static const OptimizationLevel Os
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
Definition: OptimizationLevel.h:100
IRSimilarityIdentifier.h
UnifyLoopExits.h
llvm::PassBuilder::registerCGSCCAnalyses
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
Definition: PassBuilder.cpp:443
llvm::OptimizationLevel
Definition: OptimizationLevel.h:22
PassManager.h
LowerConstantIntrinsics.h
ScalarEvolutionAliasAnalysis.h
StringSwitch.h
ScalarizeMaskedMemIntrin.h
llvm::PassBuilder::buildO0DefaultPipeline
ModulePassManager buildO0DefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build an O0 pipeline with the minimal semantically required passes.
Definition: PassBuilderPipelines.cpp:1858
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:836
Sink.h
LoopVersioning.h
WholeProgramDevirt.h
LowerGuardIntrinsic.h
LoopDistribute.h
llvm::LoopUnrollOptions::setRuntime
LoopUnrollOptions & setRuntime(bool Runtime)
Enables or disables unrolling of loops with runtime trip count.
Definition: LoopUnrollPass.h:93
CallGraph.h
WarnMissedTransforms.h
LoopReroll.h
DDGPrinter.h
llvm::SimplifyCFGOptions
Definition: SimplifyCFGOptions.h:23
MemorySSA.h
AliasAnalysisEvaluator.h
GlobalOpt.h
LoopSink.h
IVUsers.h
ObjCARC.h
isLoopPassName
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks, bool &UseMemorySSA)
Definition: PassBuilder.cpp:1003
llvm::PassInstrumentationCallbacks
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Definition: PassInstrumentation.h:66
Dominators.h
llvm::StringRef::consume_back
bool consume_back(StringRef Suffix)
Returns true if this StringRef has the given suffix and removes that suffix.
Definition: StringRef.h:647
StripNonLineTableDebugInfo.h
llvm::PassBuilder::crossRegisterProxies
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM)
Cross register the analysis managers through their proxies.
Definition: PassBuilder.cpp:1626
llvm::LoopUnrollOptions::setOptLevel
LoopUnrollOptions & setOptLevel(int O)
Definition: LoopUnrollPass.h:112
LoopDeletion.h
SanitizerBinaryMetadata.h
MemProfiler.h
TargetTransformInfo.h
llvm::MemorySanitizerOptions
Definition: MemorySanitizer.h:24
Delinearization.h
LICM.h
LoopCacheAnalysis.h
CoroEarly.h
llvm::StringSwitch::Default
R Default(T Value)
Definition: StringSwitch.h:182
llvm::LoopUnrollOptions::setProfileBasedPeeling
LoopUnrollOptions & setProfileBasedPeeling(int O)
Definition: LoopUnrollPass.h:118
llvm::StringSwitch
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
llvm::logicalview::LVOutputKind::Text
@ Text
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
DCE.h
AliasSetTracker.h
llvm::isFilterPassesEmpty
bool isFilterPassesEmpty()
Definition: PrintPasses.cpp:150
BDCE.h
InstrOrderFile.h
InstCombine.h
DependenceAnalysis.h
parseRepeatPassName
static std::optional< int > parseRepeatPassName(StringRef Name)
Definition: PassBuilder.cpp:475
abort
*Add support for compiling functions in both ARM and Thumb then taking the smallest *Add support for compiling individual basic blocks in thumb when in a larger ARM function This can be used for presumed cold like paths to abort(failure path of asserts)
llvm::cl::desc
Definition: CommandLine.h:412
llvm::Regex
Definition: Regex.h:28
llvm::LazyCallGraph
A lazily constructed view of the call graph of a module.
Definition: LazyCallGraph.h:110
LoopPredication.h
EntryExitInstrumenter.h
SimplifyCFG.h
llvm::PassBuilder::registerParseTopLevelPipelineCallback
void registerParseTopLevelPipelineCallback(const std::function< bool(ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Register a callback for a top-level pipeline entry.
Definition: PassBuilder.cpp:1854
PoisonChecking.h
MPM
ModulePassManager MPM
Definition: PassBuilderBindings.cpp:70
llvm::createModuleToPostOrderCGSCCPassAdaptor
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
Definition: CGSCCPassManager.h:373
llvm::LoopNest
This class represents a loop nest and can be used to query its properties.
Definition: LoopNestAnalysis.h:28
llvm::StringRef::split
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:692
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
llvm::FunctionAnalysisManagerModuleProxy
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1014
FunctionAttrs.h
Debug.h
isCGSCCPassName
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:927
RelLookupTableConverter.h
llvm::AddressSanitizerOptions
Definition: AddressSanitizer.h:23
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:671
CFLSteensAliasAnalysis.h
llvm::LoopUnrollOptions::setUpperBound
LoopUnrollOptions & setUpperBound(bool UpperBound)
Enables or disables the use of trip count upper bound in loop unrolling.
Definition: LoopUnrollPass.h:106
LoopDataPrefetch.h
printPassName
static void printPassName(StringRef PassName, raw_ostream &OS)
Definition: PassBuilder.cpp:1778
AddDiscriminators.h
DFAJumpThreading.h