LLVM 19.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
32#include "llvm/Analysis/DDG.h"
48#include "llvm/Analysis/Lint.h"
105#include "llvm/IR/DebugInfo.h"
106#include "llvm/IR/Dominators.h"
107#include "llvm/IR/PassManager.h"
108#include "llvm/IR/PrintPasses.h"
110#include "llvm/IR/Verifier.h"
114#include "llvm/Support/Debug.h"
117#include "llvm/Support/Regex.h"
298#include <optional>
299
300using namespace llvm;
301
303 "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
304
305namespace llvm {
307 "print-pipeline-passes",
308 cl::desc("Print a '-passes' compatible string describing the pipeline "
309 "(best-effort only)."));
310} // namespace llvm
311
312AnalysisKey NoOpModuleAnalysis::Key;
313AnalysisKey NoOpCGSCCAnalysis::Key;
314AnalysisKey NoOpFunctionAnalysis::Key;
315AnalysisKey NoOpLoopAnalysis::Key;
316
317namespace {
318
319/// Whether or not we should populate a PassInstrumentationCallbacks's class to
320/// pass name map.
321///
322/// This is for optimization purposes so we don't populate it if we never use
323/// it. This should be updated if new pass instrumentation wants to use the map.
324/// We currently only use this for --print-before/after.
325bool shouldPopulateClassToPassNames() {
326 return PrintPipelinePasses || !printBeforePasses().empty() ||
327 !printAfterPasses().empty() || !isFilterPassesEmpty() ||
329}
330
331// A pass for testing -print-on-crash.
332// DO NOT USE THIS EXCEPT FOR TESTING!
333class TriggerCrashPass : public PassInfoMixin<TriggerCrashPass> {
334public:
336 abort();
337 return PreservedAnalyses::all();
338 }
339 static StringRef name() { return "TriggerCrashPass"; }
340};
341
342// A pass for testing message reporting of -verify-each failures.
343// DO NOT USE THIS EXCEPT FOR TESTING!
344class TriggerVerifierErrorPass
345 : public PassInfoMixin<TriggerVerifierErrorPass> {
346public:
348 // Intentionally break the Module by creating an alias without setting the
349 // aliasee.
350 auto *PtrTy = llvm::PointerType::getUnqual(M.getContext());
351 GlobalAlias::create(PtrTy, PtrTy->getAddressSpace(),
352 GlobalValue::LinkageTypes::InternalLinkage,
353 "__bad_alias", nullptr, &M);
355 }
356
358 // Intentionally break the Function by inserting a terminator
359 // instruction in the middle of a basic block.
360 BasicBlock &BB = F.getEntryBlock();
361 new UnreachableInst(F.getContext(), BB.getTerminator()->getIterator());
363 }
364
365 static StringRef name() { return "TriggerVerifierErrorPass"; }
366};
367
368// A pass requires all MachineFunctionProperties.
369// DO NOT USE THIS EXCEPT FOR TESTING!
370class RequireAllMachineFunctionPropertiesPass
371 : public PassInfoMixin<RequireAllMachineFunctionPropertiesPass> {
372public:
375 }
376
377 static MachineFunctionProperties getRequiredProperties() {
379 MFProps.set(MachineFunctionProperties::Property::FailedISel);
380 MFProps.set(MachineFunctionProperties::Property::FailsVerification);
381 MFProps.set(MachineFunctionProperties::Property::IsSSA);
382 MFProps.set(MachineFunctionProperties::Property::Legalized);
383 MFProps.set(MachineFunctionProperties::Property::NoPHIs);
384 MFProps.set(MachineFunctionProperties::Property::NoVRegs);
385 MFProps.set(MachineFunctionProperties::Property::RegBankSelected);
386 MFProps.set(MachineFunctionProperties::Property::Selected);
387 MFProps.set(MachineFunctionProperties::Property::TiedOpsRewritten);
388 MFProps.set(MachineFunctionProperties::Property::TracksDebugUserValues);
389 MFProps.set(MachineFunctionProperties::Property::TracksLiveness);
390 return MFProps;
391 }
392 static StringRef name() { return "RequireAllMachineFunctionPropertiesPass"; }
393};
394
395} // namespace
396
398 std::optional<PGOOptions> PGOOpt,
400 : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
401 bool ShouldPopulateClassToPassNames = PIC && shouldPopulateClassToPassNames();
402 if (TM)
403 TM->registerPassBuilderCallbacks(*this, ShouldPopulateClassToPassNames);
404 if (ShouldPopulateClassToPassNames) {
405#define MODULE_PASS(NAME, CREATE_PASS) \
406 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
407#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
408 PIC->addClassToPassName(CLASS, NAME);
409#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
410 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
411#define FUNCTION_PASS(NAME, CREATE_PASS) \
412 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
413#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
414 PIC->addClassToPassName(CLASS, NAME);
415#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
416 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
417#define LOOPNEST_PASS(NAME, CREATE_PASS) \
418 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
419#define LOOP_PASS(NAME, CREATE_PASS) \
420 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
421#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
422 PIC->addClassToPassName(CLASS, NAME);
423#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
424 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
425#define CGSCC_PASS(NAME, CREATE_PASS) \
426 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
427#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
428 PIC->addClassToPassName(CLASS, NAME);
429#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
430 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
431#include "PassRegistry.def"
432
433#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
434 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
435#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
436 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
437#include "llvm/Passes/MachinePassRegistry.def"
438 }
439}
440
442#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
443 MAM.registerPass([&] { return CREATE_PASS; });
444#include "PassRegistry.def"
445
446 for (auto &C : ModuleAnalysisRegistrationCallbacks)
447 C(MAM);
448}
449
451#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
452 CGAM.registerPass([&] { return CREATE_PASS; });
453#include "PassRegistry.def"
454
455 for (auto &C : CGSCCAnalysisRegistrationCallbacks)
456 C(CGAM);
457}
458
460 // We almost always want the default alias analysis pipeline.
461 // If a user wants a different one, they can register their own before calling
462 // registerFunctionAnalyses().
463 FAM.registerPass([&] { return buildDefaultAAPipeline(); });
464
465#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
466 FAM.registerPass([&] { return CREATE_PASS; });
467#include "PassRegistry.def"
468
469 for (auto &C : FunctionAnalysisRegistrationCallbacks)
470 C(FAM);
471}
472
475
476#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
477 MFAM.registerPass([&] { return CREATE_PASS; });
478#include "llvm/Passes/MachinePassRegistry.def"
479
480 for (auto &C : MachineFunctionAnalysisRegistrationCallbacks)
481 C(MFAM);
482}
483
485#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
486 LAM.registerPass([&] { return CREATE_PASS; });
487#include "PassRegistry.def"
488
489 for (auto &C : LoopAnalysisRegistrationCallbacks)
490 C(LAM);
491}
492
493static std::optional<int> parseRepeatPassName(StringRef Name) {
494 if (!Name.consume_front("repeat<") || !Name.consume_back(">"))
495 return std::nullopt;
496 int Count;
497 if (Name.getAsInteger(0, Count) || Count <= 0)
498 return std::nullopt;
499 return Count;
500}
501
502static std::optional<std::pair<bool, bool>>
504 std::pair<bool, bool> Params;
505 if (!Name.consume_front("function"))
506 return std::nullopt;
507 if (Name.empty())
508 return Params;
509 if (!Name.consume_front("<") || !Name.consume_back(">"))
510 return std::nullopt;
511 while (!Name.empty()) {
512 auto [Front, Back] = Name.split(';');
513 Name = Back;
514 if (Front == "eager-inv")
515 Params.first = true;
516 else if (Front == "no-rerun")
517 Params.second = true;
518 else
519 return std::nullopt;
520 }
521 return Params;
522}
523
524static std::optional<int> parseDevirtPassName(StringRef Name) {
525 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
526 return std::nullopt;
527 int Count;
528 if (Name.getAsInteger(0, Count) || Count < 0)
529 return std::nullopt;
530 return Count;
531}
532
533static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
535 .Case("O0", OptimizationLevel::O0)
541 .Default(std::nullopt);
542}
543
545 StringRef OptionName,
547 bool Result = false;
548 while (!Params.empty()) {
549 StringRef ParamName;
550 std::tie(ParamName, Params) = Params.split(';');
551
552 if (ParamName == OptionName) {
553 Result = true;
554 } else {
555 return make_error<StringError>(
556 formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
557 .str(),
559 }
560 }
561 return Result;
562}
563
564namespace {
565
566/// Parser of parameters for HardwareLoops pass.
567Expected<HardwareLoopOptions> parseHardwareLoopOptions(StringRef Params) {
568 HardwareLoopOptions HardwareLoopOpts;
569
570 while (!Params.empty()) {
571 StringRef ParamName;
572 std::tie(ParamName, Params) = Params.split(';');
573 if (ParamName.consume_front("hardware-loop-decrement=")) {
574 int Count;
575 if (ParamName.getAsInteger(0, Count))
576 return make_error<StringError>(
577 formatv("invalid HardwareLoopPass parameter '{0}' ", ParamName).str(),
579 HardwareLoopOpts.setDecrement(Count);
580 continue;
581 }
582 if (ParamName.consume_front("hardware-loop-counter-bitwidth=")) {
583 int Count;
584 if (ParamName.getAsInteger(0, Count))
585 return make_error<StringError>(
586 formatv("invalid HardwareLoopPass parameter '{0}' ", ParamName).str(),
588 HardwareLoopOpts.setCounterBitwidth(Count);
589 continue;
590 }
591 if (ParamName == "force-hardware-loops") {
592 HardwareLoopOpts.setForce(true);
593 } else if (ParamName == "force-hardware-loop-phi") {
594 HardwareLoopOpts.setForcePhi(true);
595 } else if (ParamName == "force-nested-hardware-loop") {
596 HardwareLoopOpts.setForceNested(true);
597 } else if (ParamName == "force-hardware-loop-guard") {
598 HardwareLoopOpts.setForceGuard(true);
599 } else {
600 return make_error<StringError>(
601 formatv("invalid HardwarePass parameter '{0}' ", ParamName).str(),
603 }
604 }
605 return HardwareLoopOpts;
606}
607
608/// Parser of parameters for LoopUnroll pass.
609Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
610 LoopUnrollOptions UnrollOpts;
611 while (!Params.empty()) {
612 StringRef ParamName;
613 std::tie(ParamName, Params) = Params.split(';');
614 std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
615 // Don't accept -Os/-Oz.
616 if (OptLevel && !OptLevel->isOptimizingForSize()) {
617 UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
618 continue;
619 }
620 if (ParamName.consume_front("full-unroll-max=")) {
621 int Count;
622 if (ParamName.getAsInteger(0, Count))
623 return make_error<StringError>(
624 formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
626 UnrollOpts.setFullUnrollMaxCount(Count);
627 continue;
628 }
629
630 bool Enable = !ParamName.consume_front("no-");
631 if (ParamName == "partial") {
632 UnrollOpts.setPartial(Enable);
633 } else if (ParamName == "peeling") {
634 UnrollOpts.setPeeling(Enable);
635 } else if (ParamName == "profile-peeling") {
636 UnrollOpts.setProfileBasedPeeling(Enable);
637 } else if (ParamName == "runtime") {
638 UnrollOpts.setRuntime(Enable);
639 } else if (ParamName == "upperbound") {
640 UnrollOpts.setUpperBound(Enable);
641 } else {
642 return make_error<StringError>(
643 formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
645 }
646 }
647 return UnrollOpts;
648}
649
650Expected<bool> parseGlobalDCEPassOptions(StringRef Params) {
652 Params, "vfe-linkage-unit-visibility", "GlobalDCE");
653}
654
655Expected<bool> parseCGProfilePassOptions(StringRef Params) {
656 return PassBuilder::parseSinglePassOption(Params, "in-lto-post-link",
657 "CGProfile");
658}
659
660Expected<bool> parseInlinerPassOptions(StringRef Params) {
661 return PassBuilder::parseSinglePassOption(Params, "only-mandatory",
662 "InlinerPass");
663}
664
665Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
666 return PassBuilder::parseSinglePassOption(Params, "reuse-storage",
667 "CoroSplitPass");
668}
669
670Expected<bool> parsePostOrderFunctionAttrsPassOptions(StringRef Params) {
672 Params, "skip-non-recursive-function-attrs", "PostOrderFunctionAttrs");
673}
674
675Expected<CFGuardPass::Mechanism> parseCFGuardPassOptions(StringRef Params) {
676 if (Params.empty())
678
679 auto [Param, RHS] = Params.split(';');
680 if (!RHS.empty())
681 return make_error<StringError>(
682 formatv("too many CFGuardPass parameters '{0}' ", Params).str(),
684
685 if (Param == "check")
687 if (Param == "dispatch")
689
690 return make_error<StringError>(
691 formatv("invalid CFGuardPass mechanism: '{0}' ", Param).str(),
693}
694
695Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
696 return PassBuilder::parseSinglePassOption(Params, "memssa", "EarlyCSE");
697}
698
699Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
700 return PassBuilder::parseSinglePassOption(Params, "post-inline",
701 "EntryExitInstrumenter");
702}
703
704Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
705 return PassBuilder::parseSinglePassOption(Params, "single", "LoopExtractor");
706}
707
708Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
709 return PassBuilder::parseSinglePassOption(Params, "minimal",
710 "LowerMatrixIntrinsics");
711}
712
713Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
715 while (!Params.empty()) {
716 StringRef ParamName;
717 std::tie(ParamName, Params) = Params.split(';');
718
719 if (ParamName == "kernel") {
720 Result.CompileKernel = true;
721 } else {
722 return make_error<StringError>(
723 formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName)
724 .str(),
726 }
727 }
728 return Result;
729}
730
731Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
733 while (!Params.empty()) {
734 StringRef ParamName;
735 std::tie(ParamName, Params) = Params.split(';');
736
737 if (ParamName == "recover") {
738 Result.Recover = true;
739 } else if (ParamName == "kernel") {
740 Result.CompileKernel = true;
741 } else {
742 return make_error<StringError>(
743 formatv("invalid HWAddressSanitizer pass parameter '{0}' ", ParamName)
744 .str(),
746 }
747 }
748 return Result;
749}
750
751Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
753 while (!Params.empty()) {
754 StringRef ParamName;
755 std::tie(ParamName, Params) = Params.split(';');
756
757 if (ParamName == "thinlto") {
758 Result.IsThinLTO = true;
759 } else if (ParamName == "emit-summary") {
760 Result.EmitLTOSummary = true;
761 } else {
762 return make_error<StringError>(
763 formatv("invalid EmbedBitcode pass parameter '{0}' ", ParamName)
764 .str(),
766 }
767 }
768 return Result;
769}
770
771Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
773 while (!Params.empty()) {
774 StringRef ParamName;
775 std::tie(ParamName, Params) = Params.split(';');
776
777 if (ParamName == "recover") {
778 Result.Recover = true;
779 } else if (ParamName == "kernel") {
780 Result.Kernel = true;
781 } else if (ParamName.consume_front("track-origins=")) {
782 if (ParamName.getAsInteger(0, Result.TrackOrigins))
783 return make_error<StringError>(
784 formatv("invalid argument to MemorySanitizer pass track-origins "
785 "parameter: '{0}' ",
786 ParamName)
787 .str(),
789 } else if (ParamName == "eager-checks") {
790 Result.EagerChecks = true;
791 } else {
792 return make_error<StringError>(
793 formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
794 .str(),
796 }
797 }
798 return Result;
799}
800
801/// Parser of parameters for SimplifyCFG pass.
802Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
804 while (!Params.empty()) {
805 StringRef ParamName;
806 std::tie(ParamName, Params) = Params.split(';');
807
808 bool Enable = !ParamName.consume_front("no-");
809 if (ParamName == "speculate-blocks") {
810 Result.speculateBlocks(Enable);
811 } else if (ParamName == "simplify-cond-branch") {
812 Result.setSimplifyCondBranch(Enable);
813 } else if (ParamName == "forward-switch-cond") {
814 Result.forwardSwitchCondToPhi(Enable);
815 } else if (ParamName == "switch-range-to-icmp") {
816 Result.convertSwitchRangeToICmp(Enable);
817 } else if (ParamName == "switch-to-lookup") {
818 Result.convertSwitchToLookupTable(Enable);
819 } else if (ParamName == "keep-loops") {
820 Result.needCanonicalLoops(Enable);
821 } else if (ParamName == "hoist-common-insts") {
822 Result.hoistCommonInsts(Enable);
823 } else if (ParamName == "sink-common-insts") {
824 Result.sinkCommonInsts(Enable);
825 } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
826 APInt BonusInstThreshold;
827 if (ParamName.getAsInteger(0, BonusInstThreshold))
828 return make_error<StringError>(
829 formatv("invalid argument to SimplifyCFG pass bonus-threshold "
830 "parameter: '{0}' ",
831 ParamName).str(),
833 Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
834 } else {
835 return make_error<StringError>(
836 formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
838 }
839 }
840 return Result;
841}
842
843Expected<InstCombineOptions> parseInstCombineOptions(StringRef Params) {
845 // When specifying "instcombine" in -passes enable fix-point verification by
846 // default, as this is what most tests should use.
847 Result.setVerifyFixpoint(true);
848 while (!Params.empty()) {
849 StringRef ParamName;
850 std::tie(ParamName, Params) = Params.split(';');
851
852 bool Enable = !ParamName.consume_front("no-");
853 if (ParamName == "use-loop-info") {
854 Result.setUseLoopInfo(Enable);
855 } else if (ParamName == "verify-fixpoint") {
856 Result.setVerifyFixpoint(Enable);
857 } else if (Enable && ParamName.consume_front("max-iterations=")) {
858 APInt MaxIterations;
859 if (ParamName.getAsInteger(0, MaxIterations))
860 return make_error<StringError>(
861 formatv("invalid argument to InstCombine pass max-iterations "
862 "parameter: '{0}' ",
863 ParamName).str(),
865 Result.setMaxIterations((unsigned)MaxIterations.getZExtValue());
866 } else {
867 return make_error<StringError>(
868 formatv("invalid InstCombine pass parameter '{0}' ", ParamName).str(),
870 }
871 }
872 return Result;
873}
874
875/// Parser of parameters for LoopVectorize pass.
876Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
878 while (!Params.empty()) {
879 StringRef ParamName;
880 std::tie(ParamName, Params) = Params.split(';');
881
882 bool Enable = !ParamName.consume_front("no-");
883 if (ParamName == "interleave-forced-only") {
885 } else if (ParamName == "vectorize-forced-only") {
887 } else {
888 return make_error<StringError>(
889 formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
891 }
892 }
893 return Opts;
894}
895
896Expected<std::pair<bool, bool>> parseLoopUnswitchOptions(StringRef Params) {
897 std::pair<bool, bool> Result = {false, true};
898 while (!Params.empty()) {
899 StringRef ParamName;
900 std::tie(ParamName, Params) = Params.split(';');
901
902 bool Enable = !ParamName.consume_front("no-");
903 if (ParamName == "nontrivial") {
904 Result.first = Enable;
905 } else if (ParamName == "trivial") {
906 Result.second = Enable;
907 } else {
908 return make_error<StringError>(
909 formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
910 .str(),
912 }
913 }
914 return Result;
915}
916
917Expected<LICMOptions> parseLICMOptions(StringRef Params) {
919 while (!Params.empty()) {
920 StringRef ParamName;
921 std::tie(ParamName, Params) = Params.split(';');
922
923 bool Enable = !ParamName.consume_front("no-");
924 if (ParamName == "allowspeculation") {
925 Result.AllowSpeculation = Enable;
926 } else {
927 return make_error<StringError>(
928 formatv("invalid LICM pass parameter '{0}' ", ParamName).str(),
930 }
931 }
932 return Result;
933}
934
935Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
936 std::pair<bool, bool> Result = {true, false};
937 while (!Params.empty()) {
938 StringRef ParamName;
939 std::tie(ParamName, Params) = Params.split(';');
940
941 bool Enable = !ParamName.consume_front("no-");
942 if (ParamName == "header-duplication") {
943 Result.first = Enable;
944 } else if (ParamName == "prepare-for-lto") {
945 Result.second = Enable;
946 } else {
947 return make_error<StringError>(
948 formatv("invalid LoopRotate pass parameter '{0}' ", ParamName).str(),
950 }
951 }
952 return Result;
953}
954
955Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
956 bool Result = false;
957 while (!Params.empty()) {
958 StringRef ParamName;
959 std::tie(ParamName, Params) = Params.split(';');
960
961 bool Enable = !ParamName.consume_front("no-");
962 if (ParamName == "split-footer-bb") {
963 Result = Enable;
964 } else {
965 return make_error<StringError>(
966 formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ",
967 ParamName)
968 .str(),
970 }
971 }
972 return Result;
973}
974
975Expected<GVNOptions> parseGVNOptions(StringRef Params) {
977 while (!Params.empty()) {
978 StringRef ParamName;
979 std::tie(ParamName, Params) = Params.split(';');
980
981 bool Enable = !ParamName.consume_front("no-");
982 if (ParamName == "pre") {
983 Result.setPRE(Enable);
984 } else if (ParamName == "load-pre") {
985 Result.setLoadPRE(Enable);
986 } else if (ParamName == "split-backedge-load-pre") {
987 Result.setLoadPRESplitBackedge(Enable);
988 } else if (ParamName == "memdep") {
989 Result.setMemDep(Enable);
990 } else {
991 return make_error<StringError>(
992 formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
994 }
995 }
996 return Result;
997}
998
999Expected<IPSCCPOptions> parseIPSCCPOptions(StringRef Params) {
1001 while (!Params.empty()) {
1002 StringRef ParamName;
1003 std::tie(ParamName, Params) = Params.split(';');
1004
1005 bool Enable = !ParamName.consume_front("no-");
1006 if (ParamName == "func-spec")
1007 Result.setFuncSpec(Enable);
1008 else
1009 return make_error<StringError>(
1010 formatv("invalid IPSCCP pass parameter '{0}' ", ParamName).str(),
1012 }
1013 return Result;
1014}
1015
1016Expected<SROAOptions> parseSROAOptions(StringRef Params) {
1017 if (Params.empty() || Params == "modify-cfg")
1019 if (Params == "preserve-cfg")
1021 return make_error<StringError>(
1022 formatv("invalid SROA pass parameter '{0}' (either preserve-cfg or "
1023 "modify-cfg can be specified)",
1024 Params)
1025 .str(),
1027}
1028
1030parseStackLifetimeOptions(StringRef Params) {
1032 while (!Params.empty()) {
1033 StringRef ParamName;
1034 std::tie(ParamName, Params) = Params.split(';');
1035
1036 if (ParamName == "may") {
1038 } else if (ParamName == "must") {
1040 } else {
1041 return make_error<StringError>(
1042 formatv("invalid StackLifetime parameter '{0}' ", ParamName).str(),
1044 }
1045 }
1046 return Result;
1047}
1048
1049Expected<bool> parseDependenceAnalysisPrinterOptions(StringRef Params) {
1050 return PassBuilder::parseSinglePassOption(Params, "normalized-results",
1051 "DependenceAnalysisPrinter");
1052}
1053
1054Expected<bool> parseSeparateConstOffsetFromGEPPassOptions(StringRef Params) {
1055 return PassBuilder::parseSinglePassOption(Params, "lower-gep",
1056 "SeparateConstOffsetFromGEP");
1057}
1058
1060parseFunctionSimplificationPipelineOptions(StringRef Params) {
1061 std::optional<OptimizationLevel> L = parseOptLevel(Params);
1062 if (!L || *L == OptimizationLevel::O0) {
1063 return make_error<StringError>(
1064 formatv("invalid function-simplification parameter '{0}' ", Params)
1065 .str(),
1067 };
1068 return *L;
1069}
1070
1071Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
1072 return PassBuilder::parseSinglePassOption(Params, "no-ensure-optimized-uses",
1073 "MemorySSAPrinterPass");
1074}
1075
1076Expected<bool> parseSpeculativeExecutionPassOptions(StringRef Params) {
1077 return PassBuilder::parseSinglePassOption(Params, "only-if-divergent-target",
1078 "SpeculativeExecutionPass");
1079}
1080
1081Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
1082 std::string Result;
1083 while (!Params.empty()) {
1084 StringRef ParamName;
1085 std::tie(ParamName, Params) = Params.split(';');
1086
1087 if (ParamName.consume_front("profile-filename=")) {
1088 Result = ParamName.str();
1089 } else {
1090 return make_error<StringError>(
1091 formatv("invalid MemProfUse pass parameter '{0}' ", ParamName).str(),
1093 }
1094 }
1095 return Result;
1096}
1097
1098Expected<bool> parseStructuralHashPrinterPassOptions(StringRef Params) {
1099 return PassBuilder::parseSinglePassOption(Params, "detailed",
1100 "StructuralHashPrinterPass");
1101}
1102
1103Expected<bool> parseWinEHPrepareOptions(StringRef Params) {
1104 return PassBuilder::parseSinglePassOption(Params, "demote-catchswitch-only",
1105 "WinEHPreparePass");
1106}
1107
1108Expected<GlobalMergeOptions> parseGlobalMergeOptions(StringRef Params) {
1110 while (!Params.empty()) {
1111 StringRef ParamName;
1112 std::tie(ParamName, Params) = Params.split(';');
1113
1114 bool Enable = !ParamName.consume_front("no-");
1115 if (ParamName == "group-by-use")
1116 Result.GroupByUse = Enable;
1117 else if (ParamName == "ignore-single-use")
1118 Result.IgnoreSingleUse = Enable;
1119 else if (ParamName == "merge-const")
1120 Result.MergeConst = Enable;
1121 else if (ParamName == "merge-external")
1122 Result.MergeExternal = Enable;
1123 else if (ParamName.consume_front("max-offset=")) {
1124 if (ParamName.getAsInteger(0, Result.MaxOffset))
1125 return make_error<StringError>(
1126 formatv("invalid GlobalMergePass parameter '{0}' ", ParamName)
1127 .str(),
1129 }
1130 }
1131 return Result;
1132}
1133
1134} // namespace
1135
1136/// Tests whether a pass name starts with a valid prefix for a default pipeline
1137/// alias.
1139 return Name.starts_with("default") || Name.starts_with("thinlto") ||
1140 Name.starts_with("lto");
1141}
1142
1143/// Tests whether registered callbacks will accept a given pass name.
1144///
1145/// When parsing a pipeline text, the type of the outermost pipeline may be
1146/// omitted, in which case the type is automatically determined from the first
1147/// pass name in the text. This may be a name that is handled through one of the
1148/// callbacks. We check this through the oridinary parsing callbacks by setting
1149/// up a dummy PassManager in order to not force the client to also handle this
1150/// type of query.
1151template <typename PassManagerT, typename CallbacksT>
1152static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1153 if (!Callbacks.empty()) {
1154 PassManagerT DummyPM;
1155 for (auto &CB : Callbacks)
1156 if (CB(Name, DummyPM, {}))
1157 return true;
1158 }
1159 return false;
1160}
1161
1162template <typename CallbacksT>
1163static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1164 // Manually handle aliases for pre-configured pipeline fragments.
1167
1168 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1169
1170 // Explicitly handle pass manager names.
1171 if (Name == "module")
1172 return true;
1173 if (Name == "cgscc")
1174 return true;
1175 if (NameNoBracket == "function")
1176 return true;
1177 if (Name == "coro-cond")
1178 return true;
1179
1180 // Explicitly handle custom-parsed pass names.
1182 return true;
1183
1184#define MODULE_PASS(NAME, CREATE_PASS) \
1185 if (Name == NAME) \
1186 return true;
1187#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1188 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1189 return true;
1190#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1191 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1192 return true;
1193#include "PassRegistry.def"
1194
1195 return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1196}
1197
1198template <typename CallbacksT>
1199static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1200 // Explicitly handle pass manager names.
1201 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1202 if (Name == "cgscc")
1203 return true;
1204 if (NameNoBracket == "function")
1205 return true;
1206
1207 // Explicitly handle custom-parsed pass names.
1209 return true;
1211 return true;
1212
1213#define CGSCC_PASS(NAME, CREATE_PASS) \
1214 if (Name == NAME) \
1215 return true;
1216#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1217 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1218 return true;
1219#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1220 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1221 return true;
1222#include "PassRegistry.def"
1223
1224 return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1225}
1226
1227template <typename CallbacksT>
1228static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1229 // Explicitly handle pass manager names.
1230 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1231 if (NameNoBracket == "function")
1232 return true;
1233 if (Name == "loop" || Name == "loop-mssa")
1234 return true;
1235
1236 // Explicitly handle custom-parsed pass names.
1238 return true;
1239
1240#define FUNCTION_PASS(NAME, CREATE_PASS) \
1241 if (Name == NAME) \
1242 return true;
1243#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1244 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1245 return true;
1246#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1247 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1248 return true;
1249#include "PassRegistry.def"
1250
1251 return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1252}
1253
1254template <typename CallbacksT>
1255static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1256 // Explicitly handle pass manager names.
1257 if (Name == "machine-function")
1258 return true;
1259
1260 // Explicitly handle custom-parsed pass names.
1262 return true;
1263
1264#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1265 if (Name == NAME) \
1266 return true;
1267#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1268 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1269 return true;
1270
1271#include "llvm/Passes/MachinePassRegistry.def"
1272
1273 return callbacksAcceptPassName<MachineFunctionPassManager>(Name, Callbacks);
1274}
1275
1276template <typename CallbacksT>
1277static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
1278 bool &UseMemorySSA) {
1279 UseMemorySSA = false;
1280
1281 // Explicitly handle custom-parsed pass names.
1283 return true;
1284
1286 UseMemorySSA = true;
1287 return true;
1288 }
1289
1290#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1291 if (Name == NAME) \
1292 return true;
1293#include "PassRegistry.def"
1294
1295 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1296}
1297
1298template <typename CallbacksT>
1299static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
1300 bool &UseMemorySSA) {
1301 UseMemorySSA = false;
1302
1303 // Explicitly handle custom-parsed pass names.
1305 return true;
1306
1308 UseMemorySSA = true;
1309 return true;
1310 }
1311
1312#define LOOP_PASS(NAME, CREATE_PASS) \
1313 if (Name == NAME) \
1314 return true;
1315#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1316 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1317 return true;
1318#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1319 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1320 return true;
1321#include "PassRegistry.def"
1322
1323 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1324}
1325
1326std::optional<std::vector<PassBuilder::PipelineElement>>
1327PassBuilder::parsePipelineText(StringRef Text) {
1328 std::vector<PipelineElement> ResultPipeline;
1329
1330 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1331 &ResultPipeline};
1332 for (;;) {
1333 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1334 size_t Pos = Text.find_first_of(",()");
1335 Pipeline.push_back({Text.substr(0, Pos), {}});
1336
1337 // If we have a single terminating name, we're done.
1338 if (Pos == Text.npos)
1339 break;
1340
1341 char Sep = Text[Pos];
1342 Text = Text.substr(Pos + 1);
1343 if (Sep == ',')
1344 // Just a name ending in a comma, continue.
1345 continue;
1346
1347 if (Sep == '(') {
1348 // Push the inner pipeline onto the stack to continue processing.
1349 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1350 continue;
1351 }
1352
1353 assert(Sep == ')' && "Bogus separator!");
1354 // When handling the close parenthesis, we greedily consume them to avoid
1355 // empty strings in the pipeline.
1356 do {
1357 // If we try to pop the outer pipeline we have unbalanced parentheses.
1358 if (PipelineStack.size() == 1)
1359 return std::nullopt;
1360
1361 PipelineStack.pop_back();
1362 } while (Text.consume_front(")"));
1363
1364 // Check if we've finished parsing.
1365 if (Text.empty())
1366 break;
1367
1368 // Otherwise, the end of an inner pipeline always has to be followed by
1369 // a comma, and then we can continue.
1370 if (!Text.consume_front(","))
1371 return std::nullopt;
1372 }
1373
1374 if (PipelineStack.size() > 1)
1375 // Unbalanced paretheses.
1376 return std::nullopt;
1377
1378 assert(PipelineStack.back() == &ResultPipeline &&
1379 "Wrong pipeline at the bottom of the stack!");
1380 return {std::move(ResultPipeline)};
1381}
1382
1383Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1384 const PipelineElement &E) {
1385 auto &Name = E.Name;
1386 auto &InnerPipeline = E.InnerPipeline;
1387
1388 // First handle complex passes like the pass managers which carry pipelines.
1389 if (!InnerPipeline.empty()) {
1390 if (Name == "module") {
1391 ModulePassManager NestedMPM;
1392 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1393 return Err;
1394 MPM.addPass(std::move(NestedMPM));
1395 return Error::success();
1396 }
1397 if (Name == "coro-cond") {
1398 ModulePassManager NestedMPM;
1399 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1400 return Err;
1401 MPM.addPass(CoroConditionalWrapper(std::move(NestedMPM)));
1402 return Error::success();
1403 }
1404 if (Name == "cgscc") {
1405 CGSCCPassManager CGPM;
1406 if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1407 return Err;
1409 return Error::success();
1410 }
1411 if (Name == "machine-function") {
1413 if (auto Err = parseMachinePassPipeline(MFPM, InnerPipeline))
1414 return Err;
1416 return Error::success();
1417 }
1418 if (auto Params = parseFunctionPipelineName(Name)) {
1419 if (Params->second)
1420 return make_error<StringError>(
1421 "cannot have a no-rerun module to function adaptor",
1424 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1425 return Err;
1426 MPM.addPass(
1427 createModuleToFunctionPassAdaptor(std::move(FPM), Params->first));
1428 return Error::success();
1429 }
1430 if (auto Count = parseRepeatPassName(Name)) {
1431 ModulePassManager NestedMPM;
1432 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1433 return Err;
1434 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1435 return Error::success();
1436 }
1437
1438 for (auto &C : ModulePipelineParsingCallbacks)
1439 if (C(Name, MPM, InnerPipeline))
1440 return Error::success();
1441
1442 // Normal passes can't have pipelines.
1443 return make_error<StringError>(
1444 formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1446 ;
1447 }
1448
1449 // Manually handle aliases for pre-configured pipeline fragments.
1452 if (!DefaultAliasRegex.match(Name, &Matches))
1453 return make_error<StringError>(
1454 formatv("unknown default pipeline alias '{0}'", Name).str(),
1456
1457 assert(Matches.size() == 3 && "Must capture two matched strings!");
1458
1459 OptimizationLevel L = *parseOptLevel(Matches[2]);
1460
1461 // This is consistent with old pass manager invoked via opt, but
1462 // inconsistent with clang. Clang doesn't enable loop vectorization
1463 // but does enable slp vectorization at Oz.
1464 PTO.LoopVectorization =
1465 L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1466 PTO.SLPVectorization =
1467 L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1468
1469 if (Matches[1] == "default") {
1471 } else if (Matches[1] == "thinlto-pre-link") {
1473 } else if (Matches[1] == "thinlto") {
1475 } else if (Matches[1] == "lto-pre-link") {
1476 if (PTO.UnifiedLTO)
1477 // When UnifiedLTO is enabled, use the ThinLTO pre-link pipeline. This
1478 // avoids compile-time performance regressions and keeps the pre-link
1479 // LTO pipeline "unified" for both LTO modes.
1481 else
1483 } else {
1484 assert(Matches[1] == "lto" && "Not one of the matched options!");
1485 MPM.addPass(buildLTODefaultPipeline(L, nullptr));
1486 }
1487 return Error::success();
1488 }
1489
1490 // Finally expand the basic registered passes from the .inc file.
1491#define MODULE_PASS(NAME, CREATE_PASS) \
1492 if (Name == NAME) { \
1493 MPM.addPass(CREATE_PASS); \
1494 return Error::success(); \
1495 }
1496#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1497 if (checkParametrizedPassName(Name, NAME)) { \
1498 auto Params = parsePassParameters(PARSER, Name, NAME); \
1499 if (!Params) \
1500 return Params.takeError(); \
1501 MPM.addPass(CREATE_PASS(Params.get())); \
1502 return Error::success(); \
1503 }
1504#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1505 if (Name == "require<" NAME ">") { \
1506 MPM.addPass( \
1507 RequireAnalysisPass< \
1508 std::remove_reference_t<decltype(CREATE_PASS)>, Module>()); \
1509 return Error::success(); \
1510 } \
1511 if (Name == "invalidate<" NAME ">") { \
1512 MPM.addPass(InvalidateAnalysisPass< \
1513 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1514 return Error::success(); \
1515 }
1516#define CGSCC_PASS(NAME, CREATE_PASS) \
1517 if (Name == NAME) { \
1518 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1519 return Error::success(); \
1520 }
1521#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1522 if (checkParametrizedPassName(Name, NAME)) { \
1523 auto Params = parsePassParameters(PARSER, Name, NAME); \
1524 if (!Params) \
1525 return Params.takeError(); \
1526 MPM.addPass( \
1527 createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1528 return Error::success(); \
1529 }
1530#define FUNCTION_PASS(NAME, CREATE_PASS) \
1531 if (Name == NAME) { \
1532 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1533 return Error::success(); \
1534 }
1535#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1536 if (checkParametrizedPassName(Name, NAME)) { \
1537 auto Params = parsePassParameters(PARSER, Name, NAME); \
1538 if (!Params) \
1539 return Params.takeError(); \
1540 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1541 return Error::success(); \
1542 }
1543#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1544 if (Name == NAME) { \
1545 MPM.addPass(createModuleToFunctionPassAdaptor( \
1546 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1547 return Error::success(); \
1548 }
1549#define LOOP_PASS(NAME, CREATE_PASS) \
1550 if (Name == NAME) { \
1551 MPM.addPass(createModuleToFunctionPassAdaptor( \
1552 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1553 return Error::success(); \
1554 }
1555#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1556 if (checkParametrizedPassName(Name, NAME)) { \
1557 auto Params = parsePassParameters(PARSER, Name, NAME); \
1558 if (!Params) \
1559 return Params.takeError(); \
1560 MPM.addPass( \
1561 createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1562 CREATE_PASS(Params.get()), false, false))); \
1563 return Error::success(); \
1564 }
1565#include "PassRegistry.def"
1566
1567 for (auto &C : ModulePipelineParsingCallbacks)
1568 if (C(Name, MPM, InnerPipeline))
1569 return Error::success();
1570 return make_error<StringError>(
1571 formatv("unknown module pass '{0}'", Name).str(),
1573}
1574
1575Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1576 const PipelineElement &E) {
1577 auto &Name = E.Name;
1578 auto &InnerPipeline = E.InnerPipeline;
1579
1580 // First handle complex passes like the pass managers which carry pipelines.
1581 if (!InnerPipeline.empty()) {
1582 if (Name == "cgscc") {
1583 CGSCCPassManager NestedCGPM;
1584 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1585 return Err;
1586 // Add the nested pass manager with the appropriate adaptor.
1587 CGPM.addPass(std::move(NestedCGPM));
1588 return Error::success();
1589 }
1590 if (auto Params = parseFunctionPipelineName(Name)) {
1592 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1593 return Err;
1594 // Add the nested pass manager with the appropriate adaptor.
1596 std::move(FPM), Params->first, Params->second));
1597 return Error::success();
1598 }
1599 if (auto Count = parseRepeatPassName(Name)) {
1600 CGSCCPassManager NestedCGPM;
1601 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1602 return Err;
1603 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1604 return Error::success();
1605 }
1606 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1607 CGSCCPassManager NestedCGPM;
1608 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1609 return Err;
1610 CGPM.addPass(
1611 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1612 return Error::success();
1613 }
1614
1615 for (auto &C : CGSCCPipelineParsingCallbacks)
1616 if (C(Name, CGPM, InnerPipeline))
1617 return Error::success();
1618
1619 // Normal passes can't have pipelines.
1620 return make_error<StringError>(
1621 formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1623 }
1624
1625// Now expand the basic registered passes from the .inc file.
1626#define CGSCC_PASS(NAME, CREATE_PASS) \
1627 if (Name == NAME) { \
1628 CGPM.addPass(CREATE_PASS); \
1629 return Error::success(); \
1630 }
1631#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1632 if (checkParametrizedPassName(Name, NAME)) { \
1633 auto Params = parsePassParameters(PARSER, Name, NAME); \
1634 if (!Params) \
1635 return Params.takeError(); \
1636 CGPM.addPass(CREATE_PASS(Params.get())); \
1637 return Error::success(); \
1638 }
1639#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1640 if (Name == "require<" NAME ">") { \
1641 CGPM.addPass(RequireAnalysisPass< \
1642 std::remove_reference_t<decltype(CREATE_PASS)>, \
1643 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1644 CGSCCUpdateResult &>()); \
1645 return Error::success(); \
1646 } \
1647 if (Name == "invalidate<" NAME ">") { \
1648 CGPM.addPass(InvalidateAnalysisPass< \
1649 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1650 return Error::success(); \
1651 }
1652#define FUNCTION_PASS(NAME, CREATE_PASS) \
1653 if (Name == NAME) { \
1654 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
1655 return Error::success(); \
1656 }
1657#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1658 if (checkParametrizedPassName(Name, NAME)) { \
1659 auto Params = parsePassParameters(PARSER, Name, NAME); \
1660 if (!Params) \
1661 return Params.takeError(); \
1662 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1663 return Error::success(); \
1664 }
1665#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1666 if (Name == NAME) { \
1667 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1668 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1669 return Error::success(); \
1670 }
1671#define LOOP_PASS(NAME, CREATE_PASS) \
1672 if (Name == NAME) { \
1673 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1674 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1675 return Error::success(); \
1676 }
1677#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1678 if (checkParametrizedPassName(Name, NAME)) { \
1679 auto Params = parsePassParameters(PARSER, Name, NAME); \
1680 if (!Params) \
1681 return Params.takeError(); \
1682 CGPM.addPass( \
1683 createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1684 CREATE_PASS(Params.get()), false, false))); \
1685 return Error::success(); \
1686 }
1687#include "PassRegistry.def"
1688
1689 for (auto &C : CGSCCPipelineParsingCallbacks)
1690 if (C(Name, CGPM, InnerPipeline))
1691 return Error::success();
1692 return make_error<StringError>(
1693 formatv("unknown cgscc pass '{0}'", Name).str(),
1695}
1696
1697Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1698 const PipelineElement &E) {
1699 auto &Name = E.Name;
1700 auto &InnerPipeline = E.InnerPipeline;
1701
1702 // First handle complex passes like the pass managers which carry pipelines.
1703 if (!InnerPipeline.empty()) {
1704 if (Name == "function") {
1705 FunctionPassManager NestedFPM;
1706 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1707 return Err;
1708 // Add the nested pass manager with the appropriate adaptor.
1709 FPM.addPass(std::move(NestedFPM));
1710 return Error::success();
1711 }
1712 if (Name == "loop" || Name == "loop-mssa") {
1713 LoopPassManager LPM;
1714 if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
1715 return Err;
1716 // Add the nested pass manager with the appropriate adaptor.
1717 bool UseMemorySSA = (Name == "loop-mssa");
1718 bool UseBFI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1719 return Pipeline.Name.contains("simple-loop-unswitch");
1720 });
1721 bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1722 return Pipeline.Name == "loop-predication";
1723 });
1724 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
1725 UseBFI, UseBPI));
1726 return Error::success();
1727 }
1728 if (auto Count = parseRepeatPassName(Name)) {
1729 FunctionPassManager NestedFPM;
1730 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1731 return Err;
1732 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1733 return Error::success();
1734 }
1735
1736 for (auto &C : FunctionPipelineParsingCallbacks)
1737 if (C(Name, FPM, InnerPipeline))
1738 return Error::success();
1739
1740 // Normal passes can't have pipelines.
1741 return make_error<StringError>(
1742 formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1744 }
1745
1746// Now expand the basic registered passes from the .inc file.
1747#define FUNCTION_PASS(NAME, CREATE_PASS) \
1748 if (Name == NAME) { \
1749 FPM.addPass(CREATE_PASS); \
1750 return Error::success(); \
1751 }
1752#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1753 if (checkParametrizedPassName(Name, NAME)) { \
1754 auto Params = parsePassParameters(PARSER, Name, NAME); \
1755 if (!Params) \
1756 return Params.takeError(); \
1757 FPM.addPass(CREATE_PASS(Params.get())); \
1758 return Error::success(); \
1759 }
1760#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1761 if (Name == "require<" NAME ">") { \
1762 FPM.addPass( \
1763 RequireAnalysisPass< \
1764 std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
1765 return Error::success(); \
1766 } \
1767 if (Name == "invalidate<" NAME ">") { \
1768 FPM.addPass(InvalidateAnalysisPass< \
1769 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1770 return Error::success(); \
1771 }
1772// FIXME: UseMemorySSA is set to false. Maybe we could do things like:
1773// bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
1774// "guard-widening");
1775// The risk is that it may become obsolete if we're not careful.
1776#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1777 if (Name == NAME) { \
1778 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1779 return Error::success(); \
1780 }
1781#define LOOP_PASS(NAME, CREATE_PASS) \
1782 if (Name == NAME) { \
1783 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1784 return Error::success(); \
1785 }
1786#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1787 if (checkParametrizedPassName(Name, NAME)) { \
1788 auto Params = parsePassParameters(PARSER, Name, NAME); \
1789 if (!Params) \
1790 return Params.takeError(); \
1791 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
1792 false, false)); \
1793 return Error::success(); \
1794 }
1795#include "PassRegistry.def"
1796
1797 for (auto &C : FunctionPipelineParsingCallbacks)
1798 if (C(Name, FPM, InnerPipeline))
1799 return Error::success();
1800 return make_error<StringError>(
1801 formatv("unknown function pass '{0}'", Name).str(),
1803}
1804
1805Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
1806 const PipelineElement &E) {
1807 StringRef Name = E.Name;
1808 auto &InnerPipeline = E.InnerPipeline;
1809
1810 // First handle complex passes like the pass managers which carry pipelines.
1811 if (!InnerPipeline.empty()) {
1812 if (Name == "loop") {
1813 LoopPassManager NestedLPM;
1814 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1815 return Err;
1816 // Add the nested pass manager with the appropriate adaptor.
1817 LPM.addPass(std::move(NestedLPM));
1818 return Error::success();
1819 }
1820 if (auto Count = parseRepeatPassName(Name)) {
1821 LoopPassManager NestedLPM;
1822 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1823 return Err;
1824 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
1825 return Error::success();
1826 }
1827
1828 for (auto &C : LoopPipelineParsingCallbacks)
1829 if (C(Name, LPM, InnerPipeline))
1830 return Error::success();
1831
1832 // Normal passes can't have pipelines.
1833 return make_error<StringError>(
1834 formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
1836 }
1837
1838// Now expand the basic registered passes from the .inc file.
1839#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1840 if (Name == NAME) { \
1841 LPM.addPass(CREATE_PASS); \
1842 return Error::success(); \
1843 }
1844#define LOOP_PASS(NAME, CREATE_PASS) \
1845 if (Name == NAME) { \
1846 LPM.addPass(CREATE_PASS); \
1847 return Error::success(); \
1848 }
1849#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1850 if (checkParametrizedPassName(Name, NAME)) { \
1851 auto Params = parsePassParameters(PARSER, Name, NAME); \
1852 if (!Params) \
1853 return Params.takeError(); \
1854 LPM.addPass(CREATE_PASS(Params.get())); \
1855 return Error::success(); \
1856 }
1857#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1858 if (Name == "require<" NAME ">") { \
1859 LPM.addPass(RequireAnalysisPass< \
1860 std::remove_reference_t<decltype(CREATE_PASS)>, Loop, \
1861 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1862 LPMUpdater &>()); \
1863 return Error::success(); \
1864 } \
1865 if (Name == "invalidate<" NAME ">") { \
1866 LPM.addPass(InvalidateAnalysisPass< \
1867 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1868 return Error::success(); \
1869 }
1870#include "PassRegistry.def"
1871
1872 for (auto &C : LoopPipelineParsingCallbacks)
1873 if (C(Name, LPM, InnerPipeline))
1874 return Error::success();
1875 return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
1877}
1878
1879Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
1880 const PipelineElement &E) {
1881 StringRef Name = E.Name;
1882 if (!E.InnerPipeline.empty())
1883 return make_error<StringError>("invalid pipeline",
1885
1886#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) \
1887 if (Name == NAME) { \
1888 MFPM.addPass(CREATE_PASS); \
1889 return Error::success(); \
1890 }
1891#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1892 if (Name == NAME) { \
1893 MFPM.addPass(CREATE_PASS); \
1894 return Error::success(); \
1895 }
1896#include "llvm/Passes/MachinePassRegistry.def"
1897
1898 for (auto &C : MachineFunctionPipelineParsingCallbacks)
1899 if (C(Name, MFPM, E.InnerPipeline))
1900 return Error::success();
1901 return make_error<StringError>(
1902 formatv("unknown machine pass '{0}'", Name).str(),
1904}
1905
1906bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
1907#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1908 if (Name == NAME) { \
1909 AA.registerModuleAnalysis< \
1910 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1911 return true; \
1912 }
1913#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1914 if (Name == NAME) { \
1915 AA.registerFunctionAnalysis< \
1916 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1917 return true; \
1918 }
1919#include "PassRegistry.def"
1920
1921 for (auto &C : AAParsingCallbacks)
1922 if (C(Name, AA))
1923 return true;
1924 return false;
1925}
1926
1927Error PassBuilder::parseMachinePassPipeline(
1929 for (const auto &Element : Pipeline) {
1930 if (auto Err = parseMachinePass(MFPM, Element))
1931 return Err;
1932 }
1933 return Error::success();
1934}
1935
1936Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
1937 ArrayRef<PipelineElement> Pipeline) {
1938 for (const auto &Element : Pipeline) {
1939 if (auto Err = parseLoopPass(LPM, Element))
1940 return Err;
1941 }
1942 return Error::success();
1943}
1944
1945Error PassBuilder::parseFunctionPassPipeline(
1947 for (const auto &Element : Pipeline) {
1948 if (auto Err = parseFunctionPass(FPM, Element))
1949 return Err;
1950 }
1951 return Error::success();
1952}
1953
1954Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1955 ArrayRef<PipelineElement> Pipeline) {
1956 for (const auto &Element : Pipeline) {
1957 if (auto Err = parseCGSCCPass(CGPM, Element))
1958 return Err;
1959 }
1960 return Error::success();
1961}
1962
1975 if (MFAM) {
1977 [&] { return MachineFunctionAnalysisManagerModuleProxy(*MFAM); });
1978 MFAM->registerPass(
1980 MFAM->registerPass(
1982 }
1983}
1984
1985Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1986 ArrayRef<PipelineElement> Pipeline) {
1987 for (const auto &Element : Pipeline) {
1988 if (auto Err = parseModulePass(MPM, Element))
1989 return Err;
1990 }
1991 return Error::success();
1992}
1993
1994// Primary pass pipeline description parsing routine for a \c ModulePassManager
1995// FIXME: Should this routine accept a TargetMachine or require the caller to
1996// pre-populate the analysis managers with target-specific stuff?
1998 StringRef PipelineText) {
1999 auto Pipeline = parsePipelineText(PipelineText);
2000 if (!Pipeline || Pipeline->empty())
2001 return make_error<StringError>(
2002 formatv("invalid pipeline '{0}'", PipelineText).str(),
2004
2005 // If the first name isn't at the module layer, wrap the pipeline up
2006 // automatically.
2007 StringRef FirstName = Pipeline->front().Name;
2008
2009 if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2010 bool UseMemorySSA;
2011 if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2012 Pipeline = {{"cgscc", std::move(*Pipeline)}};
2013 } else if (isFunctionPassName(FirstName,
2014 FunctionPipelineParsingCallbacks)) {
2015 Pipeline = {{"function", std::move(*Pipeline)}};
2016 } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
2017 UseMemorySSA)) {
2018 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2019 std::move(*Pipeline)}}}};
2020 } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
2021 UseMemorySSA)) {
2022 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2023 std::move(*Pipeline)}}}};
2024 } else if (isMachineFunctionPassName(
2025 FirstName, MachineFunctionPipelineParsingCallbacks)) {
2026 Pipeline = {{"machine-function", std::move(*Pipeline)}};
2027 } else {
2028 for (auto &C : TopLevelPipelineParsingCallbacks)
2029 if (C(MPM, *Pipeline))
2030 return Error::success();
2031
2032 // Unknown pass or pipeline name!
2033 auto &InnerPipeline = Pipeline->front().InnerPipeline;
2034 return make_error<StringError>(
2035 formatv("unknown {0} name '{1}'",
2036 (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2037 .str(),
2039 }
2040 }
2041
2042 if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
2043 return Err;
2044 return Error::success();
2045}
2046
2047// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2049 StringRef PipelineText) {
2050 auto Pipeline = parsePipelineText(PipelineText);
2051 if (!Pipeline || Pipeline->empty())
2052 return make_error<StringError>(
2053 formatv("invalid pipeline '{0}'", PipelineText).str(),
2055
2056 StringRef FirstName = Pipeline->front().Name;
2057 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2058 return make_error<StringError>(
2059 formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
2060 PipelineText)
2061 .str(),
2063
2064 if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
2065 return Err;
2066 return Error::success();
2067}
2068
2069// Primary pass pipeline description parsing routine for a \c
2070// FunctionPassManager
2072 StringRef PipelineText) {
2073 auto Pipeline = parsePipelineText(PipelineText);
2074 if (!Pipeline || Pipeline->empty())
2075 return make_error<StringError>(
2076 formatv("invalid pipeline '{0}'", PipelineText).str(),
2078
2079 StringRef FirstName = Pipeline->front().Name;
2080 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2081 return make_error<StringError>(
2082 formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
2083 PipelineText)
2084 .str(),
2086
2087 if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
2088 return Err;
2089 return Error::success();
2090}
2091
2092// Primary pass pipeline description parsing routine for a \c LoopPassManager
2094 StringRef PipelineText) {
2095 auto Pipeline = parsePipelineText(PipelineText);
2096 if (!Pipeline || Pipeline->empty())
2097 return make_error<StringError>(
2098 formatv("invalid pipeline '{0}'", PipelineText).str(),
2100
2101 if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
2102 return Err;
2103
2104 return Error::success();
2105}
2106
2108 StringRef PipelineText) {
2109 auto Pipeline = parsePipelineText(PipelineText);
2110 if (!Pipeline || Pipeline->empty())
2111 return make_error<StringError>(
2112 formatv("invalid machine pass pipeline '{0}'", PipelineText).str(),
2114
2115 if (auto Err = parseMachinePassPipeline(MFPM, *Pipeline))
2116 return Err;
2117
2118 return Error::success();
2119}
2120
2122 // If the pipeline just consists of the word 'default' just replace the AA
2123 // manager with our default one.
2124 if (PipelineText == "default") {
2126 return Error::success();
2127 }
2128
2129 while (!PipelineText.empty()) {
2131 std::tie(Name, PipelineText) = PipelineText.split(',');
2132 if (!parseAAPassName(AA, Name))
2133 return make_error<StringError>(
2134 formatv("unknown alias analysis name '{0}'", Name).str(),
2136 }
2137
2138 return Error::success();
2139}
2140
2142 OS << " " << PassName << "\n";
2143}
2145 raw_ostream &OS) {
2146 OS << " " << PassName << "<" << Params << ">\n";
2147}
2148
2150 // TODO: print pass descriptions when they are available
2151
2152 OS << "Module passes:\n";
2153#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2154#include "PassRegistry.def"
2155
2156 OS << "Module passes with params:\n";
2157#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2158 printPassName(NAME, PARAMS, OS);
2159#include "PassRegistry.def"
2160
2161 OS << "Module analyses:\n";
2162#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2163#include "PassRegistry.def"
2164
2165 OS << "Module alias analyses:\n";
2166#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2167#include "PassRegistry.def"
2168
2169 OS << "CGSCC passes:\n";
2170#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2171#include "PassRegistry.def"
2172
2173 OS << "CGSCC passes with params:\n";
2174#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2175 printPassName(NAME, PARAMS, OS);
2176#include "PassRegistry.def"
2177
2178 OS << "CGSCC analyses:\n";
2179#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2180#include "PassRegistry.def"
2181
2182 OS << "Function passes:\n";
2183#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2184#include "PassRegistry.def"
2185
2186 OS << "Function passes with params:\n";
2187#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2188 printPassName(NAME, PARAMS, OS);
2189#include "PassRegistry.def"
2190
2191 OS << "Function analyses:\n";
2192#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2193#include "PassRegistry.def"
2194
2195 OS << "Function alias analyses:\n";
2196#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2197#include "PassRegistry.def"
2198
2199 OS << "LoopNest passes:\n";
2200#define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2201#include "PassRegistry.def"
2202
2203 OS << "Loop passes:\n";
2204#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2205#include "PassRegistry.def"
2206
2207 OS << "Loop passes with params:\n";
2208#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2209 printPassName(NAME, PARAMS, OS);
2210#include "PassRegistry.def"
2211
2212 OS << "Loop analyses:\n";
2213#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2214#include "PassRegistry.def"
2215
2216 OS << "Machine module passes (WIP):\n";
2217#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2218#include "llvm/Passes/MachinePassRegistry.def"
2219
2220 OS << "Machine function passes (WIP):\n";
2221#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2222#include "llvm/Passes/MachinePassRegistry.def"
2223
2224 OS << "Machine function analyses (WIP):\n";
2225#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2226#include "llvm/Passes/MachinePassRegistry.def"
2227}
2228
2230 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
2231 &C) {
2232 TopLevelPipelineParsingCallbacks.push_back(C);
2233}
AggressiveInstCombiner - Combine expression patterns to form expressions with fewer,...
This file implements a simple N^2 alias analysis accuracy evaluator.
Provides passes to inlining "always_inline" functions.
This is the interface for LLVM's primary stateless and local alias analysis.
This file provides the interface for LLVM's Call Graph Profile pass.
This header provides classes for managing passes over SCCs of the call graph.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
Defines an IR pass for CodeGen Prepare.
This file declares an analysis pass that computes CycleInfo for LLVM IR, specialized from GenericCycl...
std::string Name
This file provides the interface for a simple, fast CSE pass.
This file provides a pass which clones the current module and runs the provided pass pipeline on the ...
Super simple passes to force specific function attrs from the commandline into the IR for debugging p...
Provides passes for computing function attributes based on interprocedural analyses.
This file provides the interface for the GCOV style profiler pass.
This file provides the interface for LLVM's Global Value Numbering pass which eliminates fully redund...
This is the interface for a simple mod/ref and alias analysis over globals.
Defines an IR pass for the creation of hardware loops.
AcceleratorCodeSelection - Identify all functions reachable from a kernel, removing those that are un...
This file defines passes to print out IR in various granularities.
Interfaces for passes which infer implicit function attributes from the name and signature of functio...
This file provides the primary interface to the instcombine pass.
Defines passes for running instruction simplification across chunks of IR.
This file provides the interface for LLVM's PGO Instrumentation lowering pass.
This file contains the declaration of the InterleavedAccessPass class, its corresponding pass name is...
See the comments on JumpThreadingPass.
Implements a lazy call graph analysis and related passes for the new pass manager.
This file defines the interface for the loop cache analysis.
This file provides the interface for LLVM's Loop Data Prefetching Pass.
This file implements the Loop Fusion pass.
This header defines the LoopLoadEliminationPass object.
This file defines the interface for the loop nest analysis.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
This file provides the interface for the pass responsible for removing expensive ubsan checks.
The header file for the LowerConstantIntrinsics pass as used by the new pass manager.
The header file for the LowerExpectIntrinsic pass as used by the new pass manager.
#define F(x, y, z)
Definition: MD5.cpp:55
UseBFI
Definition: MachineLICM.cpp:88
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
This pass performs merges of loads and stores on both sides of a.
This is the interface to build a ModuleSummaryIndex for a module.
Contains a collection of routines for determining if a given instruction is guaranteed to execute if ...
This file provides the interface for LLVM's Global Value Numbering pass.
This file declares a simple ARC-aware AliasAnalysis using special knowledge of Objective C to enhance...
This header enumerates the LLVM-provided high-level optimization levels.
This file provides the interface for IR based instrumentation passes ( (profile-gen,...
CGSCCAnalysisManager CGAM
ModulePassManager MPM
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
const char LLVMTargetMachineRef TM
PassInstrumentationCallbacks PIC
static bool isModulePassName(StringRef Name, CallbacksT &Callbacks)
static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks)
Tests whether registered callbacks will accept a given pass name.
static std::optional< int > parseDevirtPassName(StringRef Name)
static std::optional< int > parseRepeatPassName(StringRef Name)
static bool startsWithDefaultPipelineAliasPrefix(StringRef Name)
Tests whether a pass name starts with a valid prefix for a default pipeline alias.
static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks, bool &UseMemorySSA)
static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks)
static std::optional< OptimizationLevel > parseOptLevel(StringRef S)
static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks, bool &UseMemorySSA)
static std::optional< std::pair< bool, bool > > parseFunctionPipelineName(StringRef Name)
static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks)
static void printPassName(StringRef PassName, raw_ostream &OS)
static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks)
static const Regex DefaultAliasRegex("^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$")
This header defines various interfaces for pass management in LLVM.
This file implements the PredicateInfo analysis, which creates an Extended SSA form for operations us...
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file provides the interface for LLVM's Scalar Replacement of Aggregates pass.
raw_pwrite_stream & OS
This file provides the interface for the pseudo probe implementation for AutoFDO.
This file provides the interface for the sampled PGO loader pass.
This is the interface for a SCEV-based alias analysis.
This pass converts vector operations into scalar operations (or, optionally, operations on smaller ve...
This is the interface for a metadata-based scoped no-alias analysis.
This file contains the declaration of the SelectOptimizePass class, its corresponding pass name is se...
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
This is the interface for a metadata-based TBAA.
Defines an IR pass for type promotion.
LLVM IR instance of the generic uniformity analysis.
static const char PassName[]
Value * RHS
A manager for alias analyses.
Class for arbitrary precision integers.
Definition: APInt.h:76
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1491
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1513
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:321
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:535
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition: BasicBlock.h:221
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:525
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:631
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static const OptimizationLevel O3
Optimize for fast execution as much as possible.
static const OptimizationLevel Oz
A very specialized mode that will optimize for code size at any and all costs.
static const OptimizationLevel O0
Disable as many optimizations as possible.
static const OptimizationLevel Os
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
static const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
static const OptimizationLevel O1
Optimize quickly without destroying debuggability.
void printPassNames(raw_ostream &OS)
Print pass names.
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
Definition: PassBuilder.h:629
AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
ModulePassManager buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, ThinLTO-targeting default optimization pipeline to a pass manager.
PassBuilder(TargetMachine *TM=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions(), std::optional< PGOOptions > PGOOpt=std::nullopt, PassInstrumentationCallbacks *PIC=nullptr)
void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM, MachineFunctionAnalysisManager *MFAM=nullptr)
Cross register the analysis managers through their proxies.
ModulePassManager buildPerModuleDefaultPipeline(OptimizationLevel Level, bool LTOPreLink=false)
Build a per-module default optimization pipeline.
Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level, ModuleSummaryIndex *ExportSummary)
Build an LTO default optimization pipeline to a pass manager.
ModulePassManager buildThinLTODefaultPipeline(OptimizationLevel Level, const ModuleSummaryIndex *ImportSummary)
Build an ThinLTO default optimization pipeline to a pass manager.
void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
static Expected< bool > parseSinglePassOption(StringRef Params, StringRef OptionName, StringRef PassName)
Handle passes only accept one bool-valued parameter.
void registerMachineFunctionAnalyses(MachineFunctionAnalysisManager &MFAM)
Registers all available machine function analysis passes.
void registerParseTopLevelPipelineCallback(const std::function< bool(ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Register a callback for a top-level pipeline entry.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level)
Build a pre-link, LTO-targeting default optimization pipeline to a pass manager.
void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
LLVM_ATTRIBUTE_MINSIZE void addPass(PassT &&Pass)
Definition: PassManager.h:249
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:42
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:57
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:53
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:662
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:109
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:115
bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
Definition: Regex.cpp:83
size_t size() const
Definition: SmallVector.h:91
void push_back(const T &Elt)
Definition: SmallVector.h:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:696
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:466
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
char front() const
front - Get the first character in the string.
Definition: StringRef.h:140
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:631
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
static bool hasLimitedCodeGenPipeline()
Returns true if one of the -start-after, -start-before, -stop-after or -stop-before options is set.
This function has undefined behavior.
self_iterator getIterator()
Definition: ilist_node.h:109
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Interfaces for registering analysis passes, producing common pass manager configurations,...
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::vector< std::string > printAfterPasses()
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:916
RepeatedPass< PassT > createRepeatedPass(int Count, PassT &&P)
Definition: PassManager.h:1050
DevirtSCCRepeatedPass createDevirtSCCRepeatedPass(CGSCCPassT &&Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:90
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:866
InnerAnalysisManagerProxy< MachineFunctionAnalysisManager, Module > MachineFunctionAnalysisManagerModuleProxy
OuterAnalysisManagerProxy< ModuleAnalysisManager, LazyCallGraph::SCC, LazyCallGraph & > ModuleAnalysisManagerCGSCCProxy
A proxy from a ModuleAnalysisManager to an SCC.
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:1729
std::vector< std::string > printBeforePasses()
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
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.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
Definition: PassManager.h:712
ModuleToMachineFunctionPassAdaptor createModuleToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass)
cl::opt< bool > PrintPipelinePasses("print-pipeline-passes", cl::desc("Print a '-passes' compatible string describing the pipeline " "(best-effort only)."))
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
OuterAnalysisManagerProxy< CGSCCAnalysisManager, Function > CGSCCAnalysisManagerFunctionProxy
A proxy from a CGSCCAnalysisManager to a Function.
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.
bool isFilterPassesEmpty()
@ Enable
Enable colors.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:26
A set of parameters to control various transforms performed by GVN pass.
Definition: GVN.h:74
HardwareLoopOptions & setForceNested(bool Force)
Definition: HardwareLoops.h:45
HardwareLoopOptions & setDecrement(unsigned Count)
Definition: HardwareLoops.h:29
HardwareLoopOptions & setForceGuard(bool Force)
Definition: HardwareLoops.h:49
HardwareLoopOptions & setForce(bool Force)
Definition: HardwareLoops.h:37
HardwareLoopOptions & setCounterBitwidth(unsigned Width)
Definition: HardwareLoops.h:33
HardwareLoopOptions & setForcePhi(bool Force)
Definition: HardwareLoops.h:41
A set of parameters to control various transforms performed by IPSCCP pass.
Definition: SCCP.h:35
A set of parameters used to control various transforms performed by the LoopUnroll pass.
LoopUnrollOptions & setPeeling(bool Peeling)
Enables or disables loop peeling.
LoopUnrollOptions & setOptLevel(int O)
LoopUnrollOptions & setPartial(bool Partial)
Enables or disables partial unrolling.
LoopUnrollOptions & setFullUnrollMaxCount(unsigned O)
LoopUnrollOptions & setUpperBound(bool UpperBound)
Enables or disables the use of trip count upper bound in loop unrolling.
LoopUnrollOptions & setRuntime(bool Runtime)
Enables or disables unrolling of loops with runtime trip count.
LoopUnrollOptions & setProfileBasedPeeling(int O)
LoopVectorizeOptions & setVectorizeOnlyWhenForced(bool Value)
LoopVectorizeOptions & setInterleaveOnlyWhenForced(bool Value)
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:74
static StringRef name()
Gets the name of the pass we are mixed into.
Definition: PassManager.h:76