LLVM  14.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"
32 #include "llvm/Analysis/DDG.h"
43 #include "llvm/Analysis/IVUsers.h"
49 #include "llvm/Analysis/Lint.h"
52 #include "llvm/Analysis/LoopInfo.h"
74 #include "llvm/IR/Dominators.h"
76 #include "llvm/IR/PassManager.h"
77 #include "llvm/IR/PrintPasses.h"
79 #include "llvm/IR/Verifier.h"
81 #include "llvm/Support/Debug.h"
84 #include "llvm/Support/Regex.h"
142 #include "llvm/Transforms/ObjCARC.h"
246 
247 using namespace llvm;
248 
249 static const Regex DefaultAliasRegex(
250  "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
251 
252 namespace llvm {
254  "print-pipeline-passes",
255  cl::desc("Print a '-passes' compatible string describing the pipeline "
256  "(best-effort only)."));
257 } // namespace llvm
258 
259 namespace {
260 
261 // The following passes/analyses have custom names, otherwise their name will
262 // include `(anonymous namespace)`. These are special since they are only for
263 // testing purposes and don't live in a header file.
264 
265 /// No-op module pass which does nothing.
266 struct NoOpModulePass : PassInfoMixin<NoOpModulePass> {
268  return PreservedAnalyses::all();
269  }
270 
271  static StringRef name() { return "NoOpModulePass"; }
272 };
273 
274 /// No-op module analysis.
275 class NoOpModuleAnalysis : public AnalysisInfoMixin<NoOpModuleAnalysis> {
277  static AnalysisKey Key;
278 
279 public:
280  struct Result {};
281  Result run(Module &, ModuleAnalysisManager &) { return Result(); }
282  static StringRef name() { return "NoOpModuleAnalysis"; }
283 };
284 
285 /// No-op CGSCC pass which does nothing.
286 struct NoOpCGSCCPass : PassInfoMixin<NoOpCGSCCPass> {
289  return PreservedAnalyses::all();
290  }
291  static StringRef name() { return "NoOpCGSCCPass"; }
292 };
293 
294 /// No-op CGSCC analysis.
295 class NoOpCGSCCAnalysis : public AnalysisInfoMixin<NoOpCGSCCAnalysis> {
297  static AnalysisKey Key;
298 
299 public:
300  struct Result {};
302  return Result();
303  }
304  static StringRef name() { return "NoOpCGSCCAnalysis"; }
305 };
306 
307 /// No-op function pass which does nothing.
308 struct NoOpFunctionPass : PassInfoMixin<NoOpFunctionPass> {
310  return PreservedAnalyses::all();
311  }
312  static StringRef name() { return "NoOpFunctionPass"; }
313 };
314 
315 /// No-op function analysis.
316 class NoOpFunctionAnalysis : public AnalysisInfoMixin<NoOpFunctionAnalysis> {
318  static AnalysisKey Key;
319 
320 public:
321  struct Result {};
322  Result run(Function &, FunctionAnalysisManager &) { return Result(); }
323  static StringRef name() { return "NoOpFunctionAnalysis"; }
324 };
325 
326 /// No-op loop nest pass which does nothing.
327 struct NoOpLoopNestPass : PassInfoMixin<NoOpLoopNestPass> {
330  return PreservedAnalyses::all();
331  }
332  static StringRef name() { return "NoOpLoopNestPass"; }
333 };
334 
335 /// No-op loop pass which does nothing.
336 struct NoOpLoopPass : PassInfoMixin<NoOpLoopPass> {
339  return PreservedAnalyses::all();
340  }
341  static StringRef name() { return "NoOpLoopPass"; }
342 };
343 
344 /// No-op loop analysis.
345 class NoOpLoopAnalysis : public AnalysisInfoMixin<NoOpLoopAnalysis> {
347  static AnalysisKey Key;
348 
349 public:
350  struct Result {};
352  return Result();
353  }
354  static StringRef name() { return "NoOpLoopAnalysis"; }
355 };
356 
361 
362 /// Whether or not we should populate a PassInstrumentationCallbacks's class to
363 /// pass name map.
364 ///
365 /// This is for optimization purposes so we don't populate it if we never use
366 /// it. This should be updated if new pass instrumentation wants to use the map.
367 /// We currently only use this for --print-before/after.
368 bool shouldPopulateClassToPassNames() {
369  return PrintPipelinePasses || !printBeforePasses().empty() ||
370  !printAfterPasses().empty();
371 }
372 
373 } // namespace
374 
376  Optional<PGOOptions> PGOOpt,
378  : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
379  if (TM)
380  TM->registerPassBuilderCallbacks(*this);
381  if (PIC && shouldPopulateClassToPassNames()) {
382 #define MODULE_PASS(NAME, CREATE_PASS) \
383  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
384 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
385  PIC->addClassToPassName(CLASS, NAME);
386 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
387  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
388 #define FUNCTION_PASS(NAME, CREATE_PASS) \
389  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
390 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
391  PIC->addClassToPassName(CLASS, NAME);
392 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
393  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
394 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
395  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
396 #define LOOP_PASS(NAME, CREATE_PASS) \
397  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
398 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
399  PIC->addClassToPassName(CLASS, NAME);
400 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
401  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
402 #define CGSCC_PASS(NAME, CREATE_PASS) \
403  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
404 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
405  PIC->addClassToPassName(CLASS, NAME);
406 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
407  PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
408 #include "PassRegistry.def"
409  }
410 }
411 
413 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
414  MAM.registerPass([&] { return CREATE_PASS; });
415 #include "PassRegistry.def"
416 
417  for (auto &C : ModuleAnalysisRegistrationCallbacks)
418  C(MAM);
419 }
420 
422 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
423  CGAM.registerPass([&] { return CREATE_PASS; });
424 #include "PassRegistry.def"
425 
426  for (auto &C : CGSCCAnalysisRegistrationCallbacks)
427  C(CGAM);
428 }
429 
431  // We almost always want the default alias analysis pipeline.
432  // If a user wants a different one, they can register their own before calling
433  // registerFunctionAnalyses().
434  FAM.registerPass([&] { return buildDefaultAAPipeline(); });
435 
436 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
437  FAM.registerPass([&] { return CREATE_PASS; });
438 #include "PassRegistry.def"
439 
440  for (auto &C : FunctionAnalysisRegistrationCallbacks)
441  C(FAM);
442 }
443 
445 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
446  LAM.registerPass([&] { return CREATE_PASS; });
447 #include "PassRegistry.def"
448 
449  for (auto &C : LoopAnalysisRegistrationCallbacks)
450  C(LAM);
451 }
452 
454  if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
455  return None;
456  int Count;
457  if (Name.getAsInteger(0, Count) || Count <= 0)
458  return None;
459  return Count;
460 }
461 
463  if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
464  return None;
465  int Count;
466  if (Name.getAsInteger(0, Count) || Count < 0)
467  return None;
468  return Count;
469 }
470 
472  if (!Name.consume_front(PassName))
473  return false;
474  // normal pass name w/o parameters == default parameters
475  if (Name.empty())
476  return true;
477  return Name.startswith("<") && Name.endswith(">");
478 }
479 
480 namespace {
481 
482 /// This performs customized parsing of pass name with parameters.
483 ///
484 /// We do not need parametrization of passes in textual pipeline very often,
485 /// yet on a rare occasion ability to specify parameters right there can be
486 /// useful.
487 ///
488 /// \p Name - parameterized specification of a pass from a textual pipeline
489 /// is a string in a form of :
490 /// PassName '<' parameter-list '>'
491 ///
492 /// Parameter list is being parsed by the parser callable argument, \p Parser,
493 /// It takes a string-ref of parameters and returns either StringError or a
494 /// parameter list in a form of a custom parameters type, all wrapped into
495 /// Expected<> template class.
496 ///
497 template <typename ParametersParseCallableT>
498 auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
499  StringRef PassName) -> decltype(Parser(StringRef{})) {
500  using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
501 
502  StringRef Params = Name;
503  if (!Params.consume_front(PassName)) {
504  assert(false &&
505  "unable to strip pass name from parametrized pass specification");
506  }
507  if (!Params.empty() &&
508  (!Params.consume_front("<") || !Params.consume_back(">"))) {
509  assert(false && "invalid format for parametrized pass name");
510  }
511 
512  Expected<ParametersT> Result = Parser(Params);
513  assert((Result || Result.template errorIsA<StringError>()) &&
514  "Pass parameter parser can only return StringErrors.");
515  return Result;
516 }
517 
518 /// Parser of parameters for LoopUnroll pass.
519 Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
520  LoopUnrollOptions UnrollOpts;
521  while (!Params.empty()) {
522  StringRef ParamName;
523  std::tie(ParamName, Params) = Params.split(';');
524  int OptLevel = StringSwitch<int>(ParamName)
525  .Case("O0", 0)
526  .Case("O1", 1)
527  .Case("O2", 2)
528  .Case("O3", 3)
529  .Default(-1);
530  if (OptLevel >= 0) {
531  UnrollOpts.setOptLevel(OptLevel);
532  continue;
533  }
534  if (ParamName.consume_front("full-unroll-max=")) {
535  int Count;
536  if (ParamName.getAsInteger(0, Count))
537  return make_error<StringError>(
538  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
540  UnrollOpts.setFullUnrollMaxCount(Count);
541  continue;
542  }
543 
544  bool Enable = !ParamName.consume_front("no-");
545  if (ParamName == "partial") {
546  UnrollOpts.setPartial(Enable);
547  } else if (ParamName == "peeling") {
548  UnrollOpts.setPeeling(Enable);
549  } else if (ParamName == "profile-peeling") {
550  UnrollOpts.setProfileBasedPeeling(Enable);
551  } else if (ParamName == "runtime") {
552  UnrollOpts.setRuntime(Enable);
553  } else if (ParamName == "upperbound") {
554  UnrollOpts.setUpperBound(Enable);
555  } else {
556  return make_error<StringError>(
557  formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
559  }
560  }
561  return UnrollOpts;
562 }
563 
564 Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
566  bool Result = false;
567  while (!Params.empty()) {
568  StringRef ParamName;
569  std::tie(ParamName, Params) = Params.split(';');
570 
571  if (ParamName == OptionName) {
572  Result = true;
573  } else {
574  return make_error<StringError>(
575  formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
576  .str(),
578  }
579  }
580  return Result;
581 }
582 
583 Expected<bool> parseInlinerPassOptions(StringRef Params) {
584  return parseSinglePassOption(Params, "only-mandatory", "InlinerPass");
585 }
586 
587 Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
588  return parseSinglePassOption(Params, "memssa", "EarlyCSE");
589 }
590 
591 Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
592  return parseSinglePassOption(Params, "post-inline", "EntryExitInstrumenter");
593 }
594 
595 Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
596  return parseSinglePassOption(Params, "single", "LoopExtractor");
597 }
598 
599 Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
600  return parseSinglePassOption(Params, "minimal", "LowerMatrixIntrinsics");
601 }
602 
603 Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
605  while (!Params.empty()) {
606  StringRef ParamName;
607  std::tie(ParamName, Params) = Params.split(';');
608 
609  if (ParamName == "kernel") {
610  Result.CompileKernel = true;
611  } else {
612  return make_error<StringError>(
613  formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName)
614  .str(),
616  }
617  }
618  return Result;
619 }
620 
621 Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
623  while (!Params.empty()) {
624  StringRef ParamName;
625  std::tie(ParamName, Params) = Params.split(';');
626 
627  if (ParamName == "recover") {
628  Result.Recover = true;
629  } else if (ParamName == "kernel") {
630  Result.CompileKernel = true;
631  } else {
632  return make_error<StringError>(
633  formatv("invalid HWAddressSanitizer pass parameter '{0}' ", ParamName)
634  .str(),
636  }
637  }
638  return Result;
639 }
640 
641 Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
643  while (!Params.empty()) {
644  StringRef ParamName;
645  std::tie(ParamName, Params) = Params.split(';');
646 
647  if (ParamName == "recover") {
648  Result.Recover = true;
649  } else if (ParamName == "kernel") {
650  Result.Kernel = true;
651  } else if (ParamName.consume_front("track-origins=")) {
652  if (ParamName.getAsInteger(0, Result.TrackOrigins))
653  return make_error<StringError>(
654  formatv("invalid argument to MemorySanitizer pass track-origins "
655  "parameter: '{0}' ",
656  ParamName)
657  .str(),
659  } else if (ParamName == "eager-checks") {
660  Result.EagerChecks = true;
661  } else {
662  return make_error<StringError>(
663  formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
664  .str(),
666  }
667  }
668  return Result;
669 }
670 
671 /// Parser of parameters for SimplifyCFG pass.
672 Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
674  while (!Params.empty()) {
675  StringRef ParamName;
676  std::tie(ParamName, Params) = Params.split(';');
677 
678  bool Enable = !ParamName.consume_front("no-");
679  if (ParamName == "forward-switch-cond") {
680  Result.forwardSwitchCondToPhi(Enable);
681  } else if (ParamName == "switch-to-lookup") {
682  Result.convertSwitchToLookupTable(Enable);
683  } else if (ParamName == "keep-loops") {
684  Result.needCanonicalLoops(Enable);
685  } else if (ParamName == "hoist-common-insts") {
686  Result.hoistCommonInsts(Enable);
687  } else if (ParamName == "sink-common-insts") {
688  Result.sinkCommonInsts(Enable);
689  } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
690  APInt BonusInstThreshold;
691  if (ParamName.getAsInteger(0, BonusInstThreshold))
692  return make_error<StringError>(
693  formatv("invalid argument to SimplifyCFG pass bonus-threshold "
694  "parameter: '{0}' ",
695  ParamName).str(),
697  Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
698  } else {
699  return make_error<StringError>(
700  formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
702  }
703  }
704  return Result;
705 }
706 
707 /// Parser of parameters for LoopVectorize pass.
708 Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
710  while (!Params.empty()) {
711  StringRef ParamName;
712  std::tie(ParamName, Params) = Params.split(';');
713 
714  bool Enable = !ParamName.consume_front("no-");
715  if (ParamName == "interleave-forced-only") {
716  Opts.setInterleaveOnlyWhenForced(Enable);
717  } else if (ParamName == "vectorize-forced-only") {
718  Opts.setVectorizeOnlyWhenForced(Enable);
719  } else {
720  return make_error<StringError>(
721  formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
723  }
724  }
725  return Opts;
726 }
727 
728 Expected<std::pair<bool, bool>> parseLoopUnswitchOptions(StringRef Params) {
729  std::pair<bool, bool> Result = {false, true};
730  while (!Params.empty()) {
731  StringRef ParamName;
732  std::tie(ParamName, Params) = Params.split(';');
733 
734  bool Enable = !ParamName.consume_front("no-");
735  if (ParamName == "nontrivial") {
736  Result.first = Enable;
737  } else if (ParamName == "trivial") {
738  Result.second = Enable;
739  } else {
740  return make_error<StringError>(
741  formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
742  .str(),
744  }
745  }
746  return Result;
747 }
748 
749 Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
750  bool Result = false;
751  while (!Params.empty()) {
752  StringRef ParamName;
753  std::tie(ParamName, Params) = Params.split(';');
754 
755  bool Enable = !ParamName.consume_front("no-");
756  if (ParamName == "split-footer-bb") {
757  Result = Enable;
758  } else {
759  return make_error<StringError>(
760  formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ",
761  ParamName)
762  .str(),
764  }
765  }
766  return Result;
767 }
768 
769 Expected<GVNOptions> parseGVNOptions(StringRef Params) {
771  while (!Params.empty()) {
772  StringRef ParamName;
773  std::tie(ParamName, Params) = Params.split(';');
774 
775  bool Enable = !ParamName.consume_front("no-");
776  if (ParamName == "pre") {
777  Result.setPRE(Enable);
778  } else if (ParamName == "load-pre") {
779  Result.setLoadPRE(Enable);
780  } else if (ParamName == "split-backedge-load-pre") {
781  Result.setLoadPRESplitBackedge(Enable);
782  } else if (ParamName == "memdep") {
783  Result.setMemDep(Enable);
784  } else {
785  return make_error<StringError>(
786  formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
788  }
789  }
790  return Result;
791 }
792 
794 parseStackLifetimeOptions(StringRef Params) {
796  while (!Params.empty()) {
797  StringRef ParamName;
798  std::tie(ParamName, Params) = Params.split(';');
799 
800  if (ParamName == "may") {
802  } else if (ParamName == "must") {
804  } else {
805  return make_error<StringError>(
806  formatv("invalid StackLifetime parameter '{0}' ", ParamName).str(),
808  }
809  }
810  return Result;
811 }
812 
813 } // namespace
814 
815 /// Tests whether a pass name starts with a valid prefix for a default pipeline
816 /// alias.
818  return Name.startswith("default") || Name.startswith("thinlto") ||
819  Name.startswith("lto");
820 }
821 
822 /// Tests whether registered callbacks will accept a given pass name.
823 ///
824 /// When parsing a pipeline text, the type of the outermost pipeline may be
825 /// omitted, in which case the type is automatically determined from the first
826 /// pass name in the text. This may be a name that is handled through one of the
827 /// callbacks. We check this through the oridinary parsing callbacks by setting
828 /// up a dummy PassManager in order to not force the client to also handle this
829 /// type of query.
830 template <typename PassManagerT, typename CallbacksT>
831 static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
832  if (!Callbacks.empty()) {
833  PassManagerT DummyPM;
834  for (auto &CB : Callbacks)
835  if (CB(Name, DummyPM, {}))
836  return true;
837  }
838  return false;
839 }
840 
841 template <typename CallbacksT>
842 static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
843  // Manually handle aliases for pre-configured pipeline fragments.
845  return DefaultAliasRegex.match(Name);
846 
847  // Explicitly handle pass manager names.
848  if (Name == "module")
849  return true;
850  if (Name == "cgscc")
851  return true;
852  if (Name == "function" || Name == "function<eager-inv>")
853  return true;
854 
855  // Explicitly handle custom-parsed pass names.
857  return true;
858 
859 #define MODULE_PASS(NAME, CREATE_PASS) \
860  if (Name == NAME) \
861  return true;
862 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
863  if (checkParametrizedPassName(Name, NAME)) \
864  return true;
865 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
866  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
867  return true;
868 #include "PassRegistry.def"
869 
870  return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
871 }
872 
873 template <typename CallbacksT>
874 static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
875  // Explicitly handle pass manager names.
876  if (Name == "cgscc")
877  return true;
878  if (Name == "function" || Name == "function<eager-inv>")
879  return true;
880 
881  // Explicitly handle custom-parsed pass names.
883  return true;
885  return true;
886 
887 #define CGSCC_PASS(NAME, CREATE_PASS) \
888  if (Name == NAME) \
889  return true;
890 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
891  if (checkParametrizedPassName(Name, NAME)) \
892  return true;
893 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
894  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
895  return true;
896 #include "PassRegistry.def"
897 
898  return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
899 }
900 
901 template <typename CallbacksT>
902 static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
903  // Explicitly handle pass manager names.
904  if (Name == "function" || Name == "function<eager-inv>")
905  return true;
906  if (Name == "loop" || Name == "loop-mssa")
907  return true;
908 
909  // Explicitly handle custom-parsed pass names.
911  return true;
912 
913 #define FUNCTION_PASS(NAME, CREATE_PASS) \
914  if (Name == NAME) \
915  return true;
916 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
917  if (checkParametrizedPassName(Name, NAME)) \
918  return true;
919 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
920  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
921  return true;
922 #include "PassRegistry.def"
923 
924  return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
925 }
926 
927 template <typename CallbacksT>
928 static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
929  bool &UseMemorySSA) {
930  UseMemorySSA = false;
931 
932  // Explicitly handle custom-parsed pass names.
934  return true;
935 
936  if (Name == "lnicm") {
937  UseMemorySSA = true;
938  return true;
939  }
940 
941 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
942  if (Name == NAME) \
943  return true;
944 #include "PassRegistry.def"
945 
946  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
947 }
948 
949 template <typename CallbacksT>
950 static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
951  bool &UseMemorySSA) {
952  UseMemorySSA = false;
953 
954  // Explicitly handle custom-parsed pass names.
956  return true;
957 
958  if (Name == "licm") {
959  UseMemorySSA = true;
960  return true;
961  }
962 
963 #define LOOP_PASS(NAME, CREATE_PASS) \
964  if (Name == NAME) \
965  return true;
966 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
967  if (checkParametrizedPassName(Name, NAME)) \
968  return true;
969 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
970  if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
971  return true;
972 #include "PassRegistry.def"
973 
974  return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
975 }
976 
978 PassBuilder::parsePipelineText(StringRef Text) {
979  std::vector<PipelineElement> ResultPipeline;
980 
981  SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
982  &ResultPipeline};
983  for (;;) {
984  std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
985  size_t Pos = Text.find_first_of(",()");
986  Pipeline.push_back({Text.substr(0, Pos), {}});
987 
988  // If we have a single terminating name, we're done.
989  if (Pos == Text.npos)
990  break;
991 
992  char Sep = Text[Pos];
993  Text = Text.substr(Pos + 1);
994  if (Sep == ',')
995  // Just a name ending in a comma, continue.
996  continue;
997 
998  if (Sep == '(') {
999  // Push the inner pipeline onto the stack to continue processing.
1000  PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1001  continue;
1002  }
1003 
1004  assert(Sep == ')' && "Bogus separator!");
1005  // When handling the close parenthesis, we greedily consume them to avoid
1006  // empty strings in the pipeline.
1007  do {
1008  // If we try to pop the outer pipeline we have unbalanced parentheses.
1009  if (PipelineStack.size() == 1)
1010  return None;
1011 
1012  PipelineStack.pop_back();
1013  } while (Text.consume_front(")"));
1014 
1015  // Check if we've finished parsing.
1016  if (Text.empty())
1017  break;
1018 
1019  // Otherwise, the end of an inner pipeline always has to be followed by
1020  // a comma, and then we can continue.
1021  if (!Text.consume_front(","))
1022  return None;
1023  }
1024 
1025  if (PipelineStack.size() > 1)
1026  // Unbalanced paretheses.
1027  return None;
1028 
1029  assert(PipelineStack.back() == &ResultPipeline &&
1030  "Wrong pipeline at the bottom of the stack!");
1031  return {std::move(ResultPipeline)};
1032 }
1033 
1034 Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1035  const PipelineElement &E) {
1036  auto &Name = E.Name;
1037  auto &InnerPipeline = E.InnerPipeline;
1038 
1039  // First handle complex passes like the pass managers which carry pipelines.
1040  if (!InnerPipeline.empty()) {
1041  if (Name == "module") {
1042  ModulePassManager NestedMPM;
1043  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1044  return Err;
1045  MPM.addPass(std::move(NestedMPM));
1046  return Error::success();
1047  }
1048  if (Name == "cgscc") {
1049  CGSCCPassManager CGPM;
1050  if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1051  return Err;
1053  return Error::success();
1054  }
1055  if (Name == "function" || Name == "function<eager-inv>") {
1056  FunctionPassManager FPM;
1057  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1058  return Err;
1060  Name != "function"));
1061  return Error::success();
1062  }
1063  if (auto Count = parseRepeatPassName(Name)) {
1064  ModulePassManager NestedMPM;
1065  if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1066  return Err;
1067  MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1068  return Error::success();
1069  }
1070 
1071  for (auto &C : ModulePipelineParsingCallbacks)
1072  if (C(Name, MPM, InnerPipeline))
1073  return Error::success();
1074 
1075  // Normal passes can't have pipelines.
1076  return make_error<StringError>(
1077  formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1079  ;
1080  }
1081 
1082  // Manually handle aliases for pre-configured pipeline fragments.
1084  SmallVector<StringRef, 3> Matches;
1085  if (!DefaultAliasRegex.match(Name, &Matches))
1086  return make_error<StringError>(
1087  formatv("unknown default pipeline alias '{0}'", Name).str(),
1089 
1090  assert(Matches.size() == 3 && "Must capture two matched strings!");
1091 
1093  .Case("O0", OptimizationLevel::O0)
1094  .Case("O1", OptimizationLevel::O1)
1095  .Case("O2", OptimizationLevel::O2)
1096  .Case("O3", OptimizationLevel::O3)
1097  .Case("Os", OptimizationLevel::Os)
1098  .Case("Oz", OptimizationLevel::Oz);
1099  if (L == OptimizationLevel::O0 && Matches[1] != "thinlto" &&
1100  Matches[1] != "lto") {
1101  MPM.addPass(buildO0DefaultPipeline(L, Matches[1] == "thinlto-pre-link" ||
1102  Matches[1] == "lto-pre-link"));
1103  return Error::success();
1104  }
1105 
1106  // This is consistent with old pass manager invoked via opt, but
1107  // inconsistent with clang. Clang doesn't enable loop vectorization
1108  // but does enable slp vectorization at Oz.
1109  PTO.LoopVectorization =
1110  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1111  PTO.SLPVectorization =
1112  L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1113 
1114  if (Matches[1] == "default") {
1116  } else if (Matches[1] == "thinlto-pre-link") {
1118  } else if (Matches[1] == "thinlto") {
1120  } else if (Matches[1] == "lto-pre-link") {
1122  } else {
1123  assert(Matches[1] == "lto" && "Not one of the matched options!");
1124  MPM.addPass(buildLTODefaultPipeline(L, nullptr));
1125  }
1126  return Error::success();
1127  }
1128 
1129  // Finally expand the basic registered passes from the .inc file.
1130 #define MODULE_PASS(NAME, CREATE_PASS) \
1131  if (Name == NAME) { \
1132  MPM.addPass(CREATE_PASS); \
1133  return Error::success(); \
1134  }
1135 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1136  if (checkParametrizedPassName(Name, NAME)) { \
1137  auto Params = parsePassParameters(PARSER, Name, NAME); \
1138  if (!Params) \
1139  return Params.takeError(); \
1140  MPM.addPass(CREATE_PASS(Params.get())); \
1141  return Error::success(); \
1142  }
1143 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1144  if (Name == "require<" NAME ">") { \
1145  MPM.addPass( \
1146  RequireAnalysisPass< \
1147  std::remove_reference<decltype(CREATE_PASS)>::type, Module>()); \
1148  return Error::success(); \
1149  } \
1150  if (Name == "invalidate<" NAME ">") { \
1151  MPM.addPass(InvalidateAnalysisPass< \
1152  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1153  return Error::success(); \
1154  }
1155 #define CGSCC_PASS(NAME, CREATE_PASS) \
1156  if (Name == NAME) { \
1157  MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1158  return Error::success(); \
1159  }
1160 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1161  if (checkParametrizedPassName(Name, NAME)) { \
1162  auto Params = parsePassParameters(PARSER, Name, NAME); \
1163  if (!Params) \
1164  return Params.takeError(); \
1165  MPM.addPass( \
1166  createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1167  return Error::success(); \
1168  }
1169 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1170  if (Name == NAME) { \
1171  MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1172  return Error::success(); \
1173  }
1174 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1175  if (checkParametrizedPassName(Name, NAME)) { \
1176  auto Params = parsePassParameters(PARSER, Name, NAME); \
1177  if (!Params) \
1178  return Params.takeError(); \
1179  MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1180  return Error::success(); \
1181  }
1182 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1183  if (Name == NAME) { \
1184  MPM.addPass(createModuleToFunctionPassAdaptor( \
1185  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1186  return Error::success(); \
1187  }
1188 #define LOOP_PASS(NAME, CREATE_PASS) \
1189  if (Name == NAME) { \
1190  MPM.addPass(createModuleToFunctionPassAdaptor( \
1191  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1192  return Error::success(); \
1193  }
1194 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1195  if (checkParametrizedPassName(Name, NAME)) { \
1196  auto Params = parsePassParameters(PARSER, Name, NAME); \
1197  if (!Params) \
1198  return Params.takeError(); \
1199  MPM.addPass( \
1200  createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1201  CREATE_PASS(Params.get()), false, false))); \
1202  return Error::success(); \
1203  }
1204 #include "PassRegistry.def"
1205 
1206  for (auto &C : ModulePipelineParsingCallbacks)
1207  if (C(Name, MPM, InnerPipeline))
1208  return Error::success();
1209  return make_error<StringError>(
1210  formatv("unknown module pass '{0}'", Name).str(),
1212 }
1213 
1214 Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1215  const PipelineElement &E) {
1216  auto &Name = E.Name;
1217  auto &InnerPipeline = E.InnerPipeline;
1218 
1219  // First handle complex passes like the pass managers which carry pipelines.
1220  if (!InnerPipeline.empty()) {
1221  if (Name == "cgscc") {
1222  CGSCCPassManager NestedCGPM;
1223  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1224  return Err;
1225  // Add the nested pass manager with the appropriate adaptor.
1226  CGPM.addPass(std::move(NestedCGPM));
1227  return Error::success();
1228  }
1229  if (Name == "function" || Name == "function<eager-inv>") {
1230  FunctionPassManager FPM;
1231  if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1232  return Err;
1233  // Add the nested pass manager with the appropriate adaptor.
1234  CGPM.addPass(
1235  createCGSCCToFunctionPassAdaptor(std::move(FPM), Name != "function"));
1236  return Error::success();
1237  }
1238  if (auto Count = parseRepeatPassName(Name)) {
1239  CGSCCPassManager NestedCGPM;
1240  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1241  return Err;
1242  CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1243  return Error::success();
1244  }
1245  if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1246  CGSCCPassManager NestedCGPM;
1247  if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1248  return Err;
1249  CGPM.addPass(
1250  createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1251  return Error::success();
1252  }
1253 
1254  for (auto &C : CGSCCPipelineParsingCallbacks)
1255  if (C(Name, CGPM, InnerPipeline))
1256  return Error::success();
1257 
1258  // Normal passes can't have pipelines.
1259  return make_error<StringError>(
1260  formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1262  }
1263 
1264 // Now expand the basic registered passes from the .inc file.
1265 #define CGSCC_PASS(NAME, CREATE_PASS) \
1266  if (Name == NAME) { \
1267  CGPM.addPass(CREATE_PASS); \
1268  return Error::success(); \
1269  }
1270 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1271  if (checkParametrizedPassName(Name, NAME)) { \
1272  auto Params = parsePassParameters(PARSER, Name, NAME); \
1273  if (!Params) \
1274  return Params.takeError(); \
1275  CGPM.addPass(CREATE_PASS(Params.get())); \
1276  return Error::success(); \
1277  }
1278 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1279  if (Name == "require<" NAME ">") { \
1280  CGPM.addPass(RequireAnalysisPass< \
1281  std::remove_reference<decltype(CREATE_PASS)>::type, \
1282  LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1283  CGSCCUpdateResult &>()); \
1284  return Error::success(); \
1285  } \
1286  if (Name == "invalidate<" NAME ">") { \
1287  CGPM.addPass(InvalidateAnalysisPass< \
1288  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1289  return Error::success(); \
1290  }
1291 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1292  if (Name == NAME) { \
1293  CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
1294  return Error::success(); \
1295  }
1296 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1297  if (checkParametrizedPassName(Name, NAME)) { \
1298  auto Params = parsePassParameters(PARSER, Name, NAME); \
1299  if (!Params) \
1300  return Params.takeError(); \
1301  CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1302  return Error::success(); \
1303  }
1304 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1305  if (Name == NAME) { \
1306  CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1307  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1308  return Error::success(); \
1309  }
1310 #define LOOP_PASS(NAME, CREATE_PASS) \
1311  if (Name == NAME) { \
1312  CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1313  createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1314  return Error::success(); \
1315  }
1316 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1317  if (checkParametrizedPassName(Name, NAME)) { \
1318  auto Params = parsePassParameters(PARSER, Name, NAME); \
1319  if (!Params) \
1320  return Params.takeError(); \
1321  CGPM.addPass( \
1322  createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1323  CREATE_PASS(Params.get()), false, false))); \
1324  return Error::success(); \
1325  }
1326 #include "PassRegistry.def"
1327 
1328  for (auto &C : CGSCCPipelineParsingCallbacks)
1329  if (C(Name, CGPM, InnerPipeline))
1330  return Error::success();
1331  return make_error<StringError>(
1332  formatv("unknown cgscc pass '{0}'", Name).str(),
1334 }
1335 
1336 Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1337  const PipelineElement &E) {
1338  auto &Name = E.Name;
1339  auto &InnerPipeline = E.InnerPipeline;
1340 
1341  // First handle complex passes like the pass managers which carry pipelines.
1342  if (!InnerPipeline.empty()) {
1343  if (Name == "function") {
1344  FunctionPassManager NestedFPM;
1345  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1346  return Err;
1347  // Add the nested pass manager with the appropriate adaptor.
1348  FPM.addPass(std::move(NestedFPM));
1349  return Error::success();
1350  }
1351  if (Name == "loop" || Name == "loop-mssa") {
1352  LoopPassManager LPM;
1353  if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
1354  return Err;
1355  // Add the nested pass manager with the appropriate adaptor.
1356  bool UseMemorySSA = (Name == "loop-mssa");
1357  bool UseBFI = llvm::any_of(
1358  InnerPipeline, [](auto Pipeline) { return Pipeline.Name == "licm"; });
1359  bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1360  return Pipeline.Name == "loop-predication";
1361  });
1362  FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
1363  UseBFI, UseBPI));
1364  return Error::success();
1365  }
1366  if (auto Count = parseRepeatPassName(Name)) {
1367  FunctionPassManager NestedFPM;
1368  if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1369  return Err;
1370  FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1371  return Error::success();
1372  }
1373 
1374  for (auto &C : FunctionPipelineParsingCallbacks)
1375  if (C(Name, FPM, InnerPipeline))
1376  return Error::success();
1377 
1378  // Normal passes can't have pipelines.
1379  return make_error<StringError>(
1380  formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1382  }
1383 
1384 // Now expand the basic registered passes from the .inc file.
1385 #define FUNCTION_PASS(NAME, CREATE_PASS) \
1386  if (Name == NAME) { \
1387  FPM.addPass(CREATE_PASS); \
1388  return Error::success(); \
1389  }
1390 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1391  if (checkParametrizedPassName(Name, NAME)) { \
1392  auto Params = parsePassParameters(PARSER, Name, NAME); \
1393  if (!Params) \
1394  return Params.takeError(); \
1395  FPM.addPass(CREATE_PASS(Params.get())); \
1396  return Error::success(); \
1397  }
1398 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1399  if (Name == "require<" NAME ">") { \
1400  FPM.addPass( \
1401  RequireAnalysisPass< \
1402  std::remove_reference<decltype(CREATE_PASS)>::type, Function>()); \
1403  return Error::success(); \
1404  } \
1405  if (Name == "invalidate<" NAME ">") { \
1406  FPM.addPass(InvalidateAnalysisPass< \
1407  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1408  return Error::success(); \
1409  }
1410 // FIXME: UseMemorySSA is set to false. Maybe we could do things like:
1411 // bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
1412 // "guard-widening");
1413 // The risk is that it may become obsolete if we're not careful.
1414 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1415  if (Name == NAME) { \
1416  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1417  return Error::success(); \
1418  }
1419 #define LOOP_PASS(NAME, CREATE_PASS) \
1420  if (Name == NAME) { \
1421  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1422  return Error::success(); \
1423  }
1424 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1425  if (checkParametrizedPassName(Name, NAME)) { \
1426  auto Params = parsePassParameters(PARSER, Name, NAME); \
1427  if (!Params) \
1428  return Params.takeError(); \
1429  FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
1430  false, false)); \
1431  return Error::success(); \
1432  }
1433 #include "PassRegistry.def"
1434 
1435  for (auto &C : FunctionPipelineParsingCallbacks)
1436  if (C(Name, FPM, InnerPipeline))
1437  return Error::success();
1438  return make_error<StringError>(
1439  formatv("unknown function pass '{0}'", Name).str(),
1441 }
1442 
1443 Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
1444  const PipelineElement &E) {
1445  StringRef Name = E.Name;
1446  auto &InnerPipeline = E.InnerPipeline;
1447 
1448  // First handle complex passes like the pass managers which carry pipelines.
1449  if (!InnerPipeline.empty()) {
1450  if (Name == "loop") {
1451  LoopPassManager NestedLPM;
1452  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1453  return Err;
1454  // Add the nested pass manager with the appropriate adaptor.
1455  LPM.addPass(std::move(NestedLPM));
1456  return Error::success();
1457  }
1458  if (auto Count = parseRepeatPassName(Name)) {
1459  LoopPassManager NestedLPM;
1460  if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1461  return Err;
1462  LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
1463  return Error::success();
1464  }
1465 
1466  for (auto &C : LoopPipelineParsingCallbacks)
1467  if (C(Name, LPM, InnerPipeline))
1468  return Error::success();
1469 
1470  // Normal passes can't have pipelines.
1471  return make_error<StringError>(
1472  formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
1474  }
1475 
1476 // Now expand the basic registered passes from the .inc file.
1477 #define LOOPNEST_PASS(NAME, CREATE_PASS) \
1478  if (Name == NAME) { \
1479  LPM.addPass(CREATE_PASS); \
1480  return Error::success(); \
1481  }
1482 #define LOOP_PASS(NAME, CREATE_PASS) \
1483  if (Name == NAME) { \
1484  LPM.addPass(CREATE_PASS); \
1485  return Error::success(); \
1486  }
1487 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1488  if (checkParametrizedPassName(Name, NAME)) { \
1489  auto Params = parsePassParameters(PARSER, Name, NAME); \
1490  if (!Params) \
1491  return Params.takeError(); \
1492  LPM.addPass(CREATE_PASS(Params.get())); \
1493  return Error::success(); \
1494  }
1495 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1496  if (Name == "require<" NAME ">") { \
1497  LPM.addPass(RequireAnalysisPass< \
1498  std::remove_reference<decltype(CREATE_PASS)>::type, Loop, \
1499  LoopAnalysisManager, LoopStandardAnalysisResults &, \
1500  LPMUpdater &>()); \
1501  return Error::success(); \
1502  } \
1503  if (Name == "invalidate<" NAME ">") { \
1504  LPM.addPass(InvalidateAnalysisPass< \
1505  std::remove_reference<decltype(CREATE_PASS)>::type>()); \
1506  return Error::success(); \
1507  }
1508 #include "PassRegistry.def"
1509 
1510  for (auto &C : LoopPipelineParsingCallbacks)
1511  if (C(Name, LPM, InnerPipeline))
1512  return Error::success();
1513  return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
1515 }
1516 
1517 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
1518 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1519  if (Name == NAME) { \
1520  AA.registerModuleAnalysis< \
1521  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1522  return true; \
1523  }
1524 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1525  if (Name == NAME) { \
1526  AA.registerFunctionAnalysis< \
1527  std::remove_reference<decltype(CREATE_PASS)>::type>(); \
1528  return true; \
1529  }
1530 #include "PassRegistry.def"
1531 
1532  for (auto &C : AAParsingCallbacks)
1533  if (C(Name, AA))
1534  return true;
1535  return false;
1536 }
1537 
1538 Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
1539  ArrayRef<PipelineElement> Pipeline) {
1540  for (const auto &Element : Pipeline) {
1541  if (auto Err = parseLoopPass(LPM, Element))
1542  return Err;
1543  }
1544  return Error::success();
1545 }
1546 
1547 Error PassBuilder::parseFunctionPassPipeline(
1549  for (const auto &Element : Pipeline) {
1550  if (auto Err = parseFunctionPass(FPM, Element))
1551  return Err;
1552  }
1553  return Error::success();
1554 }
1555 
1556 Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1557  ArrayRef<PipelineElement> Pipeline) {
1558  for (const auto &Element : Pipeline) {
1559  if (auto Err = parseCGSCCPass(CGPM, Element))
1560  return Err;
1561  }
1562  return Error::success();
1563 }
1564 
1576 }
1577 
1578 Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1579  ArrayRef<PipelineElement> Pipeline) {
1580  for (const auto &Element : Pipeline) {
1581  if (auto Err = parseModulePass(MPM, Element))
1582  return Err;
1583  }
1584  return Error::success();
1585 }
1586 
1587 // Primary pass pipeline description parsing routine for a \c ModulePassManager
1588 // FIXME: Should this routine accept a TargetMachine or require the caller to
1589 // pre-populate the analysis managers with target-specific stuff?
1591  StringRef PipelineText) {
1592  auto Pipeline = parsePipelineText(PipelineText);
1593  if (!Pipeline || Pipeline->empty())
1594  return make_error<StringError>(
1595  formatv("invalid pipeline '{0}'", PipelineText).str(),
1597 
1598  // If the first name isn't at the module layer, wrap the pipeline up
1599  // automatically.
1600  StringRef FirstName = Pipeline->front().Name;
1601 
1602  if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
1603  bool UseMemorySSA;
1604  if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
1605  Pipeline = {{"cgscc", std::move(*Pipeline)}};
1606  } else if (isFunctionPassName(FirstName,
1607  FunctionPipelineParsingCallbacks)) {
1608  Pipeline = {{"function", std::move(*Pipeline)}};
1609  } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
1610  UseMemorySSA)) {
1611  Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
1612  std::move(*Pipeline)}}}};
1613  } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
1614  UseMemorySSA)) {
1615  Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
1616  std::move(*Pipeline)}}}};
1617  } else {
1618  for (auto &C : TopLevelPipelineParsingCallbacks)
1619  if (C(MPM, *Pipeline))
1620  return Error::success();
1621 
1622  // Unknown pass or pipeline name!
1623  auto &InnerPipeline = Pipeline->front().InnerPipeline;
1624  return make_error<StringError>(
1625  formatv("unknown {0} name '{1}'",
1626  (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
1627  .str(),
1629  }
1630  }
1631 
1632  if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
1633  return Err;
1634  return Error::success();
1635 }
1636 
1637 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
1639  StringRef PipelineText) {
1640  auto Pipeline = parsePipelineText(PipelineText);
1641  if (!Pipeline || Pipeline->empty())
1642  return make_error<StringError>(
1643  formatv("invalid pipeline '{0}'", PipelineText).str(),
1645 
1646  StringRef FirstName = Pipeline->front().Name;
1647  if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
1648  return make_error<StringError>(
1649  formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
1650  PipelineText)
1651  .str(),
1653 
1654  if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
1655  return Err;
1656  return Error::success();
1657 }
1658 
1659 // Primary pass pipeline description parsing routine for a \c
1660 // FunctionPassManager
1662  StringRef PipelineText) {
1663  auto Pipeline = parsePipelineText(PipelineText);
1664  if (!Pipeline || Pipeline->empty())
1665  return make_error<StringError>(
1666  formatv("invalid pipeline '{0}'", PipelineText).str(),
1668 
1669  StringRef FirstName = Pipeline->front().Name;
1670  if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
1671  return make_error<StringError>(
1672  formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
1673  PipelineText)
1674  .str(),
1676 
1677  if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
1678  return Err;
1679  return Error::success();
1680 }
1681 
1682 // Primary pass pipeline description parsing routine for a \c LoopPassManager
1684  StringRef PipelineText) {
1685  auto Pipeline = parsePipelineText(PipelineText);
1686  if (!Pipeline || Pipeline->empty())
1687  return make_error<StringError>(
1688  formatv("invalid pipeline '{0}'", PipelineText).str(),
1690 
1691  if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
1692  return Err;
1693 
1694  return Error::success();
1695 }
1696 
1698  // If the pipeline just consists of the word 'default' just replace the AA
1699  // manager with our default one.
1700  if (PipelineText == "default") {
1701  AA = buildDefaultAAPipeline();
1702  return Error::success();
1703  }
1704 
1705  while (!PipelineText.empty()) {
1706  StringRef Name;
1707  std::tie(Name, PipelineText) = PipelineText.split(',');
1708  if (!parseAAPassName(AA, Name))
1709  return make_error<StringError>(
1710  formatv("unknown alias analysis name '{0}'", Name).str(),
1712  }
1713 
1714  return Error::success();
1715 }
1716 
1718 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1719  if (PassName == NAME) \
1720  return true;
1721 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1722  if (PassName == NAME) \
1723  return true;
1724 #include "PassRegistry.def"
1725  return false;
1726 }
1727 
1729 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1730  if (PassName == NAME) \
1731  return true;
1732 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1733  if (PassName == NAME) \
1734  return true;
1735 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1736  if (PassName == NAME) \
1737  return true;
1738 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1739  if (PassName == NAME) \
1740  return true;
1741 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1742  if (PassName == NAME) \
1743  return true;
1744 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1745  if (PassName == NAME) \
1746  return true;
1747 #include "PassRegistry.def"
1748  return false;
1749 }
1750 
1752  OS << " " << PassName << "\n";
1753 }
1755  raw_ostream &OS) {
1756  OS << " " << PassName << "<" << Params << ">\n";
1757 }
1758 
1760  // TODO: print pass descriptions when they are available
1761 
1762  OS << "Module passes:\n";
1763 #define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1764 #include "PassRegistry.def"
1765 
1766  OS << "Module passes with params:\n";
1767 #define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1768  printPassName(NAME, PARAMS, OS);
1769 #include "PassRegistry.def"
1770 
1771  OS << "Module analyses:\n";
1772 #define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1773 #include "PassRegistry.def"
1774 
1775  OS << "Module alias analyses:\n";
1776 #define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1777 #include "PassRegistry.def"
1778 
1779  OS << "CGSCC passes:\n";
1780 #define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1781 #include "PassRegistry.def"
1782 
1783  OS << "CGSCC passes with params:\n";
1784 #define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1785  printPassName(NAME, PARAMS, OS);
1786 #include "PassRegistry.def"
1787 
1788  OS << "CGSCC analyses:\n";
1789 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1790 #include "PassRegistry.def"
1791 
1792  OS << "Function passes:\n";
1793 #define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1794 #include "PassRegistry.def"
1795 
1796  OS << "Function passes with params:\n";
1797 #define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1798  printPassName(NAME, PARAMS, OS);
1799 #include "PassRegistry.def"
1800 
1801  OS << "Function analyses:\n";
1802 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1803 #include "PassRegistry.def"
1804 
1805  OS << "Function alias analyses:\n";
1806 #define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1807 #include "PassRegistry.def"
1808 
1809  OS << "LoopNest passes:\n";
1810 #define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1811 #include "PassRegistry.def"
1812 
1813  OS << "Loop passes:\n";
1814 #define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
1815 #include "PassRegistry.def"
1816 
1817  OS << "Loop passes with params:\n";
1818 #define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1819  printPassName(NAME, PARAMS, OS);
1820 #include "PassRegistry.def"
1821 
1822  OS << "Loop analyses:\n";
1823 #define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
1824 #include "PassRegistry.def"
1825 }
1826 
1829  &C) {
1830  TopLevelPipelineParsingCallbacks.push_back(C);
1831 }
llvm::GVNOptions
A set of parameters to control various transforms performed by GVN pass.
Definition: GVN.h:73
llvm::StringSwitch::Case
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
AddressSanitizer.h
RegionInfo.h
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:155
TypeBasedAliasAnalysis.h
llvm::PassManager< Loop, LoopAnalysisManager, LoopStandardAnalysisResults &, LPMUpdater & >
Definition: LoopPassManager.h:70
Instrumentation.h
SymbolRewriter.h
AssumptionCache.h
StackSafetyAnalysis.h
llvm::AAManager
A manager for alias analyses.
Definition: AliasAnalysis.h:1287
startsWithDefaultPipelineAliasPrefix
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name)
Tests whether a pass name starts with a valid prefix for a default pipeline alias.
Definition: PassBuilder.cpp:817
IROutliner.h
Lint.h
LowerWidenableCondition.h
DeadArgumentElimination.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
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
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:374
GlobalSplit.h
llvm::ModuleAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:1177
CorrelatedValuePropagation.h
llvm::Function
Definition: Function.h:62
InstructionNamer.h
llvm::Loop
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:530
NaryReassociate.h
llvm::PassManager::addPass
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same< PassT, PassManager >::value > addPass(PassT &&Pass)
Definition: PassManager.h:553
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
llvm::StringSwitch::Default
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
InferAddressSpaces.h
LCSSA.h
ConstantMerge.h
AlignmentFromAssumptions.h
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:59
LowerAtomic.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1177
FunctionImport.h
CycleAnalysis.h
llvm::APInt::getSExtValue
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1479
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:331
TailRecursionElimination.h
DivRemPairs.h
llvm::PassBuilder::PassBuilder
PassBuilder(TargetMachine *TM=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions(), Optional< PGOOptions > PGOOpt=None, PassInstrumentationCallbacks *PIC=nullptr)
Definition: PassBuilder.cpp:375
DeadStoreElimination.h
llvm::PipelineTuningOptions
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:38
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:681
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:221
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
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:52
CGProfile.h
isModulePassName
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:842
PIC
PassInstrumentationCallbacks PIC
Definition: PassBuilderBindings.cpp:55
MetaRenamer.h
JumpThreading.h
HotColdSplitting.h
llvm::Optional
Definition: APInt.h:33
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:42
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:525
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:928
Scalarizer.h
llvm::PassBuilder::parsePassPipeline
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
Definition: PassBuilder.cpp:1590
llvm::StringRef::substr
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:610
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:250
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:422
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
llvm::StringRef::split
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:748
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:174
LowerInvoke.h
isFunctionPassName
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:902
llvm::ms_demangle::QualifierMangleMode::Result
@ Result
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
TargetLibraryInfo.h
RewriteStatepointsForGC.h
AssumeBundleBuilder.h
LowerSwitch.h
InlineAdvisor.h
StructurizeCFG.h
llvm::createRepeatedPass
RepeatedPass< PassT > createRepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1362
IRPrintingPasses.h
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:597
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:1294
PrintPasses.h
ScopedNoAliasAA.h
llvm::StringRef::getAsInteger
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:509
llvm::None
const NoneType None
Definition: None.h:23
CanonicalizeFreezeInLoops.h
ControlHeightReduction.h
InstSimplifyPass.h
llvm::PassBuilder::isAnalysisPassName
bool isAnalysisPassName(StringRef PassName)
Returns true if the pass name is the name of a (non-alias) analysis pass.
Definition: PassBuilder.cpp:1728
llvm::PassBuilder::isAAPassName
bool isAAPassName(StringRef PassName)
Returns true if the pass name is the name of an alias analysis pass.
Definition: PassBuilder.cpp:1717
LoopInfo.h
LoopFuse.h
SROA.h
SampleProfile.h
MakeGuardsExplicit.h
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
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:1227
SpeculativeExecution.h
checkParametrizedPassName
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
Definition: PassBuilder.cpp:471
InlineSizeEstimatorAnalysis.h
llvm::PassBuilder::registerFunctionAnalyses
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
Definition: PassBuilder.cpp:430
BranchProbabilityInfo.h
EarlyCSE.h
CrossDSOCFI.h
CFGPrinter.h
GCOVProfiler.h
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
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:263
CoroSplit.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:1411
llvm::PassBuilder::registerModuleAnalyses
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
Definition: PassBuilder.cpp:412
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:72
llvm::StringRef::front
LLVM_NODISCARD char front() const
front - Get the first character in the string.
Definition: StringRef.h:160
llvm::PassBuilder::buildLTODefaultPipeline
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
Definition: PassBuilderPipelines.cpp:1420
AggressiveInstCombine.h
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:1355
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:1791
InferFunctionAttrs.h
SimpleLoopUnswitch.h
Enable
@ Enable
Definition: DwarfDebug.cpp:88
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:473
llvm::StackLifetime::LivenessType
LivenessType
Definition: StackLifetime.h:84
SeparateConstOffsetFromGEP.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::PassBuilder::printPassNames
void printPassNames(raw_ostream &OS)
Print pass names.
Definition: PassBuilder.cpp:1759
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:80
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:53
Reassociate.h
llvm::FunctionAnalysisManagerLoopProxy
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
Definition: LoopAnalysisManager.h:157
SafepointIRVerifier.h
GuardWidening.h
parseDevirtPassName
static Optional< int > parseDevirtPassName(StringRef Name)
Definition: PassBuilder.cpp:462
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
LoopNestAnalysis.h
llvm::printBeforePasses
std::vector< std::string > printBeforePasses()
Definition: PrintPasses.cpp:73
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:397
NameAnonGlobals.h
LowerMatrixIntrinsics.h
llvm::printAfterPasses
std::vector< std::string > printAfterPasses()
Definition: PrintPasses.cpp:77
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
LoopInterchange.h
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::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:1656
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
SanitizerCoverage.h
llvm::LoopAnalysisManagerFunctionProxy
InnerAnalysisManagerProxy< LoopAnalysisManager, Function > LoopAnalysisManagerFunctionProxy
A proxy from a LoopAnalysisManager to a Function.
Definition: LoopAnalysisManager.h:80
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:108
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:49
NewGVN.h
llvm::LoopUnrollOptions::setFullUnrollMaxCount
LoopUnrollOptions & setFullUnrollMaxCount(unsigned O)
Definition: LoopUnrollPass.h:124
LowerTypeTests.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:1697
LoopVectorize.h
SCCP.h
DemandedBits.h
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:831
FunctionPropertiesAnalysis.h
PhiValues.h
llvm::PassBuilder::registerLoopAnalyses
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
Definition: PassBuilder.cpp:444
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:74
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:238
LoopLoadElimination.h
llvm::CGSCCAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
Definition: CGSCCPassManager.h:443
Verifier.h
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
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:77
llvm::HWAddressSanitizerOptions
Definition: HWAddressSanitizer.h:21
llvm::PassBuilder::buildPerModuleDefaultPipeline
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build a per-module default optimization pipeline.
Definition: PassBuilderPipelines.cpp:1252
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:161
LoopUnrollPass.h
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
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:421
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:1690
llvm::AnalysisManager::registerPass
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:845
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:950
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:701
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:1565
llvm::LoopUnrollOptions::setOptLevel
LoopUnrollOptions & setOptLevel(int O)
Definition: LoopUnrollPass.h:112
LoopDeletion.h
MemProfiler.h
TargetTransformInfo.h
llvm::MemorySanitizerOptions
Definition: MemorySanitizer.h:21
Delinearization.h
LICM.h
LoopCacheAnalysis.h
CoroEarly.h
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:42
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:44
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
DCE.h
AliasSetTracker.h
llvm::StringRef::find_first_of
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:409
BDCE.h
InstrOrderFile.h
parseRepeatPassName
static Optional< int > parseRepeatPassName(StringRef Name)
Definition: PassBuilder.cpp:453
InstCombine.h
DependenceAnalysis.h
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:113
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:1827
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:389
llvm::LoopNest
This class represents a loop nest and can be used to query its properties.
Definition: LoopNestAnalysis.h:28
CGAM
CGSCCAnalysisManager CGAM
Definition: PassBuilderBindings.cpp:60
llvm::FunctionAnalysisManagerModuleProxy
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:1023
FunctionAttrs.h
Debug.h
isCGSCCPassName
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks)
Definition: PassBuilder.cpp:874
RelLookupTableConverter.h
llvm::AddressSanitizerOptions
Definition: AddressSanitizer.h:92
PassName
static const char PassName[]
Definition: X86LowerAMXIntrinsics.cpp:670
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:1751
AddDiscriminators.h
DFAJumpThreading.h