LLVM 20.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
33#include "llvm/Analysis/DDG.h"
51#include "llvm/Analysis/Lint.h"
125#include "llvm/IR/DebugInfo.h"
126#include "llvm/IR/Dominators.h"
127#include "llvm/IR/PassManager.h"
128#include "llvm/IR/PrintPasses.h"
130#include "llvm/IR/Verifier.h"
134#include "llvm/Support/Debug.h"
137#include "llvm/Support/Regex.h"
324#include <optional>
325
326using namespace llvm;
327
329 "^(default|thinlto-pre-link|thinlto|lto-pre-link|lto)<(O[0123sz])>$");
330
331namespace llvm {
333 "print-pipeline-passes",
334 cl::desc("Print a '-passes' compatible string describing the pipeline "
335 "(best-effort only)."));
336} // namespace llvm
337
338AnalysisKey NoOpModuleAnalysis::Key;
339AnalysisKey NoOpCGSCCAnalysis::Key;
340AnalysisKey NoOpFunctionAnalysis::Key;
341AnalysisKey NoOpLoopAnalysis::Key;
342
343namespace {
344
345// Passes for testing crashes.
346// DO NOT USE THIS EXCEPT FOR TESTING!
347class TriggerCrashModulePass : public PassInfoMixin<TriggerCrashModulePass> {
348public:
350 abort();
351 return PreservedAnalyses::all();
352 }
353 static StringRef name() { return "TriggerCrashModulePass"; }
354};
355
356class TriggerCrashFunctionPass
357 : public PassInfoMixin<TriggerCrashFunctionPass> {
358public:
360 abort();
361 return PreservedAnalyses::all();
362 }
363 static StringRef name() { return "TriggerCrashFunctionPass"; }
364};
365
366// A pass for testing message reporting of -verify-each failures.
367// DO NOT USE THIS EXCEPT FOR TESTING!
368class TriggerVerifierErrorPass
369 : public PassInfoMixin<TriggerVerifierErrorPass> {
370public:
372 // Intentionally break the Module by creating an alias without setting the
373 // aliasee.
374 auto *PtrTy = llvm::PointerType::getUnqual(M.getContext());
375 GlobalAlias::create(PtrTy, PtrTy->getAddressSpace(),
376 GlobalValue::LinkageTypes::InternalLinkage,
377 "__bad_alias", nullptr, &M);
379 }
380
382 // Intentionally break the Function by inserting a terminator
383 // instruction in the middle of a basic block.
384 BasicBlock &BB = F.getEntryBlock();
385 new UnreachableInst(F.getContext(), BB.getTerminator()->getIterator());
387 }
388
390 // Intentionally create a virtual register and set NoVRegs property.
391 auto &MRI = MF.getRegInfo();
392 MRI.createGenericVirtualRegister(LLT::scalar(8));
393 MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs);
394 return PreservedAnalyses::all();
395 }
396
397 static StringRef name() { return "TriggerVerifierErrorPass"; }
398};
399
400// A pass requires all MachineFunctionProperties.
401// DO NOT USE THIS EXCEPT FOR TESTING!
402class RequireAllMachineFunctionPropertiesPass
403 : public PassInfoMixin<RequireAllMachineFunctionPropertiesPass> {
404public:
406 MFPropsModifier _(*this, MF);
408 }
409
410 static MachineFunctionProperties getRequiredProperties() {
412 MFProps.set(MachineFunctionProperties::Property::FailedISel);
413 MFProps.set(MachineFunctionProperties::Property::FailsVerification);
414 MFProps.set(MachineFunctionProperties::Property::IsSSA);
415 MFProps.set(MachineFunctionProperties::Property::Legalized);
416 MFProps.set(MachineFunctionProperties::Property::NoPHIs);
417 MFProps.set(MachineFunctionProperties::Property::NoVRegs);
418 MFProps.set(MachineFunctionProperties::Property::RegBankSelected);
419 MFProps.set(MachineFunctionProperties::Property::Selected);
420 MFProps.set(MachineFunctionProperties::Property::TiedOpsRewritten);
421 MFProps.set(MachineFunctionProperties::Property::TracksDebugUserValues);
422 MFProps.set(MachineFunctionProperties::Property::TracksLiveness);
423 return MFProps;
424 }
425 static StringRef name() { return "RequireAllMachineFunctionPropertiesPass"; }
426};
427
428} // namespace
429
431 std::optional<PGOOptions> PGOOpt,
433 : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
434 if (TM)
435 TM->registerPassBuilderCallbacks(*this);
436 if (PIC) {
438 // MSVC requires this to be captured if it's used inside decltype.
439 // Other compilers consider it an unused lambda capture.
440 (void)this;
441#define MODULE_PASS(NAME, CREATE_PASS) \
442 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
443#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
444 PIC->addClassToPassName(CLASS, NAME);
445#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
446 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
447#define FUNCTION_PASS(NAME, CREATE_PASS) \
448 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
449#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
450 PIC->addClassToPassName(CLASS, NAME);
451#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
452 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
453#define LOOPNEST_PASS(NAME, CREATE_PASS) \
454 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
455#define LOOP_PASS(NAME, CREATE_PASS) \
456 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
457#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
458 PIC->addClassToPassName(CLASS, NAME);
459#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
460 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
461#define CGSCC_PASS(NAME, CREATE_PASS) \
462 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
463#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
464 PIC->addClassToPassName(CLASS, NAME);
465#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
466 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
467#include "PassRegistry.def"
468
469#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
470 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
471#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
472 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
473#include "llvm/Passes/MachinePassRegistry.def"
474 });
475 }
476}
477
479#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
480 MAM.registerPass([&] { return CREATE_PASS; });
481#include "PassRegistry.def"
482
483 for (auto &C : ModuleAnalysisRegistrationCallbacks)
484 C(MAM);
485}
486
488#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
489 CGAM.registerPass([&] { return CREATE_PASS; });
490#include "PassRegistry.def"
491
492 for (auto &C : CGSCCAnalysisRegistrationCallbacks)
493 C(CGAM);
494}
495
497 // We almost always want the default alias analysis pipeline.
498 // If a user wants a different one, they can register their own before calling
499 // registerFunctionAnalyses().
500 FAM.registerPass([&] { return buildDefaultAAPipeline(); });
501
502#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
503 FAM.registerPass([&] { return CREATE_PASS; });
504#include "PassRegistry.def"
505
506 for (auto &C : FunctionAnalysisRegistrationCallbacks)
507 C(FAM);
508}
509
512
513#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
514 MFAM.registerPass([&] { return CREATE_PASS; });
515#include "llvm/Passes/MachinePassRegistry.def"
516
517 for (auto &C : MachineFunctionAnalysisRegistrationCallbacks)
518 C(MFAM);
519}
520
522#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
523 LAM.registerPass([&] { return CREATE_PASS; });
524#include "PassRegistry.def"
525
526 for (auto &C : LoopAnalysisRegistrationCallbacks)
527 C(LAM);
528}
529
530static std::optional<std::pair<bool, bool>>
532 std::pair<bool, bool> Params;
533 if (!Name.consume_front("function"))
534 return std::nullopt;
535 if (Name.empty())
536 return Params;
537 if (!Name.consume_front("<") || !Name.consume_back(">"))
538 return std::nullopt;
539 while (!Name.empty()) {
540 auto [Front, Back] = Name.split(';');
541 Name = Back;
542 if (Front == "eager-inv")
543 Params.first = true;
544 else if (Front == "no-rerun")
545 Params.second = true;
546 else
547 return std::nullopt;
548 }
549 return Params;
550}
551
552static std::optional<int> parseDevirtPassName(StringRef Name) {
553 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
554 return std::nullopt;
555 int Count;
556 if (Name.getAsInteger(0, Count) || Count < 0)
557 return std::nullopt;
558 return Count;
559}
560
561static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
563 .Case("O0", OptimizationLevel::O0)
569 .Default(std::nullopt);
570}
571
573 StringRef OptionName,
575 bool Result = false;
576 while (!Params.empty()) {
577 StringRef ParamName;
578 std::tie(ParamName, Params) = Params.split(';');
579
580 if (ParamName == OptionName) {
581 Result = true;
582 } else {
583 return make_error<StringError>(
584 formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
585 .str(),
587 }
588 }
589 return Result;
590}
591
592namespace {
593
594/// Parser of parameters for HardwareLoops pass.
595Expected<HardwareLoopOptions> parseHardwareLoopOptions(StringRef Params) {
596 HardwareLoopOptions HardwareLoopOpts;
597
598 while (!Params.empty()) {
599 StringRef ParamName;
600 std::tie(ParamName, Params) = Params.split(';');
601 if (ParamName.consume_front("hardware-loop-decrement=")) {
602 int Count;
603 if (ParamName.getAsInteger(0, Count))
604 return make_error<StringError>(
605 formatv("invalid HardwareLoopPass parameter '{0}' ", ParamName).str(),
607 HardwareLoopOpts.setDecrement(Count);
608 continue;
609 }
610 if (ParamName.consume_front("hardware-loop-counter-bitwidth=")) {
611 int Count;
612 if (ParamName.getAsInteger(0, Count))
613 return make_error<StringError>(
614 formatv("invalid HardwareLoopPass parameter '{0}' ", ParamName).str(),
616 HardwareLoopOpts.setCounterBitwidth(Count);
617 continue;
618 }
619 if (ParamName == "force-hardware-loops") {
620 HardwareLoopOpts.setForce(true);
621 } else if (ParamName == "force-hardware-loop-phi") {
622 HardwareLoopOpts.setForcePhi(true);
623 } else if (ParamName == "force-nested-hardware-loop") {
624 HardwareLoopOpts.setForceNested(true);
625 } else if (ParamName == "force-hardware-loop-guard") {
626 HardwareLoopOpts.setForceGuard(true);
627 } else {
628 return make_error<StringError>(
629 formatv("invalid HardwarePass parameter '{0}' ", ParamName).str(),
631 }
632 }
633 return HardwareLoopOpts;
634}
635
636/// Parser of parameters for LoopUnroll pass.
637Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
638 LoopUnrollOptions UnrollOpts;
639 while (!Params.empty()) {
640 StringRef ParamName;
641 std::tie(ParamName, Params) = Params.split(';');
642 std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
643 // Don't accept -Os/-Oz.
644 if (OptLevel && !OptLevel->isOptimizingForSize()) {
645 UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
646 continue;
647 }
648 if (ParamName.consume_front("full-unroll-max=")) {
649 int Count;
650 if (ParamName.getAsInteger(0, Count))
651 return make_error<StringError>(
652 formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
654 UnrollOpts.setFullUnrollMaxCount(Count);
655 continue;
656 }
657
658 bool Enable = !ParamName.consume_front("no-");
659 if (ParamName == "partial") {
660 UnrollOpts.setPartial(Enable);
661 } else if (ParamName == "peeling") {
662 UnrollOpts.setPeeling(Enable);
663 } else if (ParamName == "profile-peeling") {
664 UnrollOpts.setProfileBasedPeeling(Enable);
665 } else if (ParamName == "runtime") {
666 UnrollOpts.setRuntime(Enable);
667 } else if (ParamName == "upperbound") {
668 UnrollOpts.setUpperBound(Enable);
669 } else {
670 return make_error<StringError>(
671 formatv("invalid LoopUnrollPass parameter '{0}' ", ParamName).str(),
673 }
674 }
675 return UnrollOpts;
676}
677
678Expected<bool> parseGlobalDCEPassOptions(StringRef Params) {
680 Params, "vfe-linkage-unit-visibility", "GlobalDCE");
681}
682
683Expected<bool> parseCGProfilePassOptions(StringRef Params) {
684 return PassBuilder::parseSinglePassOption(Params, "in-lto-post-link",
685 "CGProfile");
686}
687
688Expected<bool> parseInlinerPassOptions(StringRef Params) {
689 return PassBuilder::parseSinglePassOption(Params, "only-mandatory",
690 "InlinerPass");
691}
692
693Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
694 return PassBuilder::parseSinglePassOption(Params, "reuse-storage",
695 "CoroSplitPass");
696}
697
698Expected<bool> parsePostOrderFunctionAttrsPassOptions(StringRef Params) {
700 Params, "skip-non-recursive-function-attrs", "PostOrderFunctionAttrs");
701}
702
703Expected<CFGuardPass::Mechanism> parseCFGuardPassOptions(StringRef Params) {
704 if (Params.empty())
706
707 auto [Param, RHS] = Params.split(';');
708 if (!RHS.empty())
709 return make_error<StringError>(
710 formatv("too many CFGuardPass parameters '{0}' ", Params).str(),
712
713 if (Param == "check")
715 if (Param == "dispatch")
717
718 return make_error<StringError>(
719 formatv("invalid CFGuardPass mechanism: '{0}' ", Param).str(),
721}
722
723Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
724 return PassBuilder::parseSinglePassOption(Params, "memssa", "EarlyCSE");
725}
726
727Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
728 return PassBuilder::parseSinglePassOption(Params, "post-inline",
729 "EntryExitInstrumenter");
730}
731
732Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
733 return PassBuilder::parseSinglePassOption(Params, "single", "LoopExtractor");
734}
735
736Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
737 return PassBuilder::parseSinglePassOption(Params, "minimal",
738 "LowerMatrixIntrinsics");
739}
740
741Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
743 while (!Params.empty()) {
744 StringRef ParamName;
745 std::tie(ParamName, Params) = Params.split(';');
746
747 if (ParamName == "kernel") {
748 Result.CompileKernel = true;
749 } else {
750 return make_error<StringError>(
751 formatv("invalid AddressSanitizer pass parameter '{0}' ", ParamName)
752 .str(),
754 }
755 }
756 return Result;
757}
758
759Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
761 while (!Params.empty()) {
762 StringRef ParamName;
763 std::tie(ParamName, Params) = Params.split(';');
764
765 if (ParamName == "recover") {
766 Result.Recover = true;
767 } else if (ParamName == "kernel") {
768 Result.CompileKernel = true;
769 } else {
770 return make_error<StringError>(
771 formatv("invalid HWAddressSanitizer pass parameter '{0}' ", ParamName)
772 .str(),
774 }
775 }
776 return Result;
777}
778
779Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
781 while (!Params.empty()) {
782 StringRef ParamName;
783 std::tie(ParamName, Params) = Params.split(';');
784
785 if (ParamName == "thinlto") {
786 Result.IsThinLTO = true;
787 } else if (ParamName == "emit-summary") {
788 Result.EmitLTOSummary = true;
789 } else {
790 return make_error<StringError>(
791 formatv("invalid EmbedBitcode pass parameter '{0}' ", ParamName)
792 .str(),
794 }
795 }
796 return Result;
797}
798
799Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
801 while (!Params.empty()) {
802 StringRef ParamName;
803 std::tie(ParamName, Params) = Params.split(';');
804
805 if (ParamName == "recover") {
806 Result.Recover = true;
807 } else if (ParamName == "kernel") {
808 Result.Kernel = true;
809 } else if (ParamName.consume_front("track-origins=")) {
810 if (ParamName.getAsInteger(0, Result.TrackOrigins))
811 return make_error<StringError>(
812 formatv("invalid argument to MemorySanitizer pass track-origins "
813 "parameter: '{0}' ",
814 ParamName)
815 .str(),
817 } else if (ParamName == "eager-checks") {
818 Result.EagerChecks = true;
819 } else {
820 return make_error<StringError>(
821 formatv("invalid MemorySanitizer pass parameter '{0}' ", ParamName)
822 .str(),
824 }
825 }
826 return Result;
827}
828
829/// Parser of parameters for SimplifyCFG pass.
830Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
832 while (!Params.empty()) {
833 StringRef ParamName;
834 std::tie(ParamName, Params) = Params.split(';');
835
836 bool Enable = !ParamName.consume_front("no-");
837 if (ParamName == "speculate-blocks") {
838 Result.speculateBlocks(Enable);
839 } else if (ParamName == "simplify-cond-branch") {
840 Result.setSimplifyCondBranch(Enable);
841 } else if (ParamName == "forward-switch-cond") {
842 Result.forwardSwitchCondToPhi(Enable);
843 } else if (ParamName == "switch-range-to-icmp") {
844 Result.convertSwitchRangeToICmp(Enable);
845 } else if (ParamName == "switch-to-lookup") {
846 Result.convertSwitchToLookupTable(Enable);
847 } else if (ParamName == "keep-loops") {
848 Result.needCanonicalLoops(Enable);
849 } else if (ParamName == "hoist-common-insts") {
850 Result.hoistCommonInsts(Enable);
851 } else if (ParamName == "sink-common-insts") {
852 Result.sinkCommonInsts(Enable);
853 } else if (ParamName == "speculate-unpredictables") {
854 Result.speculateUnpredictables(Enable);
855 } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
856 APInt BonusInstThreshold;
857 if (ParamName.getAsInteger(0, BonusInstThreshold))
858 return make_error<StringError>(
859 formatv("invalid argument to SimplifyCFG pass bonus-threshold "
860 "parameter: '{0}' ",
861 ParamName).str(),
863 Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
864 } else {
865 return make_error<StringError>(
866 formatv("invalid SimplifyCFG pass parameter '{0}' ", ParamName).str(),
868 }
869 }
870 return Result;
871}
872
873Expected<InstCombineOptions> parseInstCombineOptions(StringRef Params) {
875 // When specifying "instcombine" in -passes enable fix-point verification by
876 // default, as this is what most tests should use.
877 Result.setVerifyFixpoint(true);
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 == "use-loop-info") {
884 Result.setUseLoopInfo(Enable);
885 } else if (ParamName == "verify-fixpoint") {
886 Result.setVerifyFixpoint(Enable);
887 } else if (Enable && ParamName.consume_front("max-iterations=")) {
888 APInt MaxIterations;
889 if (ParamName.getAsInteger(0, MaxIterations))
890 return make_error<StringError>(
891 formatv("invalid argument to InstCombine pass max-iterations "
892 "parameter: '{0}' ",
893 ParamName).str(),
895 Result.setMaxIterations((unsigned)MaxIterations.getZExtValue());
896 } else {
897 return make_error<StringError>(
898 formatv("invalid InstCombine pass parameter '{0}' ", ParamName).str(),
900 }
901 }
902 return Result;
903}
904
905/// Parser of parameters for LoopVectorize pass.
906Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
908 while (!Params.empty()) {
909 StringRef ParamName;
910 std::tie(ParamName, Params) = Params.split(';');
911
912 bool Enable = !ParamName.consume_front("no-");
913 if (ParamName == "interleave-forced-only") {
915 } else if (ParamName == "vectorize-forced-only") {
917 } else {
918 return make_error<StringError>(
919 formatv("invalid LoopVectorize parameter '{0}' ", ParamName).str(),
921 }
922 }
923 return Opts;
924}
925
926Expected<std::pair<bool, bool>> parseLoopUnswitchOptions(StringRef Params) {
927 std::pair<bool, bool> Result = {false, true};
928 while (!Params.empty()) {
929 StringRef ParamName;
930 std::tie(ParamName, Params) = Params.split(';');
931
932 bool Enable = !ParamName.consume_front("no-");
933 if (ParamName == "nontrivial") {
934 Result.first = Enable;
935 } else if (ParamName == "trivial") {
936 Result.second = Enable;
937 } else {
938 return make_error<StringError>(
939 formatv("invalid LoopUnswitch pass parameter '{0}' ", ParamName)
940 .str(),
942 }
943 }
944 return Result;
945}
946
947Expected<LICMOptions> parseLICMOptions(StringRef Params) {
949 while (!Params.empty()) {
950 StringRef ParamName;
951 std::tie(ParamName, Params) = Params.split(';');
952
953 bool Enable = !ParamName.consume_front("no-");
954 if (ParamName == "allowspeculation") {
955 Result.AllowSpeculation = Enable;
956 } else {
957 return make_error<StringError>(
958 formatv("invalid LICM pass parameter '{0}' ", ParamName).str(),
960 }
961 }
962 return Result;
963}
964
965Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
966 std::pair<bool, bool> Result = {true, false};
967 while (!Params.empty()) {
968 StringRef ParamName;
969 std::tie(ParamName, Params) = Params.split(';');
970
971 bool Enable = !ParamName.consume_front("no-");
972 if (ParamName == "header-duplication") {
973 Result.first = Enable;
974 } else if (ParamName == "prepare-for-lto") {
975 Result.second = Enable;
976 } else {
977 return make_error<StringError>(
978 formatv("invalid LoopRotate pass parameter '{0}' ", ParamName).str(),
980 }
981 }
982 return Result;
983}
984
985Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
986 bool Result = false;
987 while (!Params.empty()) {
988 StringRef ParamName;
989 std::tie(ParamName, Params) = Params.split(';');
990
991 bool Enable = !ParamName.consume_front("no-");
992 if (ParamName == "split-footer-bb") {
993 Result = Enable;
994 } else {
995 return make_error<StringError>(
996 formatv("invalid MergedLoadStoreMotion pass parameter '{0}' ",
997 ParamName)
998 .str(),
1000 }
1001 }
1002 return Result;
1003}
1004
1005Expected<GVNOptions> parseGVNOptions(StringRef Params) {
1007 while (!Params.empty()) {
1008 StringRef ParamName;
1009 std::tie(ParamName, Params) = Params.split(';');
1010
1011 bool Enable = !ParamName.consume_front("no-");
1012 if (ParamName == "pre") {
1013 Result.setPRE(Enable);
1014 } else if (ParamName == "load-pre") {
1015 Result.setLoadPRE(Enable);
1016 } else if (ParamName == "split-backedge-load-pre") {
1017 Result.setLoadPRESplitBackedge(Enable);
1018 } else if (ParamName == "memdep") {
1019 Result.setMemDep(Enable);
1020 } else {
1021 return make_error<StringError>(
1022 formatv("invalid GVN pass parameter '{0}' ", ParamName).str(),
1024 }
1025 }
1026 return Result;
1027}
1028
1029Expected<IPSCCPOptions> parseIPSCCPOptions(StringRef Params) {
1031 while (!Params.empty()) {
1032 StringRef ParamName;
1033 std::tie(ParamName, Params) = Params.split(';');
1034
1035 bool Enable = !ParamName.consume_front("no-");
1036 if (ParamName == "func-spec")
1037 Result.setFuncSpec(Enable);
1038 else
1039 return make_error<StringError>(
1040 formatv("invalid IPSCCP pass parameter '{0}' ", ParamName).str(),
1042 }
1043 return Result;
1044}
1045
1046Expected<SROAOptions> parseSROAOptions(StringRef Params) {
1047 if (Params.empty() || Params == "modify-cfg")
1049 if (Params == "preserve-cfg")
1051 return make_error<StringError>(
1052 formatv("invalid SROA pass parameter '{0}' (either preserve-cfg or "
1053 "modify-cfg can be specified)",
1054 Params)
1055 .str(),
1057}
1058
1060parseStackLifetimeOptions(StringRef Params) {
1062 while (!Params.empty()) {
1063 StringRef ParamName;
1064 std::tie(ParamName, Params) = Params.split(';');
1065
1066 if (ParamName == "may") {
1068 } else if (ParamName == "must") {
1070 } else {
1071 return make_error<StringError>(
1072 formatv("invalid StackLifetime parameter '{0}' ", ParamName).str(),
1074 }
1075 }
1076 return Result;
1077}
1078
1079Expected<bool> parseDependenceAnalysisPrinterOptions(StringRef Params) {
1080 return PassBuilder::parseSinglePassOption(Params, "normalized-results",
1081 "DependenceAnalysisPrinter");
1082}
1083
1084Expected<bool> parseSeparateConstOffsetFromGEPPassOptions(StringRef Params) {
1085 return PassBuilder::parseSinglePassOption(Params, "lower-gep",
1086 "SeparateConstOffsetFromGEP");
1087}
1088
1089Expected<bool> parseStructurizeCFGPassOptions(StringRef Params) {
1090 return PassBuilder::parseSinglePassOption(Params, "skip-uniform-regions",
1091 "StructurizeCFG");
1092}
1093
1095parseFunctionSimplificationPipelineOptions(StringRef Params) {
1096 std::optional<OptimizationLevel> L = parseOptLevel(Params);
1097 if (!L || *L == OptimizationLevel::O0) {
1098 return make_error<StringError>(
1099 formatv("invalid function-simplification parameter '{0}' ", Params)
1100 .str(),
1102 };
1103 return *L;
1104}
1105
1106Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
1107 return PassBuilder::parseSinglePassOption(Params, "no-ensure-optimized-uses",
1108 "MemorySSAPrinterPass");
1109}
1110
1111Expected<bool> parseSpeculativeExecutionPassOptions(StringRef Params) {
1112 return PassBuilder::parseSinglePassOption(Params, "only-if-divergent-target",
1113 "SpeculativeExecutionPass");
1114}
1115
1116Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
1117 std::string Result;
1118 while (!Params.empty()) {
1119 StringRef ParamName;
1120 std::tie(ParamName, Params) = Params.split(';');
1121
1122 if (ParamName.consume_front("profile-filename=")) {
1123 Result = ParamName.str();
1124 } else {
1125 return make_error<StringError>(
1126 formatv("invalid MemProfUse pass parameter '{0}' ", ParamName).str(),
1128 }
1129 }
1130 return Result;
1131}
1132
1133Expected<bool> parseStructuralHashPrinterPassOptions(StringRef Params) {
1134 return PassBuilder::parseSinglePassOption(Params, "detailed",
1135 "StructuralHashPrinterPass");
1136}
1137
1138Expected<bool> parseWinEHPrepareOptions(StringRef Params) {
1139 return PassBuilder::parseSinglePassOption(Params, "demote-catchswitch-only",
1140 "WinEHPreparePass");
1141}
1142
1143Expected<GlobalMergeOptions> parseGlobalMergeOptions(StringRef Params) {
1145 while (!Params.empty()) {
1146 StringRef ParamName;
1147 std::tie(ParamName, Params) = Params.split(';');
1148
1149 bool Enable = !ParamName.consume_front("no-");
1150 if (ParamName == "group-by-use")
1151 Result.GroupByUse = Enable;
1152 else if (ParamName == "ignore-single-use")
1153 Result.IgnoreSingleUse = Enable;
1154 else if (ParamName == "merge-const")
1155 Result.MergeConst = Enable;
1156 else if (ParamName == "merge-external")
1157 Result.MergeExternal = Enable;
1158 else if (ParamName.consume_front("max-offset=")) {
1159 if (ParamName.getAsInteger(0, Result.MaxOffset))
1160 return make_error<StringError>(
1161 formatv("invalid GlobalMergePass parameter '{0}' ", ParamName)
1162 .str(),
1164 }
1165 }
1166 return Result;
1167}
1168
1169Expected<SmallVector<std::string, 0>> parseInternalizeGVs(StringRef Params) {
1170 SmallVector<std::string, 1> PreservedGVs;
1171 while (!Params.empty()) {
1172 StringRef ParamName;
1173 std::tie(ParamName, Params) = Params.split(';');
1174
1175 if (ParamName.consume_front("preserve-gv=")) {
1176 PreservedGVs.push_back(ParamName.str());
1177 } else {
1178 return make_error<StringError>(
1179 formatv("invalid Internalize pass parameter '{0}' ", ParamName).str(),
1181 }
1182 }
1183
1184 return Expected<SmallVector<std::string, 0>>(std::move(PreservedGVs));
1185}
1186
1188parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) {
1190 while (!Params.empty()) {
1191 StringRef ParamName;
1192 std::tie(ParamName, Params) = Params.split(';');
1193
1194 if (ParamName.consume_front("filter=")) {
1195 std::optional<RegAllocFilterFunc> Filter =
1196 PB.parseRegAllocFilter(ParamName);
1197 if (!Filter) {
1198 return make_error<StringError>(
1199 formatv("invalid regallocfast register filter '{0}' ", ParamName)
1200 .str(),
1202 }
1203 Opts.Filter = *Filter;
1204 Opts.FilterName = ParamName;
1205 continue;
1206 }
1207
1208 if (ParamName == "no-clear-vregs") {
1209 Opts.ClearVRegs = false;
1210 continue;
1211 }
1212
1213 return make_error<StringError>(
1214 formatv("invalid regallocfast pass parameter '{0}' ", ParamName).str(),
1216 }
1217 return Opts;
1218}
1219
1220Expected<RealtimeSanitizerOptions> parseRtSanPassOptions(StringRef Params) {
1222 return Result;
1223}
1224
1225} // namespace
1226
1227/// Tests whether a pass name starts with a valid prefix for a default pipeline
1228/// alias.
1230 return Name.starts_with("default") || Name.starts_with("thinlto") ||
1231 Name.starts_with("lto");
1232}
1233
1234/// Tests whether registered callbacks will accept a given pass name.
1235///
1236/// When parsing a pipeline text, the type of the outermost pipeline may be
1237/// omitted, in which case the type is automatically determined from the first
1238/// pass name in the text. This may be a name that is handled through one of the
1239/// callbacks. We check this through the oridinary parsing callbacks by setting
1240/// up a dummy PassManager in order to not force the client to also handle this
1241/// type of query.
1242template <typename PassManagerT, typename CallbacksT>
1243static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1244 if (!Callbacks.empty()) {
1245 PassManagerT DummyPM;
1246 for (auto &CB : Callbacks)
1247 if (CB(Name, DummyPM, {}))
1248 return true;
1249 }
1250 return false;
1251}
1252
1253template <typename CallbacksT>
1254static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1255 // Manually handle aliases for pre-configured pipeline fragments.
1258
1259 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1260
1261 // Explicitly handle pass manager names.
1262 if (Name == "module")
1263 return true;
1264 if (Name == "cgscc")
1265 return true;
1266 if (NameNoBracket == "function")
1267 return true;
1268 if (Name == "coro-cond")
1269 return true;
1270
1271#define MODULE_PASS(NAME, CREATE_PASS) \
1272 if (Name == NAME) \
1273 return true;
1274#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1275 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1276 return true;
1277#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1278 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1279 return true;
1280#include "PassRegistry.def"
1281
1282 return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1283}
1284
1285template <typename CallbacksT>
1286static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1287 // Explicitly handle pass manager names.
1288 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1289 if (Name == "cgscc")
1290 return true;
1291 if (NameNoBracket == "function")
1292 return true;
1293
1294 // Explicitly handle custom-parsed pass names.
1296 return true;
1297
1298#define CGSCC_PASS(NAME, CREATE_PASS) \
1299 if (Name == NAME) \
1300 return true;
1301#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1302 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1303 return true;
1304#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1305 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1306 return true;
1307#include "PassRegistry.def"
1308
1309 return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1310}
1311
1312template <typename CallbacksT>
1313static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1314 // Explicitly handle pass manager names.
1315 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1316 if (NameNoBracket == "function")
1317 return true;
1318 if (Name == "loop" || Name == "loop-mssa" || Name == "machine-function")
1319 return true;
1320
1321#define FUNCTION_PASS(NAME, CREATE_PASS) \
1322 if (Name == NAME) \
1323 return true;
1324#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1325 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1326 return true;
1327#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1328 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1329 return true;
1330#include "PassRegistry.def"
1331
1332 return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1333}
1334
1335template <typename CallbacksT>
1336static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1337 // Explicitly handle pass manager names.
1338 if (Name == "machine-function")
1339 return true;
1340
1341#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1342 if (Name == NAME) \
1343 return true;
1344#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1345 PARAMS) \
1346 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1347 return true;
1348
1349#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1350 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1351 return true;
1352
1353#include "llvm/Passes/MachinePassRegistry.def"
1354
1355 return callbacksAcceptPassName<MachineFunctionPassManager>(Name, Callbacks);
1356}
1357
1358template <typename CallbacksT>
1359static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
1360 bool &UseMemorySSA) {
1361 UseMemorySSA = false;
1362
1364 UseMemorySSA = true;
1365 return true;
1366 }
1367
1368#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1369 if (Name == NAME) \
1370 return true;
1371#include "PassRegistry.def"
1372
1373 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1374}
1375
1376template <typename CallbacksT>
1377static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
1378 bool &UseMemorySSA) {
1379 UseMemorySSA = false;
1380
1382 UseMemorySSA = true;
1383 return true;
1384 }
1385
1386#define LOOP_PASS(NAME, CREATE_PASS) \
1387 if (Name == NAME) \
1388 return true;
1389#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1390 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1391 return true;
1392#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1393 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1394 return true;
1395#include "PassRegistry.def"
1396
1397 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1398}
1399
1400std::optional<std::vector<PassBuilder::PipelineElement>>
1401PassBuilder::parsePipelineText(StringRef Text) {
1402 std::vector<PipelineElement> ResultPipeline;
1403
1404 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1405 &ResultPipeline};
1406 for (;;) {
1407 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1408 size_t Pos = Text.find_first_of(",()");
1409 Pipeline.push_back({Text.substr(0, Pos), {}});
1410
1411 // If we have a single terminating name, we're done.
1412 if (Pos == Text.npos)
1413 break;
1414
1415 char Sep = Text[Pos];
1416 Text = Text.substr(Pos + 1);
1417 if (Sep == ',')
1418 // Just a name ending in a comma, continue.
1419 continue;
1420
1421 if (Sep == '(') {
1422 // Push the inner pipeline onto the stack to continue processing.
1423 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1424 continue;
1425 }
1426
1427 assert(Sep == ')' && "Bogus separator!");
1428 // When handling the close parenthesis, we greedily consume them to avoid
1429 // empty strings in the pipeline.
1430 do {
1431 // If we try to pop the outer pipeline we have unbalanced parentheses.
1432 if (PipelineStack.size() == 1)
1433 return std::nullopt;
1434
1435 PipelineStack.pop_back();
1436 } while (Text.consume_front(")"));
1437
1438 // Check if we've finished parsing.
1439 if (Text.empty())
1440 break;
1441
1442 // Otherwise, the end of an inner pipeline always has to be followed by
1443 // a comma, and then we can continue.
1444 if (!Text.consume_front(","))
1445 return std::nullopt;
1446 }
1447
1448 if (PipelineStack.size() > 1)
1449 // Unbalanced paretheses.
1450 return std::nullopt;
1451
1452 assert(PipelineStack.back() == &ResultPipeline &&
1453 "Wrong pipeline at the bottom of the stack!");
1454 return {std::move(ResultPipeline)};
1455}
1456
1457Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1458 const PipelineElement &E) {
1459 auto &Name = E.Name;
1460 auto &InnerPipeline = E.InnerPipeline;
1461
1462 // First handle complex passes like the pass managers which carry pipelines.
1463 if (!InnerPipeline.empty()) {
1464 if (Name == "module") {
1465 ModulePassManager NestedMPM;
1466 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1467 return Err;
1468 MPM.addPass(std::move(NestedMPM));
1469 return Error::success();
1470 }
1471 if (Name == "coro-cond") {
1472 ModulePassManager NestedMPM;
1473 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1474 return Err;
1475 MPM.addPass(CoroConditionalWrapper(std::move(NestedMPM)));
1476 return Error::success();
1477 }
1478 if (Name == "cgscc") {
1479 CGSCCPassManager CGPM;
1480 if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1481 return Err;
1483 return Error::success();
1484 }
1485 if (auto Params = parseFunctionPipelineName(Name)) {
1486 if (Params->second)
1487 return make_error<StringError>(
1488 "cannot have a no-rerun module to function adaptor",
1491 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1492 return Err;
1493 MPM.addPass(
1494 createModuleToFunctionPassAdaptor(std::move(FPM), Params->first));
1495 return Error::success();
1496 }
1497
1498 for (auto &C : ModulePipelineParsingCallbacks)
1499 if (C(Name, MPM, InnerPipeline))
1500 return Error::success();
1501
1502 // Normal passes can't have pipelines.
1503 return make_error<StringError>(
1504 formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1506 ;
1507 }
1508
1509 // Manually handle aliases for pre-configured pipeline fragments.
1512 if (!DefaultAliasRegex.match(Name, &Matches))
1513 return make_error<StringError>(
1514 formatv("unknown default pipeline alias '{0}'", Name).str(),
1516
1517 assert(Matches.size() == 3 && "Must capture two matched strings!");
1518
1519 OptimizationLevel L = *parseOptLevel(Matches[2]);
1520
1521 // This is consistent with old pass manager invoked via opt, but
1522 // inconsistent with clang. Clang doesn't enable loop vectorization
1523 // but does enable slp vectorization at Oz.
1524 PTO.LoopVectorization =
1525 L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1526 PTO.SLPVectorization =
1527 L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1528
1529 if (Matches[1] == "default") {
1531 } else if (Matches[1] == "thinlto-pre-link") {
1533 } else if (Matches[1] == "thinlto") {
1534 MPM.addPass(buildThinLTODefaultPipeline(L, nullptr));
1535 } else if (Matches[1] == "lto-pre-link") {
1536 if (PTO.UnifiedLTO)
1537 // When UnifiedLTO is enabled, use the ThinLTO pre-link pipeline. This
1538 // avoids compile-time performance regressions and keeps the pre-link
1539 // LTO pipeline "unified" for both LTO modes.
1541 else
1543 } else {
1544 assert(Matches[1] == "lto" && "Not one of the matched options!");
1545 MPM.addPass(buildLTODefaultPipeline(L, nullptr));
1546 }
1547 return Error::success();
1548 }
1549
1550 // Finally expand the basic registered passes from the .inc file.
1551#define MODULE_PASS(NAME, CREATE_PASS) \
1552 if (Name == NAME) { \
1553 MPM.addPass(CREATE_PASS); \
1554 return Error::success(); \
1555 }
1556#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1557 if (checkParametrizedPassName(Name, NAME)) { \
1558 auto Params = parsePassParameters(PARSER, Name, NAME); \
1559 if (!Params) \
1560 return Params.takeError(); \
1561 MPM.addPass(CREATE_PASS(Params.get())); \
1562 return Error::success(); \
1563 }
1564#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1565 if (Name == "require<" NAME ">") { \
1566 MPM.addPass( \
1567 RequireAnalysisPass< \
1568 std::remove_reference_t<decltype(CREATE_PASS)>, Module>()); \
1569 return Error::success(); \
1570 } \
1571 if (Name == "invalidate<" NAME ">") { \
1572 MPM.addPass(InvalidateAnalysisPass< \
1573 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1574 return Error::success(); \
1575 }
1576#define CGSCC_PASS(NAME, CREATE_PASS) \
1577 if (Name == NAME) { \
1578 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1579 return Error::success(); \
1580 }
1581#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1582 if (checkParametrizedPassName(Name, NAME)) { \
1583 auto Params = parsePassParameters(PARSER, Name, NAME); \
1584 if (!Params) \
1585 return Params.takeError(); \
1586 MPM.addPass( \
1587 createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1588 return Error::success(); \
1589 }
1590#define FUNCTION_PASS(NAME, CREATE_PASS) \
1591 if (Name == NAME) { \
1592 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1593 return Error::success(); \
1594 }
1595#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1596 if (checkParametrizedPassName(Name, NAME)) { \
1597 auto Params = parsePassParameters(PARSER, Name, NAME); \
1598 if (!Params) \
1599 return Params.takeError(); \
1600 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1601 return Error::success(); \
1602 }
1603#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1604 if (Name == NAME) { \
1605 MPM.addPass(createModuleToFunctionPassAdaptor( \
1606 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1607 return Error::success(); \
1608 }
1609#define LOOP_PASS(NAME, CREATE_PASS) \
1610 if (Name == NAME) { \
1611 MPM.addPass(createModuleToFunctionPassAdaptor( \
1612 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1613 return Error::success(); \
1614 }
1615#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1616 if (checkParametrizedPassName(Name, NAME)) { \
1617 auto Params = parsePassParameters(PARSER, Name, NAME); \
1618 if (!Params) \
1619 return Params.takeError(); \
1620 MPM.addPass( \
1621 createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1622 CREATE_PASS(Params.get()), false, false))); \
1623 return Error::success(); \
1624 }
1625#include "PassRegistry.def"
1626
1627 for (auto &C : ModulePipelineParsingCallbacks)
1628 if (C(Name, MPM, InnerPipeline))
1629 return Error::success();
1630 return make_error<StringError>(
1631 formatv("unknown module pass '{0}'", Name).str(),
1633}
1634
1635Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1636 const PipelineElement &E) {
1637 auto &Name = E.Name;
1638 auto &InnerPipeline = E.InnerPipeline;
1639
1640 // First handle complex passes like the pass managers which carry pipelines.
1641 if (!InnerPipeline.empty()) {
1642 if (Name == "cgscc") {
1643 CGSCCPassManager NestedCGPM;
1644 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1645 return Err;
1646 // Add the nested pass manager with the appropriate adaptor.
1647 CGPM.addPass(std::move(NestedCGPM));
1648 return Error::success();
1649 }
1650 if (auto Params = parseFunctionPipelineName(Name)) {
1652 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1653 return Err;
1654 // Add the nested pass manager with the appropriate adaptor.
1656 std::move(FPM), Params->first, Params->second));
1657 return Error::success();
1658 }
1659 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1660 CGSCCPassManager NestedCGPM;
1661 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1662 return Err;
1663 CGPM.addPass(
1664 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1665 return Error::success();
1666 }
1667
1668 for (auto &C : CGSCCPipelineParsingCallbacks)
1669 if (C(Name, CGPM, InnerPipeline))
1670 return Error::success();
1671
1672 // Normal passes can't have pipelines.
1673 return make_error<StringError>(
1674 formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1676 }
1677
1678// Now expand the basic registered passes from the .inc file.
1679#define CGSCC_PASS(NAME, CREATE_PASS) \
1680 if (Name == NAME) { \
1681 CGPM.addPass(CREATE_PASS); \
1682 return Error::success(); \
1683 }
1684#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1685 if (checkParametrizedPassName(Name, NAME)) { \
1686 auto Params = parsePassParameters(PARSER, Name, NAME); \
1687 if (!Params) \
1688 return Params.takeError(); \
1689 CGPM.addPass(CREATE_PASS(Params.get())); \
1690 return Error::success(); \
1691 }
1692#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1693 if (Name == "require<" NAME ">") { \
1694 CGPM.addPass(RequireAnalysisPass< \
1695 std::remove_reference_t<decltype(CREATE_PASS)>, \
1696 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
1697 CGSCCUpdateResult &>()); \
1698 return Error::success(); \
1699 } \
1700 if (Name == "invalidate<" NAME ">") { \
1701 CGPM.addPass(InvalidateAnalysisPass< \
1702 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1703 return Error::success(); \
1704 }
1705#define FUNCTION_PASS(NAME, CREATE_PASS) \
1706 if (Name == NAME) { \
1707 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
1708 return Error::success(); \
1709 }
1710#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1711 if (checkParametrizedPassName(Name, NAME)) { \
1712 auto Params = parsePassParameters(PARSER, Name, NAME); \
1713 if (!Params) \
1714 return Params.takeError(); \
1715 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1716 return Error::success(); \
1717 }
1718#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1719 if (Name == NAME) { \
1720 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1721 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1722 return Error::success(); \
1723 }
1724#define LOOP_PASS(NAME, CREATE_PASS) \
1725 if (Name == NAME) { \
1726 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
1727 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1728 return Error::success(); \
1729 }
1730#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1731 if (checkParametrizedPassName(Name, NAME)) { \
1732 auto Params = parsePassParameters(PARSER, Name, NAME); \
1733 if (!Params) \
1734 return Params.takeError(); \
1735 CGPM.addPass( \
1736 createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1737 CREATE_PASS(Params.get()), false, false))); \
1738 return Error::success(); \
1739 }
1740#include "PassRegistry.def"
1741
1742 for (auto &C : CGSCCPipelineParsingCallbacks)
1743 if (C(Name, CGPM, InnerPipeline))
1744 return Error::success();
1745 return make_error<StringError>(
1746 formatv("unknown cgscc pass '{0}'", Name).str(),
1748}
1749
1750Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1751 const PipelineElement &E) {
1752 auto &Name = E.Name;
1753 auto &InnerPipeline = E.InnerPipeline;
1754
1755 // First handle complex passes like the pass managers which carry pipelines.
1756 if (!InnerPipeline.empty()) {
1757 if (Name == "function") {
1758 FunctionPassManager NestedFPM;
1759 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
1760 return Err;
1761 // Add the nested pass manager with the appropriate adaptor.
1762 FPM.addPass(std::move(NestedFPM));
1763 return Error::success();
1764 }
1765 if (Name == "loop" || Name == "loop-mssa") {
1766 LoopPassManager LPM;
1767 if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
1768 return Err;
1769 // Add the nested pass manager with the appropriate adaptor.
1770 bool UseMemorySSA = (Name == "loop-mssa");
1771 bool UseBFI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1772 return Pipeline.Name.contains("simple-loop-unswitch");
1773 });
1774 bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
1775 return Pipeline.Name == "loop-predication";
1776 });
1777 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
1778 UseBFI, UseBPI));
1779 return Error::success();
1780 }
1781 if (Name == "machine-function") {
1783 if (auto Err = parseMachinePassPipeline(MFPM, InnerPipeline))
1784 return Err;
1786 return Error::success();
1787 }
1788
1789 for (auto &C : FunctionPipelineParsingCallbacks)
1790 if (C(Name, FPM, InnerPipeline))
1791 return Error::success();
1792
1793 // Normal passes can't have pipelines.
1794 return make_error<StringError>(
1795 formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1797 }
1798
1799// Now expand the basic registered passes from the .inc file.
1800#define FUNCTION_PASS(NAME, CREATE_PASS) \
1801 if (Name == NAME) { \
1802 FPM.addPass(CREATE_PASS); \
1803 return Error::success(); \
1804 }
1805#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1806 if (checkParametrizedPassName(Name, NAME)) { \
1807 auto Params = parsePassParameters(PARSER, Name, NAME); \
1808 if (!Params) \
1809 return Params.takeError(); \
1810 FPM.addPass(CREATE_PASS(Params.get())); \
1811 return Error::success(); \
1812 }
1813#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1814 if (Name == "require<" NAME ">") { \
1815 FPM.addPass( \
1816 RequireAnalysisPass< \
1817 std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
1818 return Error::success(); \
1819 } \
1820 if (Name == "invalidate<" NAME ">") { \
1821 FPM.addPass(InvalidateAnalysisPass< \
1822 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1823 return Error::success(); \
1824 }
1825// FIXME: UseMemorySSA is set to false. Maybe we could do things like:
1826// bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
1827// "guard-widening");
1828// The risk is that it may become obsolete if we're not careful.
1829#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1830 if (Name == NAME) { \
1831 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1832 return Error::success(); \
1833 }
1834#define LOOP_PASS(NAME, CREATE_PASS) \
1835 if (Name == NAME) { \
1836 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
1837 return Error::success(); \
1838 }
1839#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1840 if (checkParametrizedPassName(Name, NAME)) { \
1841 auto Params = parsePassParameters(PARSER, Name, NAME); \
1842 if (!Params) \
1843 return Params.takeError(); \
1844 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
1845 false, false)); \
1846 return Error::success(); \
1847 }
1848#include "PassRegistry.def"
1849
1850 for (auto &C : FunctionPipelineParsingCallbacks)
1851 if (C(Name, FPM, InnerPipeline))
1852 return Error::success();
1853 return make_error<StringError>(
1854 formatv("unknown function pass '{0}'", Name).str(),
1856}
1857
1858Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
1859 const PipelineElement &E) {
1860 StringRef Name = E.Name;
1861 auto &InnerPipeline = E.InnerPipeline;
1862
1863 // First handle complex passes like the pass managers which carry pipelines.
1864 if (!InnerPipeline.empty()) {
1865 if (Name == "loop") {
1866 LoopPassManager NestedLPM;
1867 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
1868 return Err;
1869 // Add the nested pass manager with the appropriate adaptor.
1870 LPM.addPass(std::move(NestedLPM));
1871 return Error::success();
1872 }
1873
1874 for (auto &C : LoopPipelineParsingCallbacks)
1875 if (C(Name, LPM, InnerPipeline))
1876 return Error::success();
1877
1878 // Normal passes can't have pipelines.
1879 return make_error<StringError>(
1880 formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
1882 }
1883
1884// Now expand the basic registered passes from the .inc file.
1885#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1886 if (Name == NAME) { \
1887 LPM.addPass(CREATE_PASS); \
1888 return Error::success(); \
1889 }
1890#define LOOP_PASS(NAME, CREATE_PASS) \
1891 if (Name == NAME) { \
1892 LPM.addPass(CREATE_PASS); \
1893 return Error::success(); \
1894 }
1895#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1896 if (checkParametrizedPassName(Name, NAME)) { \
1897 auto Params = parsePassParameters(PARSER, Name, NAME); \
1898 if (!Params) \
1899 return Params.takeError(); \
1900 LPM.addPass(CREATE_PASS(Params.get())); \
1901 return Error::success(); \
1902 }
1903#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1904 if (Name == "require<" NAME ">") { \
1905 LPM.addPass(RequireAnalysisPass< \
1906 std::remove_reference_t<decltype(CREATE_PASS)>, Loop, \
1907 LoopAnalysisManager, LoopStandardAnalysisResults &, \
1908 LPMUpdater &>()); \
1909 return Error::success(); \
1910 } \
1911 if (Name == "invalidate<" NAME ">") { \
1912 LPM.addPass(InvalidateAnalysisPass< \
1913 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1914 return Error::success(); \
1915 }
1916#include "PassRegistry.def"
1917
1918 for (auto &C : LoopPipelineParsingCallbacks)
1919 if (C(Name, LPM, InnerPipeline))
1920 return Error::success();
1921 return make_error<StringError>(formatv("unknown loop pass '{0}'", Name).str(),
1923}
1924
1925Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
1926 const PipelineElement &E) {
1927 StringRef Name = E.Name;
1928 if (!E.InnerPipeline.empty())
1929 return make_error<StringError>("invalid pipeline",
1931
1932#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) \
1933 if (Name == NAME) { \
1934 MFPM.addPass(CREATE_PASS); \
1935 return Error::success(); \
1936 }
1937#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1938 if (Name == NAME) { \
1939 MFPM.addPass(CREATE_PASS); \
1940 return Error::success(); \
1941 }
1942#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1943 PARAMS) \
1944 if (checkParametrizedPassName(Name, NAME)) { \
1945 auto Params = parsePassParameters(PARSER, Name, NAME); \
1946 if (!Params) \
1947 return Params.takeError(); \
1948 MFPM.addPass(CREATE_PASS(Params.get())); \
1949 return Error::success(); \
1950 }
1951#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1952 if (Name == "require<" NAME ">") { \
1953 MFPM.addPass( \
1954 RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>, \
1955 MachineFunction>()); \
1956 return Error::success(); \
1957 } \
1958 if (Name == "invalidate<" NAME ">") { \
1959 MFPM.addPass(InvalidateAnalysisPass< \
1960 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1961 return Error::success(); \
1962 }
1963#include "llvm/Passes/MachinePassRegistry.def"
1964
1965 for (auto &C : MachineFunctionPipelineParsingCallbacks)
1966 if (C(Name, MFPM, E.InnerPipeline))
1967 return Error::success();
1968 return make_error<StringError>(
1969 formatv("unknown machine pass '{0}'", Name).str(),
1971}
1972
1973bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
1974#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1975 if (Name == NAME) { \
1976 AA.registerModuleAnalysis< \
1977 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1978 return true; \
1979 }
1980#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
1981 if (Name == NAME) { \
1982 AA.registerFunctionAnalysis< \
1983 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
1984 return true; \
1985 }
1986#include "PassRegistry.def"
1987
1988 for (auto &C : AAParsingCallbacks)
1989 if (C(Name, AA))
1990 return true;
1991 return false;
1992}
1993
1994Error PassBuilder::parseMachinePassPipeline(
1996 for (const auto &Element : Pipeline) {
1997 if (auto Err = parseMachinePass(MFPM, Element))
1998 return Err;
1999 }
2000 return Error::success();
2001}
2002
2003Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2004 ArrayRef<PipelineElement> Pipeline) {
2005 for (const auto &Element : Pipeline) {
2006 if (auto Err = parseLoopPass(LPM, Element))
2007 return Err;
2008 }
2009 return Error::success();
2010}
2011
2012Error PassBuilder::parseFunctionPassPipeline(
2014 for (const auto &Element : Pipeline) {
2015 if (auto Err = parseFunctionPass(FPM, Element))
2016 return Err;
2017 }
2018 return Error::success();
2019}
2020
2021Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2022 ArrayRef<PipelineElement> Pipeline) {
2023 for (const auto &Element : Pipeline) {
2024 if (auto Err = parseCGSCCPass(CGPM, Element))
2025 return Err;
2026 }
2027 return Error::success();
2028}
2029
2042 if (MFAM) {
2044 [&] { return MachineFunctionAnalysisManagerModuleProxy(*MFAM); });
2046 [&] { return MachineFunctionAnalysisManagerFunctionProxy(*MFAM); });
2047 MFAM->registerPass(
2049 MFAM->registerPass(
2051 }
2052}
2053
2054Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2055 ArrayRef<PipelineElement> Pipeline) {
2056 for (const auto &Element : Pipeline) {
2057 if (auto Err = parseModulePass(MPM, Element))
2058 return Err;
2059 }
2060 return Error::success();
2061}
2062
2063// Primary pass pipeline description parsing routine for a \c ModulePassManager
2064// FIXME: Should this routine accept a TargetMachine or require the caller to
2065// pre-populate the analysis managers with target-specific stuff?
2067 StringRef PipelineText) {
2068 auto Pipeline = parsePipelineText(PipelineText);
2069 if (!Pipeline || Pipeline->empty())
2070 return make_error<StringError>(
2071 formatv("invalid pipeline '{0}'", PipelineText).str(),
2073
2074 // If the first name isn't at the module layer, wrap the pipeline up
2075 // automatically.
2076 StringRef FirstName = Pipeline->front().Name;
2077
2078 if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2079 bool UseMemorySSA;
2080 if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2081 Pipeline = {{"cgscc", std::move(*Pipeline)}};
2082 } else if (isFunctionPassName(FirstName,
2083 FunctionPipelineParsingCallbacks)) {
2084 Pipeline = {{"function", std::move(*Pipeline)}};
2085 } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
2086 UseMemorySSA)) {
2087 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2088 std::move(*Pipeline)}}}};
2089 } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
2090 UseMemorySSA)) {
2091 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2092 std::move(*Pipeline)}}}};
2093 } else if (isMachineFunctionPassName(
2094 FirstName, MachineFunctionPipelineParsingCallbacks)) {
2095 Pipeline = {{"function", {{"machine-function", std::move(*Pipeline)}}}};
2096 } else {
2097 for (auto &C : TopLevelPipelineParsingCallbacks)
2098 if (C(MPM, *Pipeline))
2099 return Error::success();
2100
2101 // Unknown pass or pipeline name!
2102 auto &InnerPipeline = Pipeline->front().InnerPipeline;
2103 return make_error<StringError>(
2104 formatv("unknown {0} name '{1}'",
2105 (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2106 .str(),
2108 }
2109 }
2110
2111 if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
2112 return Err;
2113 return Error::success();
2114}
2115
2116// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2118 StringRef PipelineText) {
2119 auto Pipeline = parsePipelineText(PipelineText);
2120 if (!Pipeline || Pipeline->empty())
2121 return make_error<StringError>(
2122 formatv("invalid pipeline '{0}'", PipelineText).str(),
2124
2125 StringRef FirstName = Pipeline->front().Name;
2126 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2127 return make_error<StringError>(
2128 formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
2129 PipelineText)
2130 .str(),
2132
2133 if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
2134 return Err;
2135 return Error::success();
2136}
2137
2138// Primary pass pipeline description parsing routine for a \c
2139// FunctionPassManager
2141 StringRef PipelineText) {
2142 auto Pipeline = parsePipelineText(PipelineText);
2143 if (!Pipeline || Pipeline->empty())
2144 return make_error<StringError>(
2145 formatv("invalid pipeline '{0}'", PipelineText).str(),
2147
2148 StringRef FirstName = Pipeline->front().Name;
2149 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2150 return make_error<StringError>(
2151 formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
2152 PipelineText)
2153 .str(),
2155
2156 if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
2157 return Err;
2158 return Error::success();
2159}
2160
2161// Primary pass pipeline description parsing routine for a \c LoopPassManager
2163 StringRef PipelineText) {
2164 auto Pipeline = parsePipelineText(PipelineText);
2165 if (!Pipeline || Pipeline->empty())
2166 return make_error<StringError>(
2167 formatv("invalid pipeline '{0}'", PipelineText).str(),
2169
2170 if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
2171 return Err;
2172
2173 return Error::success();
2174}
2175
2177 StringRef PipelineText) {
2178 auto Pipeline = parsePipelineText(PipelineText);
2179 if (!Pipeline || Pipeline->empty())
2180 return make_error<StringError>(
2181 formatv("invalid machine pass pipeline '{0}'", PipelineText).str(),
2183
2184 if (auto Err = parseMachinePassPipeline(MFPM, *Pipeline))
2185 return Err;
2186
2187 return Error::success();
2188}
2189
2191 // If the pipeline just consists of the word 'default' just replace the AA
2192 // manager with our default one.
2193 if (PipelineText == "default") {
2195 return Error::success();
2196 }
2197
2198 while (!PipelineText.empty()) {
2200 std::tie(Name, PipelineText) = PipelineText.split(',');
2201 if (!parseAAPassName(AA, Name))
2202 return make_error<StringError>(
2203 formatv("unknown alias analysis name '{0}'", Name).str(),
2205 }
2206
2207 return Error::success();
2208}
2209
2210std::optional<RegAllocFilterFunc>
2212 if (FilterName == "all")
2213 return nullptr;
2214 for (auto &C : RegClassFilterParsingCallbacks)
2215 if (auto F = C(FilterName))
2216 return F;
2217 return std::nullopt;
2218}
2219
2221 OS << " " << PassName << "\n";
2222}
2224 raw_ostream &OS) {
2225 OS << " " << PassName << "<" << Params << ">\n";
2226}
2227
2229 // TODO: print pass descriptions when they are available
2230
2231 OS << "Module passes:\n";
2232#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2233#include "PassRegistry.def"
2234
2235 OS << "Module passes with params:\n";
2236#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2237 printPassName(NAME, PARAMS, OS);
2238#include "PassRegistry.def"
2239
2240 OS << "Module analyses:\n";
2241#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2242#include "PassRegistry.def"
2243
2244 OS << "Module alias analyses:\n";
2245#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2246#include "PassRegistry.def"
2247
2248 OS << "CGSCC passes:\n";
2249#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2250#include "PassRegistry.def"
2251
2252 OS << "CGSCC passes with params:\n";
2253#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2254 printPassName(NAME, PARAMS, OS);
2255#include "PassRegistry.def"
2256
2257 OS << "CGSCC analyses:\n";
2258#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2259#include "PassRegistry.def"
2260
2261 OS << "Function passes:\n";
2262#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2263#include "PassRegistry.def"
2264
2265 OS << "Function passes with params:\n";
2266#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2267 printPassName(NAME, PARAMS, OS);
2268#include "PassRegistry.def"
2269
2270 OS << "Function analyses:\n";
2271#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2272#include "PassRegistry.def"
2273
2274 OS << "Function alias analyses:\n";
2275#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2276#include "PassRegistry.def"
2277
2278 OS << "LoopNest passes:\n";
2279#define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2280#include "PassRegistry.def"
2281
2282 OS << "Loop passes:\n";
2283#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2284#include "PassRegistry.def"
2285
2286 OS << "Loop passes with params:\n";
2287#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2288 printPassName(NAME, PARAMS, OS);
2289#include "PassRegistry.def"
2290
2291 OS << "Loop analyses:\n";
2292#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2293#include "PassRegistry.def"
2294
2295 OS << "Machine module passes (WIP):\n";
2296#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2297#include "llvm/Passes/MachinePassRegistry.def"
2298
2299 OS << "Machine function passes (WIP):\n";
2300#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2301#include "llvm/Passes/MachinePassRegistry.def"
2302
2303 OS << "Machine function analyses (WIP):\n";
2304#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2305#include "llvm/Passes/MachinePassRegistry.def"
2306}
2307
2309 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
2310 &C) {
2311 TopLevelPipelineParsingCallbacks.push_back(C);
2312}
unsigned const MachineRegisterInfo * MRI
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.
#define _
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
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
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
LoopAnalysisManager LAM
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
PassInstrumentationCallbacks PIC
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &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 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:78
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1498
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1520
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:467
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:61
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:239
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
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:550
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:563
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:42
An RAII based helper class to modify MachineFunctionProperties when running pass.
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const MachineFunctionProperties & getProperties() const
Get the function properties.
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.
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:106
void printPassNames(raw_ostream &OS)
Print pass names.
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
Definition: PassBuilder.h:643
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.
std::optional< RegAllocFilterFunc > parseRegAllocFilter(StringRef RegAllocFilterName)
Parse RegAllocFilterName to get RegAllocFilterFunc.
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 a 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 std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
Definition: PassManager.h:195
Tunable parameters for passes in the default pipelines.
Definition: PassBuilder.h:44
bool SLPVectorization
Tuning option to enable/disable slp loop vectorization, set based on opt level.
Definition: PassBuilder.h:59
bool LoopVectorization
Tuning option to enable/disable loop vectorization, set based on opt level.
Definition: PassBuilder.h:55
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:111
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:114
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
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:685
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:455
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:215
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:620
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:77
This function has undefined behavior.
self_iterator getIterator()
Definition: ilist_node.h:132
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
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:848
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:98
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:798
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
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:644
FunctionToMachineFunctionPassAdaptor createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass)
InnerAnalysisManagerProxy< MachineFunctionAnalysisManager, Function > MachineFunctionAnalysisManagerFunctionProxy
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
cl::opt< bool > PrintPipelinePasses
Common option used by multiple tools to print pipeline passes.
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.
@ Enable
Enable colors.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
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:69
static StringRef name()
Gets the name of the pass we are mixed into.
Definition: PassManager.h:71
RegAllocFilterFunc Filter
Definition: RegAllocFast.h:18