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