LLVM 22.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"
54#include "llvm/Analysis/Lint.h"
139#include "llvm/CodeGen/PEI.h"
181#include "llvm/IR/DebugInfo.h"
182#include "llvm/IR/Dominators.h"
183#include "llvm/IR/PassManager.h"
185#include "llvm/IR/Verifier.h"
189#include "llvm/Support/Debug.h"
192#include "llvm/Support/Regex.h"
381#include <optional>
382
383using namespace llvm;
384
386 "print-pipeline-passes",
387 cl::desc("Print a '-passes' compatible string describing the pipeline "
388 "(best-effort only)."));
389
390AnalysisKey NoOpModuleAnalysis::Key;
391AnalysisKey NoOpCGSCCAnalysis::Key;
392AnalysisKey NoOpFunctionAnalysis::Key;
393AnalysisKey NoOpLoopAnalysis::Key;
394
395namespace {
396
397// Passes for testing crashes.
398// DO NOT USE THIS EXCEPT FOR TESTING!
399class TriggerCrashModulePass : public PassInfoMixin<TriggerCrashModulePass> {
400public:
402 abort();
403 return PreservedAnalyses::all();
404 }
405 static StringRef name() { return "TriggerCrashModulePass"; }
406};
407
408class TriggerCrashFunctionPass
409 : public PassInfoMixin<TriggerCrashFunctionPass> {
410public:
412 abort();
413 return PreservedAnalyses::all();
414 }
415 static StringRef name() { return "TriggerCrashFunctionPass"; }
416};
417
418// A pass for testing message reporting of -verify-each failures.
419// DO NOT USE THIS EXCEPT FOR TESTING!
420class TriggerVerifierErrorPass
421 : public PassInfoMixin<TriggerVerifierErrorPass> {
422public:
424 // Intentionally break the Module by creating an alias without setting the
425 // aliasee.
426 auto *PtrTy = PointerType::getUnqual(M.getContext());
427 GlobalAlias::create(PtrTy, PtrTy->getAddressSpace(),
428 GlobalValue::LinkageTypes::InternalLinkage,
429 "__bad_alias", nullptr, &M);
431 }
432
434 // Intentionally break the Function by inserting a terminator
435 // instruction in the middle of a basic block.
436 BasicBlock &BB = F.getEntryBlock();
437 new UnreachableInst(F.getContext(), BB.getTerminator()->getIterator());
439 }
440
442 // Intentionally create a virtual register and set NoVRegs property.
443 auto &MRI = MF.getRegInfo();
444 MRI.createGenericVirtualRegister(LLT::scalar(8));
445 MF.getProperties().setNoVRegs();
446 return PreservedAnalyses::all();
447 }
448
449 static StringRef name() { return "TriggerVerifierErrorPass"; }
450};
451
452// A pass requires all MachineFunctionProperties.
453// DO NOT USE THIS EXCEPT FOR TESTING!
454class RequireAllMachineFunctionPropertiesPass
455 : public PassInfoMixin<RequireAllMachineFunctionPropertiesPass> {
456public:
458 MFPropsModifier _(*this, MF);
460 }
461
462 static MachineFunctionProperties getRequiredProperties() {
464 .setFailedISel()
465 .setFailsVerification()
466 .setIsSSA()
467 .setLegalized()
468 .setNoPHIs()
469 .setNoVRegs()
470 .setRegBankSelected()
471 .setSelected()
472 .setTiedOpsRewritten()
473 .setTracksDebugUserValues()
474 .setTracksLiveness();
475 }
476 static StringRef name() { return "RequireAllMachineFunctionPropertiesPass"; }
477};
478
479} // namespace
480
482 std::optional<PGOOptions> PGOOpt,
484 : TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
485 if (TM)
486 TM->registerPassBuilderCallbacks(*this);
487 if (PIC) {
489 // MSVC requires this to be captured if it's used inside decltype.
490 // Other compilers consider it an unused lambda capture.
491 (void)this;
492#define MODULE_PASS(NAME, CREATE_PASS) \
493 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
494#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
495 PIC->addClassToPassName(CLASS, NAME);
496#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
497 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
498#define FUNCTION_PASS(NAME, CREATE_PASS) \
499 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
500#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
501 PIC->addClassToPassName(CLASS, NAME);
502#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
503 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
504#define LOOPNEST_PASS(NAME, CREATE_PASS) \
505 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
506#define LOOP_PASS(NAME, CREATE_PASS) \
507 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
508#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
509 PIC->addClassToPassName(CLASS, NAME);
510#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
511 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
512#define CGSCC_PASS(NAME, CREATE_PASS) \
513 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
514#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
515 PIC->addClassToPassName(CLASS, NAME);
516#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
517 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
518#include "PassRegistry.def"
519
520#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
521 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
522#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
523 PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME);
524#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
525 PARAMS) \
526 PIC->addClassToPassName(CLASS, NAME);
527#include "llvm/Passes/MachinePassRegistry.def"
528 });
529 }
530}
531
533#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
534 MAM.registerPass([&] { return CREATE_PASS; });
535#include "PassRegistry.def"
536
537 for (auto &C : ModuleAnalysisRegistrationCallbacks)
538 C(MAM);
539}
540
542#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
543 CGAM.registerPass([&] { return CREATE_PASS; });
544#include "PassRegistry.def"
545
546 for (auto &C : CGSCCAnalysisRegistrationCallbacks)
547 C(CGAM);
548}
549
551 // We almost always want the default alias analysis pipeline.
552 // If a user wants a different one, they can register their own before calling
553 // registerFunctionAnalyses().
554 FAM.registerPass([&] { return buildDefaultAAPipeline(); });
555
556#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
557 FAM.registerPass([&] { return CREATE_PASS; });
558#include "PassRegistry.def"
559
560 for (auto &C : FunctionAnalysisRegistrationCallbacks)
561 C(FAM);
562}
563
566
567#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
568 MFAM.registerPass([&] { return CREATE_PASS; });
569#include "llvm/Passes/MachinePassRegistry.def"
570
571 for (auto &C : MachineFunctionAnalysisRegistrationCallbacks)
572 C(MFAM);
573}
574
576#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
577 LAM.registerPass([&] { return CREATE_PASS; });
578#include "PassRegistry.def"
579
580 for (auto &C : LoopAnalysisRegistrationCallbacks)
581 C(LAM);
582}
583
584static std::optional<std::pair<bool, bool>>
586 std::pair<bool, bool> Params;
587 if (!Name.consume_front("function"))
588 return std::nullopt;
589 if (Name.empty())
590 return Params;
591 if (!Name.consume_front("<") || !Name.consume_back(">"))
592 return std::nullopt;
593 while (!Name.empty()) {
594 auto [Front, Back] = Name.split(';');
595 Name = Back;
596 if (Front == "eager-inv")
597 Params.first = true;
598 else if (Front == "no-rerun")
599 Params.second = true;
600 else
601 return std::nullopt;
602 }
603 return Params;
604}
605
606static std::optional<int> parseDevirtPassName(StringRef Name) {
607 if (!Name.consume_front("devirt<") || !Name.consume_back(">"))
608 return std::nullopt;
609 int Count;
610 if (Name.getAsInteger(0, Count) || Count < 0)
611 return std::nullopt;
612 return Count;
613}
614
615static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
617 .Case("O0", OptimizationLevel::O0)
623 .Default(std::nullopt);
624}
625
627 std::optional<OptimizationLevel> OptLevel = parseOptLevel(S);
628 if (OptLevel)
629 return *OptLevel;
630 return make_error<StringError>(
631 formatv("invalid optimization level '{}'", S).str(),
633}
634
636 StringRef OptionName,
638 bool Result = false;
639 while (!Params.empty()) {
640 StringRef ParamName;
641 std::tie(ParamName, Params) = Params.split(';');
642
643 if (ParamName == OptionName) {
644 Result = true;
645 } else {
646 return make_error<StringError>(
647 formatv("invalid {} pass parameter '{}'", PassName, ParamName).str(),
649 }
650 }
651 return Result;
652}
653
654namespace {
655
656/// Parser of parameters for HardwareLoops pass.
657Expected<HardwareLoopOptions> parseHardwareLoopOptions(StringRef Params) {
658 HardwareLoopOptions HardwareLoopOpts;
659
660 while (!Params.empty()) {
661 StringRef ParamName;
662 std::tie(ParamName, Params) = Params.split(';');
663 if (ParamName.consume_front("hardware-loop-decrement=")) {
664 int Count;
665 if (ParamName.getAsInteger(0, Count))
666 return make_error<StringError>(
667 formatv("invalid HardwareLoopPass parameter '{}'", ParamName).str(),
669 HardwareLoopOpts.setDecrement(Count);
670 continue;
671 }
672 if (ParamName.consume_front("hardware-loop-counter-bitwidth=")) {
673 int Count;
674 if (ParamName.getAsInteger(0, Count))
675 return make_error<StringError>(
676 formatv("invalid HardwareLoopPass parameter '{}'", ParamName).str(),
678 HardwareLoopOpts.setCounterBitwidth(Count);
679 continue;
680 }
681 if (ParamName == "force-hardware-loops") {
682 HardwareLoopOpts.setForce(true);
683 } else if (ParamName == "force-hardware-loop-phi") {
684 HardwareLoopOpts.setForcePhi(true);
685 } else if (ParamName == "force-nested-hardware-loop") {
686 HardwareLoopOpts.setForceNested(true);
687 } else if (ParamName == "force-hardware-loop-guard") {
688 HardwareLoopOpts.setForceGuard(true);
689 } else {
690 return make_error<StringError>(
691 formatv("invalid HardwarePass parameter '{}'", ParamName).str(),
693 }
694 }
695 return HardwareLoopOpts;
696}
697
698/// Parser of parameters for Lint pass.
699Expected<bool> parseLintOptions(StringRef Params) {
700 return PassBuilder::parseSinglePassOption(Params, "abort-on-error",
701 "LintPass");
702}
703
704/// Parser of parameters for LoopUnroll pass.
705Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
706 LoopUnrollOptions UnrollOpts;
707 while (!Params.empty()) {
708 StringRef ParamName;
709 std::tie(ParamName, Params) = Params.split(';');
710 std::optional<OptimizationLevel> OptLevel = parseOptLevel(ParamName);
711 // Don't accept -Os/-Oz.
712 if (OptLevel && !OptLevel->isOptimizingForSize()) {
713 UnrollOpts.setOptLevel(OptLevel->getSpeedupLevel());
714 continue;
715 }
716 if (ParamName.consume_front("full-unroll-max=")) {
717 int Count;
718 if (ParamName.getAsInteger(0, Count))
719 return make_error<StringError>(
720 formatv("invalid LoopUnrollPass parameter '{}'", ParamName).str(),
722 UnrollOpts.setFullUnrollMaxCount(Count);
723 continue;
724 }
725
726 bool Enable = !ParamName.consume_front("no-");
727 if (ParamName == "partial") {
728 UnrollOpts.setPartial(Enable);
729 } else if (ParamName == "peeling") {
730 UnrollOpts.setPeeling(Enable);
731 } else if (ParamName == "profile-peeling") {
732 UnrollOpts.setProfileBasedPeeling(Enable);
733 } else if (ParamName == "runtime") {
734 UnrollOpts.setRuntime(Enable);
735 } else if (ParamName == "upperbound") {
736 UnrollOpts.setUpperBound(Enable);
737 } else {
738 return make_error<StringError>(
739 formatv("invalid LoopUnrollPass parameter '{}'", ParamName).str(),
741 }
742 }
743 return UnrollOpts;
744}
745
746Expected<bool> parseGlobalDCEPassOptions(StringRef Params) {
748 Params, "vfe-linkage-unit-visibility", "GlobalDCE");
749}
750
751Expected<bool> parseCGProfilePassOptions(StringRef Params) {
752 return PassBuilder::parseSinglePassOption(Params, "in-lto-post-link",
753 "CGProfile");
754}
755
756Expected<bool> parseInlinerPassOptions(StringRef Params) {
757 return PassBuilder::parseSinglePassOption(Params, "only-mandatory",
758 "InlinerPass");
759}
760
761Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
762 return PassBuilder::parseSinglePassOption(Params, "reuse-storage",
763 "CoroSplitPass");
764}
765
766Expected<bool> parsePostOrderFunctionAttrsPassOptions(StringRef Params) {
768 Params, "skip-non-recursive-function-attrs", "PostOrderFunctionAttrs");
769}
770
771Expected<CFGuardPass::Mechanism> parseCFGuardPassOptions(StringRef Params) {
772 if (Params.empty())
774
775 auto [Param, RHS] = Params.split(';');
776 if (!RHS.empty())
777 return make_error<StringError>(
778 formatv("too many CFGuardPass parameters '{}'", Params).str(),
780
781 if (Param == "check")
783 if (Param == "dispatch")
785
786 return make_error<StringError>(
787 formatv("invalid CFGuardPass mechanism: '{}'", Param).str(),
789}
790
791Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
792 return PassBuilder::parseSinglePassOption(Params, "memssa", "EarlyCSE");
793}
794
795Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
796 return PassBuilder::parseSinglePassOption(Params, "post-inline",
797 "EntryExitInstrumenter");
798}
799
800Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
801 return PassBuilder::parseSinglePassOption(Params, "single", "LoopExtractor");
802}
803
804Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
805 return PassBuilder::parseSinglePassOption(Params, "minimal",
806 "LowerMatrixIntrinsics");
807}
808
809Expected<IRNormalizerOptions> parseIRNormalizerPassOptions(StringRef Params) {
811 while (!Params.empty()) {
812 StringRef ParamName;
813 std::tie(ParamName, Params) = Params.split(';');
814
815 bool Enable = !ParamName.consume_front("no-");
816 if (ParamName == "preserve-order")
817 Result.PreserveOrder = Enable;
818 else if (ParamName == "rename-all")
819 Result.RenameAll = Enable;
820 else if (ParamName == "fold-all") // FIXME: Name mismatch
821 Result.FoldPreOutputs = Enable;
822 else if (ParamName == "reorder-operands")
823 Result.ReorderOperands = Enable;
824 else {
825 return make_error<StringError>(
826 formatv("invalid normalize pass parameter '{}'", ParamName).str(),
828 }
829 }
830
831 return Result;
832}
833
834Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
836 while (!Params.empty()) {
837 StringRef ParamName;
838 std::tie(ParamName, Params) = Params.split(';');
839
840 if (ParamName == "kernel") {
841 Result.CompileKernel = true;
842 } else if (ParamName == "use-after-scope") {
843 Result.UseAfterScope = true;
844 } else {
845 return make_error<StringError>(
846 formatv("invalid AddressSanitizer pass parameter '{}'", ParamName)
847 .str(),
849 }
850 }
851 return Result;
852}
853
854Expected<HWAddressSanitizerOptions> parseHWASanPassOptions(StringRef Params) {
856 while (!Params.empty()) {
857 StringRef ParamName;
858 std::tie(ParamName, Params) = Params.split(';');
859
860 if (ParamName == "recover") {
861 Result.Recover = true;
862 } else if (ParamName == "kernel") {
863 Result.CompileKernel = true;
864 } else {
865 return make_error<StringError>(
866 formatv("invalid HWAddressSanitizer pass parameter '{}'", ParamName)
867 .str(),
869 }
870 }
871 return Result;
872}
873
874Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
876 while (!Params.empty()) {
877 StringRef ParamName;
878 std::tie(ParamName, Params) = Params.split(';');
879
880 if (ParamName == "thinlto") {
881 Result.IsThinLTO = true;
882 } else if (ParamName == "emit-summary") {
883 Result.EmitLTOSummary = true;
884 } else {
885 return make_error<StringError>(
886 formatv("invalid EmbedBitcode pass parameter '{}'", ParamName).str(),
888 }
889 }
890 return Result;
891}
892
894parseLowerAllowCheckPassOptions(StringRef Params) {
896 while (!Params.empty()) {
897 StringRef ParamName;
898 std::tie(ParamName, Params) = Params.split(';');
899
900 // Format is <cutoffs[1,2,3]=70000;cutoffs[5,6,8]=90000>
901 //
902 // Parsing allows duplicate indices (last one takes precedence).
903 // It would technically be in spec to specify
904 // cutoffs[0]=70000,cutoffs[1]=90000,cutoffs[0]=80000,...
905 if (ParamName.starts_with("cutoffs[")) {
906 StringRef IndicesStr;
907 StringRef CutoffStr;
908
909 std::tie(IndicesStr, CutoffStr) = ParamName.split("]=");
910 // cutoffs[1,2,3
911 // 70000
912
913 int cutoff;
914 if (CutoffStr.getAsInteger(0, cutoff))
915 return make_error<StringError>(
916 formatv("invalid LowerAllowCheck pass cutoffs parameter '{}' ({})",
917 CutoffStr, Params)
918 .str(),
920
921 if (!IndicesStr.consume_front("cutoffs[") || IndicesStr == "")
922 return make_error<StringError>(
923 formatv("invalid LowerAllowCheck pass index parameter '{}' ({})",
924 IndicesStr, CutoffStr)
925 .str(),
927
928 while (IndicesStr != "") {
929 StringRef firstIndexStr;
930 std::tie(firstIndexStr, IndicesStr) = IndicesStr.split('|');
931
932 unsigned int index;
933 if (firstIndexStr.getAsInteger(0, index))
934 return make_error<StringError>(
935 formatv(
936 "invalid LowerAllowCheck pass index parameter '{}' ({}) {}",
937 firstIndexStr, IndicesStr)
938 .str(),
940
941 // In the common case (sequentially increasing indices), we will issue
942 // O(n) resize requests. We assume the underlying data structure has
943 // O(1) runtime for each added element.
944 if (index >= Result.cutoffs.size())
945 Result.cutoffs.resize(index + 1, 0);
946
947 Result.cutoffs[index] = cutoff;
948 }
949 } else if (ParamName.starts_with("runtime_check")) {
950 StringRef ValueString;
951 std::tie(std::ignore, ValueString) = ParamName.split("=");
952 int runtime_check;
953 if (ValueString.getAsInteger(0, runtime_check)) {
954 return make_error<StringError>(
955 formatv("invalid LowerAllowCheck pass runtime_check parameter '{}' "
956 "({})",
957 ValueString, Params)
958 .str(),
960 }
961 Result.runtime_check = runtime_check;
962 } else {
963 return make_error<StringError>(
964 formatv("invalid LowerAllowCheck pass parameter '{}'", ParamName)
965 .str(),
967 }
968 }
969
970 return Result;
971}
972
973Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
975 while (!Params.empty()) {
976 StringRef ParamName;
977 std::tie(ParamName, Params) = Params.split(';');
978
979 if (ParamName == "recover") {
980 Result.Recover = true;
981 } else if (ParamName == "kernel") {
982 Result.Kernel = true;
983 } else if (ParamName.consume_front("track-origins=")) {
984 if (ParamName.getAsInteger(0, Result.TrackOrigins))
985 return make_error<StringError>(
986 formatv("invalid argument to MemorySanitizer pass track-origins "
987 "parameter: '{}'",
988 ParamName)
989 .str(),
991 } else if (ParamName == "eager-checks") {
992 Result.EagerChecks = true;
993 } else {
994 return make_error<StringError>(
995 formatv("invalid MemorySanitizer pass parameter '{}'", ParamName)
996 .str(),
998 }
999 }
1000 return Result;
1001}
1002
1003/// Parser of parameters for SimplifyCFG pass.
1004Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
1006 while (!Params.empty()) {
1007 StringRef ParamName;
1008 std::tie(ParamName, Params) = Params.split(';');
1009
1010 bool Enable = !ParamName.consume_front("no-");
1011 if (ParamName == "speculate-blocks") {
1012 Result.speculateBlocks(Enable);
1013 } else if (ParamName == "simplify-cond-branch") {
1014 Result.setSimplifyCondBranch(Enable);
1015 } else if (ParamName == "forward-switch-cond") {
1016 Result.forwardSwitchCondToPhi(Enable);
1017 } else if (ParamName == "switch-range-to-icmp") {
1018 Result.convertSwitchRangeToICmp(Enable);
1019 } else if (ParamName == "switch-to-lookup") {
1020 Result.convertSwitchToLookupTable(Enable);
1021 } else if (ParamName == "keep-loops") {
1022 Result.needCanonicalLoops(Enable);
1023 } else if (ParamName == "hoist-common-insts") {
1024 Result.hoistCommonInsts(Enable);
1025 } else if (ParamName == "hoist-loads-stores-with-cond-faulting") {
1026 Result.hoistLoadsStoresWithCondFaulting(Enable);
1027 } else if (ParamName == "sink-common-insts") {
1028 Result.sinkCommonInsts(Enable);
1029 } else if (ParamName == "speculate-unpredictables") {
1030 Result.speculateUnpredictables(Enable);
1031 } else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
1032 APInt BonusInstThreshold;
1033 if (ParamName.getAsInteger(0, BonusInstThreshold))
1034 return make_error<StringError>(
1035 formatv("invalid argument to SimplifyCFG pass bonus-threshold "
1036 "parameter: '{}'",
1037 ParamName)
1038 .str(),
1040 Result.bonusInstThreshold(BonusInstThreshold.getSExtValue());
1041 } else {
1042 return make_error<StringError>(
1043 formatv("invalid SimplifyCFG pass parameter '{}'", ParamName).str(),
1045 }
1046 }
1047 return Result;
1048}
1049
1050Expected<InstCombineOptions> parseInstCombineOptions(StringRef Params) {
1052 // When specifying "instcombine" in -passes enable fix-point verification by
1053 // default, as this is what most tests should use.
1054 Result.setVerifyFixpoint(true);
1055 while (!Params.empty()) {
1056 StringRef ParamName;
1057 std::tie(ParamName, Params) = Params.split(';');
1058
1059 bool Enable = !ParamName.consume_front("no-");
1060 if (ParamName == "verify-fixpoint") {
1061 Result.setVerifyFixpoint(Enable);
1062 } else if (Enable && ParamName.consume_front("max-iterations=")) {
1063 APInt MaxIterations;
1064 if (ParamName.getAsInteger(0, MaxIterations))
1065 return make_error<StringError>(
1066 formatv("invalid argument to InstCombine pass max-iterations "
1067 "parameter: '{}'",
1068 ParamName)
1069 .str(),
1071 Result.setMaxIterations((unsigned)MaxIterations.getZExtValue());
1072 } else {
1073 return make_error<StringError>(
1074 formatv("invalid InstCombine pass parameter '{}'", ParamName).str(),
1076 }
1077 }
1078 return Result;
1079}
1080
1081/// Parser of parameters for LoopVectorize pass.
1082Expected<LoopVectorizeOptions> parseLoopVectorizeOptions(StringRef Params) {
1084 while (!Params.empty()) {
1085 StringRef ParamName;
1086 std::tie(ParamName, Params) = Params.split(';');
1087
1088 bool Enable = !ParamName.consume_front("no-");
1089 if (ParamName == "interleave-forced-only") {
1091 } else if (ParamName == "vectorize-forced-only") {
1093 } else {
1094 return make_error<StringError>(
1095 formatv("invalid LoopVectorize parameter '{}'", ParamName).str(),
1097 }
1098 }
1099 return Opts;
1100}
1101
1102Expected<std::pair<bool, bool>> parseLoopUnswitchOptions(StringRef Params) {
1103 std::pair<bool, bool> Result = {false, true};
1104 while (!Params.empty()) {
1105 StringRef ParamName;
1106 std::tie(ParamName, Params) = Params.split(';');
1107
1108 bool Enable = !ParamName.consume_front("no-");
1109 if (ParamName == "nontrivial") {
1110 Result.first = Enable;
1111 } else if (ParamName == "trivial") {
1112 Result.second = Enable;
1113 } else {
1114 return make_error<StringError>(
1115 formatv("invalid LoopUnswitch pass parameter '{}'", ParamName).str(),
1117 }
1118 }
1119 return Result;
1120}
1121
1122Expected<LICMOptions> parseLICMOptions(StringRef Params) {
1124 while (!Params.empty()) {
1125 StringRef ParamName;
1126 std::tie(ParamName, Params) = Params.split(';');
1127
1128 bool Enable = !ParamName.consume_front("no-");
1129 if (ParamName == "allowspeculation") {
1130 Result.AllowSpeculation = Enable;
1131 } else {
1132 return make_error<StringError>(
1133 formatv("invalid LICM pass parameter '{}'", ParamName).str(),
1135 }
1136 }
1137 return Result;
1138}
1139
1140Expected<std::pair<bool, bool>> parseLoopRotateOptions(StringRef Params) {
1141 std::pair<bool, bool> Result = {true, false};
1142 while (!Params.empty()) {
1143 StringRef ParamName;
1144 std::tie(ParamName, Params) = Params.split(';');
1145
1146 bool Enable = !ParamName.consume_front("no-");
1147 if (ParamName == "header-duplication") {
1148 Result.first = Enable;
1149 } else if (ParamName == "prepare-for-lto") {
1150 Result.second = Enable;
1151 } else {
1152 return make_error<StringError>(
1153 formatv("invalid LoopRotate pass parameter '{}'", ParamName).str(),
1155 }
1156 }
1157 return Result;
1158}
1159
1160Expected<bool> parseMergedLoadStoreMotionOptions(StringRef Params) {
1161 bool Result = false;
1162 while (!Params.empty()) {
1163 StringRef ParamName;
1164 std::tie(ParamName, Params) = Params.split(';');
1165
1166 bool Enable = !ParamName.consume_front("no-");
1167 if (ParamName == "split-footer-bb") {
1168 Result = Enable;
1169 } else {
1170 return make_error<StringError>(
1171 formatv("invalid MergedLoadStoreMotion pass parameter '{}'",
1172 ParamName)
1173 .str(),
1175 }
1176 }
1177 return Result;
1178}
1179
1180Expected<GVNOptions> parseGVNOptions(StringRef Params) {
1182 while (!Params.empty()) {
1183 StringRef ParamName;
1184 std::tie(ParamName, Params) = Params.split(';');
1185
1186 bool Enable = !ParamName.consume_front("no-");
1187 if (ParamName == "pre") {
1188 Result.setPRE(Enable);
1189 } else if (ParamName == "load-pre") {
1190 Result.setLoadPRE(Enable);
1191 } else if (ParamName == "split-backedge-load-pre") {
1192 Result.setLoadPRESplitBackedge(Enable);
1193 } else if (ParamName == "memdep") {
1194 // MemDep and MemorySSA are mutually exclusive.
1195 Result.setMemDep(Enable);
1196 Result.setMemorySSA(!Enable);
1197 } else if (ParamName == "memoryssa") {
1198 // MemDep and MemorySSA are mutually exclusive.
1199 Result.setMemorySSA(Enable);
1200 Result.setMemDep(!Enable);
1201 } else {
1202 return make_error<StringError>(
1203 formatv("invalid GVN pass parameter '{}'", ParamName).str(),
1205 }
1206 }
1207 return Result;
1208}
1209
1210Expected<IPSCCPOptions> parseIPSCCPOptions(StringRef Params) {
1212 while (!Params.empty()) {
1213 StringRef ParamName;
1214 std::tie(ParamName, Params) = Params.split(';');
1215
1216 bool Enable = !ParamName.consume_front("no-");
1217 if (ParamName == "func-spec")
1218 Result.setFuncSpec(Enable);
1219 else
1220 return make_error<StringError>(
1221 formatv("invalid IPSCCP pass parameter '{}'", ParamName).str(),
1223 }
1224 return Result;
1225}
1226
1227Expected<ScalarizerPassOptions> parseScalarizerOptions(StringRef Params) {
1229 while (!Params.empty()) {
1230 StringRef ParamName;
1231 std::tie(ParamName, Params) = Params.split(';');
1232
1233 if (ParamName.consume_front("min-bits=")) {
1234 if (ParamName.getAsInteger(0, Result.ScalarizeMinBits)) {
1235 return make_error<StringError>(
1236 formatv("invalid argument to Scalarizer pass min-bits "
1237 "parameter: '{}'",
1238 ParamName)
1239 .str(),
1241 }
1242
1243 continue;
1244 }
1245
1246 bool Enable = !ParamName.consume_front("no-");
1247 if (ParamName == "load-store")
1248 Result.ScalarizeLoadStore = Enable;
1249 else if (ParamName == "variable-insert-extract")
1250 Result.ScalarizeVariableInsertExtract = Enable;
1251 else {
1252 return make_error<StringError>(
1253 formatv("invalid Scalarizer pass parameter '{}'", ParamName).str(),
1255 }
1256 }
1257
1258 return Result;
1259}
1260
1261Expected<SROAOptions> parseSROAOptions(StringRef Params) {
1262 if (Params.empty() || Params == "modify-cfg")
1264 if (Params == "preserve-cfg")
1266 return make_error<StringError>(
1267 formatv("invalid SROA pass parameter '{}' (either preserve-cfg or "
1268 "modify-cfg can be specified)",
1269 Params)
1270 .str(),
1272}
1273
1275parseStackLifetimeOptions(StringRef Params) {
1277 while (!Params.empty()) {
1278 StringRef ParamName;
1279 std::tie(ParamName, Params) = Params.split(';');
1280
1281 if (ParamName == "may") {
1283 } else if (ParamName == "must") {
1285 } else {
1286 return make_error<StringError>(
1287 formatv("invalid StackLifetime parameter '{}'", ParamName).str(),
1289 }
1290 }
1291 return Result;
1292}
1293
1294Expected<bool> parseDependenceAnalysisPrinterOptions(StringRef Params) {
1295 return PassBuilder::parseSinglePassOption(Params, "normalized-results",
1296 "DependenceAnalysisPrinter");
1297}
1298
1299Expected<bool> parseSeparateConstOffsetFromGEPPassOptions(StringRef Params) {
1300 return PassBuilder::parseSinglePassOption(Params, "lower-gep",
1301 "SeparateConstOffsetFromGEP");
1302}
1303
1304Expected<bool> parseStructurizeCFGPassOptions(StringRef Params) {
1305 return PassBuilder::parseSinglePassOption(Params, "skip-uniform-regions",
1306 "StructurizeCFG");
1307}
1308
1310parseFunctionSimplificationPipelineOptions(StringRef Params) {
1311 std::optional<OptimizationLevel> L = parseOptLevel(Params);
1312 if (!L || *L == OptimizationLevel::O0) {
1313 return make_error<StringError>(
1314 formatv("invalid function-simplification parameter '{}'", Params).str(),
1316 };
1317 return *L;
1318}
1319
1320Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
1321 return PassBuilder::parseSinglePassOption(Params, "no-ensure-optimized-uses",
1322 "MemorySSAPrinterPass");
1323}
1324
1325Expected<bool> parseSpeculativeExecutionPassOptions(StringRef Params) {
1326 return PassBuilder::parseSinglePassOption(Params, "only-if-divergent-target",
1327 "SpeculativeExecutionPass");
1328}
1329
1330Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
1331 std::string Result;
1332 while (!Params.empty()) {
1333 StringRef ParamName;
1334 std::tie(ParamName, Params) = Params.split(';');
1335
1336 if (ParamName.consume_front("profile-filename=")) {
1337 Result = ParamName.str();
1338 } else {
1339 return make_error<StringError>(
1340 formatv("invalid MemProfUse pass parameter '{}'", ParamName).str(),
1342 }
1343 }
1344 return Result;
1345}
1346
1348parseStructuralHashPrinterPassOptions(StringRef Params) {
1349 if (Params.empty())
1351 if (Params == "detailed")
1353 if (Params == "call-target-ignored")
1355 return make_error<StringError>(
1356 formatv("invalid structural hash printer parameter '{}'", Params).str(),
1358}
1359
1360Expected<bool> parseWinEHPrepareOptions(StringRef Params) {
1361 return PassBuilder::parseSinglePassOption(Params, "demote-catchswitch-only",
1362 "WinEHPreparePass");
1363}
1364
1365Expected<GlobalMergeOptions> parseGlobalMergeOptions(StringRef Params) {
1367 while (!Params.empty()) {
1368 StringRef ParamName;
1369 std::tie(ParamName, Params) = Params.split(';');
1370
1371 bool Enable = !ParamName.consume_front("no-");
1372 if (ParamName == "group-by-use")
1373 Result.GroupByUse = Enable;
1374 else if (ParamName == "ignore-single-use")
1375 Result.IgnoreSingleUse = Enable;
1376 else if (ParamName == "merge-const")
1377 Result.MergeConstantGlobals = Enable;
1378 else if (ParamName == "merge-const-aggressive")
1379 Result.MergeConstAggressive = Enable;
1380 else if (ParamName == "merge-external")
1381 Result.MergeExternal = Enable;
1382 else if (ParamName.consume_front("max-offset=")) {
1383 if (ParamName.getAsInteger(0, Result.MaxOffset))
1384 return make_error<StringError>(
1385 formatv("invalid GlobalMergePass parameter '{}'", ParamName).str(),
1387 } else {
1388 return make_error<StringError>(
1389 formatv("invalid global-merge pass parameter '{}'", Params).str(),
1391 }
1392 }
1393 return Result;
1394}
1395
1396Expected<SmallVector<std::string, 0>> parseInternalizeGVs(StringRef Params) {
1397 SmallVector<std::string, 1> PreservedGVs;
1398 while (!Params.empty()) {
1399 StringRef ParamName;
1400 std::tie(ParamName, Params) = Params.split(';');
1401
1402 if (ParamName.consume_front("preserve-gv=")) {
1403 PreservedGVs.push_back(ParamName.str());
1404 } else {
1405 return make_error<StringError>(
1406 formatv("invalid Internalize pass parameter '{}'", ParamName).str(),
1408 }
1409 }
1410
1411 return Expected<SmallVector<std::string, 0>>(std::move(PreservedGVs));
1412}
1413
1415parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) {
1417 while (!Params.empty()) {
1418 StringRef ParamName;
1419 std::tie(ParamName, Params) = Params.split(';');
1420
1421 if (ParamName.consume_front("filter=")) {
1422 std::optional<RegAllocFilterFunc> Filter =
1423 PB.parseRegAllocFilter(ParamName);
1424 if (!Filter) {
1425 return make_error<StringError>(
1426 formatv("invalid regallocfast register filter '{}'", ParamName)
1427 .str(),
1429 }
1430 Opts.Filter = *Filter;
1431 Opts.FilterName = ParamName;
1432 continue;
1433 }
1434
1435 if (ParamName == "no-clear-vregs") {
1436 Opts.ClearVRegs = false;
1437 continue;
1438 }
1439
1440 return make_error<StringError>(
1441 formatv("invalid regallocfast pass parameter '{}'", ParamName).str(),
1443 }
1444 return Opts;
1445}
1446
1448parseBoundsCheckingOptions(StringRef Params) {
1450 while (!Params.empty()) {
1451 StringRef ParamName;
1452 std::tie(ParamName, Params) = Params.split(';');
1453 if (ParamName == "trap") {
1454 Options.Rt = std::nullopt;
1455 } else if (ParamName == "rt") {
1456 Options.Rt = {
1457 /*MinRuntime=*/false,
1458 /*MayReturn=*/true,
1459 };
1460 } else if (ParamName == "rt-abort") {
1461 Options.Rt = {
1462 /*MinRuntime=*/false,
1463 /*MayReturn=*/false,
1464 };
1465 } else if (ParamName == "min-rt") {
1466 Options.Rt = {
1467 /*MinRuntime=*/true,
1468 /*MayReturn=*/true,
1469 };
1470 } else if (ParamName == "min-rt-abort") {
1471 Options.Rt = {
1472 /*MinRuntime=*/true,
1473 /*MayReturn=*/false,
1474 };
1475 } else if (ParamName == "merge") {
1476 Options.Merge = true;
1477 } else {
1478 StringRef ParamEQ;
1479 StringRef Val;
1480 std::tie(ParamEQ, Val) = ParamName.split('=');
1481 int8_t Id;
1482 if (ParamEQ == "guard" && !Val.getAsInteger(0, Id)) {
1483 Options.GuardKind = Id;
1484 } else {
1485 return make_error<StringError>(
1486 formatv("invalid BoundsChecking pass parameter '{}'", ParamName)
1487 .str(),
1489 }
1490 }
1491 }
1492 return Options;
1493}
1494
1496parseRegAllocGreedyFilterFunc(PassBuilder &PB, StringRef Params) {
1497 if (Params.empty() || Params == "all")
1498 return RAGreedyPass::Options();
1499
1500 std::optional<RegAllocFilterFunc> Filter = PB.parseRegAllocFilter(Params);
1501 if (Filter)
1502 return RAGreedyPass::Options{*Filter, Params};
1503
1504 return make_error<StringError>(
1505 formatv("invalid regallocgreedy register filter '{}'", Params).str(),
1507}
1508
1509Expected<bool> parseMachineSinkingPassOptions(StringRef Params) {
1510 return PassBuilder::parseSinglePassOption(Params, "enable-sink-fold",
1511 "MachineSinkingPass");
1512}
1513
1514Expected<bool> parseMachineBlockPlacementPassOptions(StringRef Params) {
1515 bool AllowTailMerge = true;
1516 if (!Params.empty()) {
1517 AllowTailMerge = !Params.consume_front("no-");
1518 if (Params != "tail-merge")
1519 return make_error<StringError>(
1520 formatv("invalid MachineBlockPlacementPass parameter '{}'", Params)
1521 .str(),
1523 }
1524 return AllowTailMerge;
1525}
1526
1527Expected<bool> parseVirtRegRewriterPassOptions(StringRef Params) {
1528 bool ClearVirtRegs = true;
1529 if (!Params.empty()) {
1530 ClearVirtRegs = !Params.consume_front("no-");
1531 if (Params != "clear-vregs")
1532 return make_error<StringError>(
1533 formatv("invalid VirtRegRewriter pass parameter '{}'", Params).str(),
1535 }
1536 return ClearVirtRegs;
1537}
1538
1539struct FatLTOOptions {
1540 OptimizationLevel OptLevel;
1541 bool ThinLTO = false;
1542 bool EmitSummary = false;
1543};
1544
1545Expected<FatLTOOptions> parseFatLTOOptions(StringRef Params) {
1546 FatLTOOptions Result;
1547 bool HaveOptLevel = false;
1548 while (!Params.empty()) {
1549 StringRef ParamName;
1550 std::tie(ParamName, Params) = Params.split(';');
1551
1552 if (ParamName == "thinlto") {
1553 Result.ThinLTO = true;
1554 } else if (ParamName == "emit-summary") {
1555 Result.EmitSummary = true;
1556 } else if (std::optional<OptimizationLevel> OptLevel =
1557 parseOptLevel(ParamName)) {
1558 Result.OptLevel = *OptLevel;
1559 HaveOptLevel = true;
1560 } else {
1561 return make_error<StringError>(
1562 formatv("invalid fatlto-pre-link pass parameter '{}'", ParamName)
1563 .str(),
1565 }
1566 }
1567 if (!HaveOptLevel)
1568 return make_error<StringError>(
1569 "missing optimization level for fatlto-pre-link pipeline",
1571 return Result;
1572}
1573
1574} // namespace
1575
1576/// Tests whether registered callbacks will accept a given pass name.
1577///
1578/// When parsing a pipeline text, the type of the outermost pipeline may be
1579/// omitted, in which case the type is automatically determined from the first
1580/// pass name in the text. This may be a name that is handled through one of the
1581/// callbacks. We check this through the oridinary parsing callbacks by setting
1582/// up a dummy PassManager in order to not force the client to also handle this
1583/// type of query.
1584template <typename PassManagerT, typename CallbacksT>
1585static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1586 if (!Callbacks.empty()) {
1587 PassManagerT DummyPM;
1588 for (auto &CB : Callbacks)
1589 if (CB(Name, DummyPM, {}))
1590 return true;
1591 }
1592 return false;
1593}
1594
1595template <typename CallbacksT>
1596static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1597 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1598
1599 // Explicitly handle pass manager names.
1600 if (Name == "module")
1601 return true;
1602 if (Name == "cgscc")
1603 return true;
1604 if (NameNoBracket == "function")
1605 return true;
1606 if (Name == "coro-cond")
1607 return true;
1608
1609#define MODULE_PASS(NAME, CREATE_PASS) \
1610 if (Name == NAME) \
1611 return true;
1612#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1613 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1614 return true;
1615#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1616 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1617 return true;
1618#include "PassRegistry.def"
1619
1620 return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1621}
1622
1623template <typename CallbacksT>
1624static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1625 // Explicitly handle pass manager names.
1626 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1627 if (Name == "cgscc")
1628 return true;
1629 if (NameNoBracket == "function")
1630 return true;
1631
1632 // Explicitly handle custom-parsed pass names.
1634 return true;
1635
1636#define CGSCC_PASS(NAME, CREATE_PASS) \
1637 if (Name == NAME) \
1638 return true;
1639#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1640 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1641 return true;
1642#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1643 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1644 return true;
1645#include "PassRegistry.def"
1646
1647 return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1648}
1649
1650template <typename CallbacksT>
1651static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1652 // Explicitly handle pass manager names.
1653 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1654 if (NameNoBracket == "function")
1655 return true;
1656 if (Name == "loop" || Name == "loop-mssa" || Name == "machine-function")
1657 return true;
1658
1659#define FUNCTION_PASS(NAME, CREATE_PASS) \
1660 if (Name == NAME) \
1661 return true;
1662#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1663 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1664 return true;
1665#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1666 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1667 return true;
1668#include "PassRegistry.def"
1669
1670 return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1671}
1672
1673template <typename CallbacksT>
1674static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1675 // Explicitly handle pass manager names.
1676 if (Name == "machine-function")
1677 return true;
1678
1679#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1680 if (Name == NAME) \
1681 return true;
1682#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1683 PARAMS) \
1684 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1685 return true;
1686
1687#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1688 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1689 return true;
1690
1691#include "llvm/Passes/MachinePassRegistry.def"
1692
1693 return callbacksAcceptPassName<MachineFunctionPassManager>(Name, Callbacks);
1694}
1695
1696template <typename CallbacksT>
1697static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
1698 bool &UseMemorySSA) {
1699 UseMemorySSA = false;
1700
1702 UseMemorySSA = true;
1703 return true;
1704 }
1705
1706#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1707 if (Name == NAME) \
1708 return true;
1709#include "PassRegistry.def"
1710
1711 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1712}
1713
1714template <typename CallbacksT>
1715static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
1716 bool &UseMemorySSA) {
1717 UseMemorySSA = false;
1718
1720 UseMemorySSA = true;
1721 return true;
1722 }
1723
1724#define LOOP_PASS(NAME, CREATE_PASS) \
1725 if (Name == NAME) \
1726 return true;
1727#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1728 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1729 return true;
1730#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1731 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1732 return true;
1733#include "PassRegistry.def"
1734
1735 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1736}
1737
1738std::optional<std::vector<PassBuilder::PipelineElement>>
1739PassBuilder::parsePipelineText(StringRef Text) {
1740 std::vector<PipelineElement> ResultPipeline;
1741
1742 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1743 &ResultPipeline};
1744 for (;;) {
1745 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1746 size_t Pos = Text.find_first_of(",()");
1747 Pipeline.push_back({Text.substr(0, Pos), {}});
1748
1749 // If we have a single terminating name, we're done.
1750 if (Pos == Text.npos)
1751 break;
1752
1753 char Sep = Text[Pos];
1754 Text = Text.substr(Pos + 1);
1755 if (Sep == ',')
1756 // Just a name ending in a comma, continue.
1757 continue;
1758
1759 if (Sep == '(') {
1760 // Push the inner pipeline onto the stack to continue processing.
1761 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1762 continue;
1763 }
1764
1765 assert(Sep == ')' && "Bogus separator!");
1766 // When handling the close parenthesis, we greedily consume them to avoid
1767 // empty strings in the pipeline.
1768 do {
1769 // If we try to pop the outer pipeline we have unbalanced parentheses.
1770 if (PipelineStack.size() == 1)
1771 return std::nullopt;
1772
1773 PipelineStack.pop_back();
1774 } while (Text.consume_front(")"));
1775
1776 // Check if we've finished parsing.
1777 if (Text.empty())
1778 break;
1779
1780 // Otherwise, the end of an inner pipeline always has to be followed by
1781 // a comma, and then we can continue.
1782 if (!Text.consume_front(","))
1783 return std::nullopt;
1784 }
1785
1786 if (PipelineStack.size() > 1)
1787 // Unbalanced paretheses.
1788 return std::nullopt;
1789
1790 assert(PipelineStack.back() == &ResultPipeline &&
1791 "Wrong pipeline at the bottom of the stack!");
1792 return {std::move(ResultPipeline)};
1793}
1794
1797 // This is consistent with old pass manager invoked via opt, but
1798 // inconsistent with clang. Clang doesn't enable loop vectorization
1799 // but does enable slp vectorization at Oz.
1800 PTO.LoopVectorization = L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1801 PTO.SLPVectorization = L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1802}
1803
1804Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1805 const PipelineElement &E) {
1806 auto &Name = E.Name;
1807 auto &InnerPipeline = E.InnerPipeline;
1808
1809 // First handle complex passes like the pass managers which carry pipelines.
1810 if (!InnerPipeline.empty()) {
1811 if (Name == "module") {
1812 ModulePassManager NestedMPM;
1813 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1814 return Err;
1815 MPM.addPass(std::move(NestedMPM));
1816 return Error::success();
1817 }
1818 if (Name == "coro-cond") {
1819 ModulePassManager NestedMPM;
1820 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1821 return Err;
1822 MPM.addPass(CoroConditionalWrapper(std::move(NestedMPM)));
1823 return Error::success();
1824 }
1825 if (Name == "cgscc") {
1826 CGSCCPassManager CGPM;
1827 if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1828 return Err;
1830 return Error::success();
1831 }
1832 if (auto Params = parseFunctionPipelineName(Name)) {
1833 if (Params->second)
1834 return make_error<StringError>(
1835 "cannot have a no-rerun module to function adaptor",
1838 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1839 return Err;
1840 MPM.addPass(
1841 createModuleToFunctionPassAdaptor(std::move(FPM), Params->first));
1842 return Error::success();
1843 }
1844
1845 for (auto &C : ModulePipelineParsingCallbacks)
1846 if (C(Name, MPM, InnerPipeline))
1847 return Error::success();
1848
1849 // Normal passes can't have pipelines.
1850 return make_error<StringError>(
1851 formatv("invalid use of '{}' pass as module pipeline", Name).str(),
1853 ;
1854 }
1855
1856 // Finally expand the basic registered passes from the .inc file.
1857#define MODULE_PASS(NAME, CREATE_PASS) \
1858 if (Name == NAME) { \
1859 MPM.addPass(CREATE_PASS); \
1860 return Error::success(); \
1861 }
1862#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1863 if (checkParametrizedPassName(Name, NAME)) { \
1864 auto Params = parsePassParameters(PARSER, Name, NAME); \
1865 if (!Params) \
1866 return Params.takeError(); \
1867 MPM.addPass(CREATE_PASS(Params.get())); \
1868 return Error::success(); \
1869 }
1870#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1871 if (Name == "require<" NAME ">") { \
1872 MPM.addPass( \
1873 RequireAnalysisPass< \
1874 std::remove_reference_t<decltype(CREATE_PASS)>, Module>()); \
1875 return Error::success(); \
1876 } \
1877 if (Name == "invalidate<" NAME ">") { \
1878 MPM.addPass(InvalidateAnalysisPass< \
1879 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1880 return Error::success(); \
1881 }
1882#define CGSCC_PASS(NAME, CREATE_PASS) \
1883 if (Name == NAME) { \
1884 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1885 return Error::success(); \
1886 }
1887#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1888 if (checkParametrizedPassName(Name, NAME)) { \
1889 auto Params = parsePassParameters(PARSER, Name, NAME); \
1890 if (!Params) \
1891 return Params.takeError(); \
1892 MPM.addPass( \
1893 createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1894 return Error::success(); \
1895 }
1896#define FUNCTION_PASS(NAME, CREATE_PASS) \
1897 if (Name == NAME) { \
1898 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1899 return Error::success(); \
1900 }
1901#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1902 if (checkParametrizedPassName(Name, NAME)) { \
1903 auto Params = parsePassParameters(PARSER, Name, NAME); \
1904 if (!Params) \
1905 return Params.takeError(); \
1906 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1907 return Error::success(); \
1908 }
1909#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1910 if (Name == NAME) { \
1911 MPM.addPass(createModuleToFunctionPassAdaptor( \
1912 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1913 return Error::success(); \
1914 }
1915#define LOOP_PASS(NAME, CREATE_PASS) \
1916 if (Name == NAME) { \
1917 MPM.addPass(createModuleToFunctionPassAdaptor( \
1918 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1919 return Error::success(); \
1920 }
1921#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1922 if (checkParametrizedPassName(Name, NAME)) { \
1923 auto Params = parsePassParameters(PARSER, Name, NAME); \
1924 if (!Params) \
1925 return Params.takeError(); \
1926 MPM.addPass( \
1927 createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1928 CREATE_PASS(Params.get()), false, false))); \
1929 return Error::success(); \
1930 }
1931#include "PassRegistry.def"
1932
1933 for (auto &C : ModulePipelineParsingCallbacks)
1934 if (C(Name, MPM, InnerPipeline))
1935 return Error::success();
1936 return make_error<StringError>(
1937 formatv("unknown module pass '{}'", Name).str(),
1939}
1940
1941Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1942 const PipelineElement &E) {
1943 auto &Name = E.Name;
1944 auto &InnerPipeline = E.InnerPipeline;
1945
1946 // First handle complex passes like the pass managers which carry pipelines.
1947 if (!InnerPipeline.empty()) {
1948 if (Name == "cgscc") {
1949 CGSCCPassManager NestedCGPM;
1950 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1951 return Err;
1952 // Add the nested pass manager with the appropriate adaptor.
1953 CGPM.addPass(std::move(NestedCGPM));
1954 return Error::success();
1955 }
1956 if (auto Params = parseFunctionPipelineName(Name)) {
1958 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1959 return Err;
1960 // Add the nested pass manager with the appropriate adaptor.
1962 std::move(FPM), Params->first, Params->second));
1963 return Error::success();
1964 }
1965 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1966 CGSCCPassManager NestedCGPM;
1967 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1968 return Err;
1969 CGPM.addPass(
1970 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1971 return Error::success();
1972 }
1973
1974 for (auto &C : CGSCCPipelineParsingCallbacks)
1975 if (C(Name, CGPM, InnerPipeline))
1976 return Error::success();
1977
1978 // Normal passes can't have pipelines.
1979 return make_error<StringError>(
1980 formatv("invalid use of '{}' pass as cgscc pipeline", Name).str(),
1982 }
1983
1984// Now expand the basic registered passes from the .inc file.
1985#define CGSCC_PASS(NAME, CREATE_PASS) \
1986 if (Name == NAME) { \
1987 CGPM.addPass(CREATE_PASS); \
1988 return Error::success(); \
1989 }
1990#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1991 if (checkParametrizedPassName(Name, NAME)) { \
1992 auto Params = parsePassParameters(PARSER, Name, NAME); \
1993 if (!Params) \
1994 return Params.takeError(); \
1995 CGPM.addPass(CREATE_PASS(Params.get())); \
1996 return Error::success(); \
1997 }
1998#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1999 if (Name == "require<" NAME ">") { \
2000 CGPM.addPass(RequireAnalysisPass< \
2001 std::remove_reference_t<decltype(CREATE_PASS)>, \
2002 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
2003 CGSCCUpdateResult &>()); \
2004 return Error::success(); \
2005 } \
2006 if (Name == "invalidate<" NAME ">") { \
2007 CGPM.addPass(InvalidateAnalysisPass< \
2008 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2009 return Error::success(); \
2010 }
2011#define FUNCTION_PASS(NAME, CREATE_PASS) \
2012 if (Name == NAME) { \
2013 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
2014 return Error::success(); \
2015 }
2016#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2017 if (checkParametrizedPassName(Name, NAME)) { \
2018 auto Params = parsePassParameters(PARSER, Name, NAME); \
2019 if (!Params) \
2020 return Params.takeError(); \
2021 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
2022 return Error::success(); \
2023 }
2024#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2025 if (Name == NAME) { \
2026 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
2027 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
2028 return Error::success(); \
2029 }
2030#define LOOP_PASS(NAME, CREATE_PASS) \
2031 if (Name == NAME) { \
2032 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
2033 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
2034 return Error::success(); \
2035 }
2036#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2037 if (checkParametrizedPassName(Name, NAME)) { \
2038 auto Params = parsePassParameters(PARSER, Name, NAME); \
2039 if (!Params) \
2040 return Params.takeError(); \
2041 CGPM.addPass( \
2042 createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
2043 CREATE_PASS(Params.get()), false, false))); \
2044 return Error::success(); \
2045 }
2046#include "PassRegistry.def"
2047
2048 for (auto &C : CGSCCPipelineParsingCallbacks)
2049 if (C(Name, CGPM, InnerPipeline))
2050 return Error::success();
2051 return make_error<StringError>(formatv("unknown cgscc pass '{}'", Name).str(),
2053}
2054
2055Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
2056 const PipelineElement &E) {
2057 auto &Name = E.Name;
2058 auto &InnerPipeline = E.InnerPipeline;
2059
2060 // First handle complex passes like the pass managers which carry pipelines.
2061 if (!InnerPipeline.empty()) {
2062 if (Name == "function") {
2063 FunctionPassManager NestedFPM;
2064 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
2065 return Err;
2066 // Add the nested pass manager with the appropriate adaptor.
2067 FPM.addPass(std::move(NestedFPM));
2068 return Error::success();
2069 }
2070 if (Name == "loop" || Name == "loop-mssa") {
2071 LoopPassManager LPM;
2072 if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
2073 return Err;
2074 // Add the nested pass manager with the appropriate adaptor.
2075 bool UseMemorySSA = (Name == "loop-mssa");
2076 bool UseBFI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
2077 return Pipeline.Name.contains("simple-loop-unswitch");
2078 });
2079 bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
2080 return Pipeline.Name == "loop-predication";
2081 });
2082 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
2083 UseBFI, UseBPI));
2084 return Error::success();
2085 }
2086 if (Name == "machine-function") {
2088 if (auto Err = parseMachinePassPipeline(MFPM, InnerPipeline))
2089 return Err;
2091 return Error::success();
2092 }
2093
2094 for (auto &C : FunctionPipelineParsingCallbacks)
2095 if (C(Name, FPM, InnerPipeline))
2096 return Error::success();
2097
2098 // Normal passes can't have pipelines.
2099 return make_error<StringError>(
2100 formatv("invalid use of '{}' pass as function pipeline", Name).str(),
2102 }
2103
2104// Now expand the basic registered passes from the .inc file.
2105#define FUNCTION_PASS(NAME, CREATE_PASS) \
2106 if (Name == NAME) { \
2107 FPM.addPass(CREATE_PASS); \
2108 return Error::success(); \
2109 }
2110#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2111 if (checkParametrizedPassName(Name, NAME)) { \
2112 auto Params = parsePassParameters(PARSER, Name, NAME); \
2113 if (!Params) \
2114 return Params.takeError(); \
2115 FPM.addPass(CREATE_PASS(Params.get())); \
2116 return Error::success(); \
2117 }
2118#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
2119 if (Name == "require<" NAME ">") { \
2120 FPM.addPass( \
2121 RequireAnalysisPass< \
2122 std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
2123 return Error::success(); \
2124 } \
2125 if (Name == "invalidate<" NAME ">") { \
2126 FPM.addPass(InvalidateAnalysisPass< \
2127 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2128 return Error::success(); \
2129 }
2130// FIXME: UseMemorySSA is set to false. Maybe we could do things like:
2131// bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
2132// "guard-widening");
2133// The risk is that it may become obsolete if we're not careful.
2134#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2135 if (Name == NAME) { \
2136 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
2137 return Error::success(); \
2138 }
2139#define LOOP_PASS(NAME, CREATE_PASS) \
2140 if (Name == NAME) { \
2141 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
2142 return Error::success(); \
2143 }
2144#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2145 if (checkParametrizedPassName(Name, NAME)) { \
2146 auto Params = parsePassParameters(PARSER, Name, NAME); \
2147 if (!Params) \
2148 return Params.takeError(); \
2149 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
2150 false, false)); \
2151 return Error::success(); \
2152 }
2153#include "PassRegistry.def"
2154
2155 for (auto &C : FunctionPipelineParsingCallbacks)
2156 if (C(Name, FPM, InnerPipeline))
2157 return Error::success();
2158 return make_error<StringError>(
2159 formatv("unknown function pass '{}'", Name).str(),
2161}
2162
2163Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
2164 const PipelineElement &E) {
2165 StringRef Name = E.Name;
2166 auto &InnerPipeline = E.InnerPipeline;
2167
2168 // First handle complex passes like the pass managers which carry pipelines.
2169 if (!InnerPipeline.empty()) {
2170 if (Name == "loop") {
2171 LoopPassManager NestedLPM;
2172 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
2173 return Err;
2174 // Add the nested pass manager with the appropriate adaptor.
2175 LPM.addPass(std::move(NestedLPM));
2176 return Error::success();
2177 }
2178
2179 for (auto &C : LoopPipelineParsingCallbacks)
2180 if (C(Name, LPM, InnerPipeline))
2181 return Error::success();
2182
2183 // Normal passes can't have pipelines.
2184 return make_error<StringError>(
2185 formatv("invalid use of '{}' pass as loop pipeline", Name).str(),
2187 }
2188
2189// Now expand the basic registered passes from the .inc file.
2190#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2191 if (Name == NAME) { \
2192 LPM.addPass(CREATE_PASS); \
2193 return Error::success(); \
2194 }
2195#define LOOP_PASS(NAME, CREATE_PASS) \
2196 if (Name == NAME) { \
2197 LPM.addPass(CREATE_PASS); \
2198 return Error::success(); \
2199 }
2200#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2201 if (checkParametrizedPassName(Name, NAME)) { \
2202 auto Params = parsePassParameters(PARSER, Name, NAME); \
2203 if (!Params) \
2204 return Params.takeError(); \
2205 LPM.addPass(CREATE_PASS(Params.get())); \
2206 return Error::success(); \
2207 }
2208#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
2209 if (Name == "require<" NAME ">") { \
2210 LPM.addPass(RequireAnalysisPass< \
2211 std::remove_reference_t<decltype(CREATE_PASS)>, Loop, \
2212 LoopAnalysisManager, LoopStandardAnalysisResults &, \
2213 LPMUpdater &>()); \
2214 return Error::success(); \
2215 } \
2216 if (Name == "invalidate<" NAME ">") { \
2217 LPM.addPass(InvalidateAnalysisPass< \
2218 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2219 return Error::success(); \
2220 }
2221#include "PassRegistry.def"
2222
2223 for (auto &C : LoopPipelineParsingCallbacks)
2224 if (C(Name, LPM, InnerPipeline))
2225 return Error::success();
2226 return make_error<StringError>(formatv("unknown loop pass '{}'", Name).str(),
2228}
2229
2230Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
2231 const PipelineElement &E) {
2232 StringRef Name = E.Name;
2233 // Handle any nested pass managers.
2234 if (!E.InnerPipeline.empty()) {
2235 if (E.Name == "machine-function") {
2237 if (auto Err = parseMachinePassPipeline(NestedPM, E.InnerPipeline))
2238 return Err;
2239 MFPM.addPass(std::move(NestedPM));
2240 return Error::success();
2241 }
2242 return make_error<StringError>("invalid pipeline",
2244 }
2245
2246#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) \
2247 if (Name == NAME) { \
2248 MFPM.addPass(CREATE_PASS); \
2249 return Error::success(); \
2250 }
2251#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
2252 if (Name == NAME) { \
2253 MFPM.addPass(CREATE_PASS); \
2254 return Error::success(); \
2255 }
2256#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
2257 PARAMS) \
2258 if (checkParametrizedPassName(Name, NAME)) { \
2259 auto Params = parsePassParameters(PARSER, Name, NAME); \
2260 if (!Params) \
2261 return Params.takeError(); \
2262 MFPM.addPass(CREATE_PASS(Params.get())); \
2263 return Error::success(); \
2264 }
2265#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
2266 if (Name == "require<" NAME ">") { \
2267 MFPM.addPass( \
2268 RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>, \
2269 MachineFunction>()); \
2270 return Error::success(); \
2271 } \
2272 if (Name == "invalidate<" NAME ">") { \
2273 MFPM.addPass(InvalidateAnalysisPass< \
2274 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2275 return Error::success(); \
2276 }
2277#include "llvm/Passes/MachinePassRegistry.def"
2278
2279 for (auto &C : MachineFunctionPipelineParsingCallbacks)
2280 if (C(Name, MFPM, E.InnerPipeline))
2281 return Error::success();
2282 return make_error<StringError>(
2283 formatv("unknown machine pass '{}'", Name).str(),
2285}
2286
2287bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
2288#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2289 if (Name == NAME) { \
2290 AA.registerModuleAnalysis< \
2291 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
2292 return true; \
2293 }
2294#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2295 if (Name == NAME) { \
2296 AA.registerFunctionAnalysis< \
2297 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
2298 return true; \
2299 }
2300#include "PassRegistry.def"
2301
2302 for (auto &C : AAParsingCallbacks)
2303 if (C(Name, AA))
2304 return true;
2305 return false;
2306}
2307
2308Error PassBuilder::parseMachinePassPipeline(
2310 for (const auto &Element : Pipeline) {
2311 if (auto Err = parseMachinePass(MFPM, Element))
2312 return Err;
2313 }
2314 return Error::success();
2315}
2316
2317Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2318 ArrayRef<PipelineElement> Pipeline) {
2319 for (const auto &Element : Pipeline) {
2320 if (auto Err = parseLoopPass(LPM, Element))
2321 return Err;
2322 }
2323 return Error::success();
2324}
2325
2326Error PassBuilder::parseFunctionPassPipeline(
2328 for (const auto &Element : Pipeline) {
2329 if (auto Err = parseFunctionPass(FPM, Element))
2330 return Err;
2331 }
2332 return Error::success();
2333}
2334
2335Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2336 ArrayRef<PipelineElement> Pipeline) {
2337 for (const auto &Element : Pipeline) {
2338 if (auto Err = parseCGSCCPass(CGPM, Element))
2339 return Err;
2340 }
2341 return Error::success();
2342}
2343
2356 if (MFAM) {
2358 [&] { return MachineFunctionAnalysisManagerModuleProxy(*MFAM); });
2360 [&] { return MachineFunctionAnalysisManagerFunctionProxy(*MFAM); });
2361 MFAM->registerPass(
2363 MFAM->registerPass(
2365 }
2366}
2367
2368Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2369 ArrayRef<PipelineElement> Pipeline) {
2370 for (const auto &Element : Pipeline) {
2371 if (auto Err = parseModulePass(MPM, Element))
2372 return Err;
2373 }
2374 return Error::success();
2375}
2376
2377// Primary pass pipeline description parsing routine for a \c ModulePassManager
2378// FIXME: Should this routine accept a TargetMachine or require the caller to
2379// pre-populate the analysis managers with target-specific stuff?
2381 StringRef PipelineText) {
2382 auto Pipeline = parsePipelineText(PipelineText);
2383 if (!Pipeline || Pipeline->empty())
2384 return make_error<StringError>(
2385 formatv("invalid pipeline '{}'", PipelineText).str(),
2387
2388 // If the first name isn't at the module layer, wrap the pipeline up
2389 // automatically.
2390 StringRef FirstName = Pipeline->front().Name;
2391
2392 if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2393 bool UseMemorySSA;
2394 if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2395 Pipeline = {{"cgscc", std::move(*Pipeline)}};
2396 } else if (isFunctionPassName(FirstName,
2397 FunctionPipelineParsingCallbacks)) {
2398 Pipeline = {{"function", std::move(*Pipeline)}};
2399 } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
2400 UseMemorySSA)) {
2401 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2402 std::move(*Pipeline)}}}};
2403 } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
2404 UseMemorySSA)) {
2405 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2406 std::move(*Pipeline)}}}};
2407 } else if (isMachineFunctionPassName(
2408 FirstName, MachineFunctionPipelineParsingCallbacks)) {
2409 Pipeline = {{"function", {{"machine-function", std::move(*Pipeline)}}}};
2410 } else {
2411 for (auto &C : TopLevelPipelineParsingCallbacks)
2412 if (C(MPM, *Pipeline))
2413 return Error::success();
2414
2415 // Unknown pass or pipeline name!
2416 auto &InnerPipeline = Pipeline->front().InnerPipeline;
2417 return make_error<StringError>(
2418 formatv("unknown {} name '{}'",
2419 (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2420 .str(),
2422 }
2423 }
2424
2425 if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
2426 return Err;
2427 return Error::success();
2428}
2429
2430// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2432 StringRef PipelineText) {
2433 auto Pipeline = parsePipelineText(PipelineText);
2434 if (!Pipeline || Pipeline->empty())
2435 return make_error<StringError>(
2436 formatv("invalid pipeline '{}'", PipelineText).str(),
2438
2439 StringRef FirstName = Pipeline->front().Name;
2440 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2441 return make_error<StringError>(
2442 formatv("unknown cgscc pass '{}' in pipeline '{}'", FirstName,
2443 PipelineText)
2444 .str(),
2446
2447 if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
2448 return Err;
2449 return Error::success();
2450}
2451
2452// Primary pass pipeline description parsing routine for a \c
2453// FunctionPassManager
2455 StringRef PipelineText) {
2456 auto Pipeline = parsePipelineText(PipelineText);
2457 if (!Pipeline || Pipeline->empty())
2458 return make_error<StringError>(
2459 formatv("invalid pipeline '{}'", PipelineText).str(),
2461
2462 StringRef FirstName = Pipeline->front().Name;
2463 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2464 return make_error<StringError>(
2465 formatv("unknown function pass '{}' in pipeline '{}'", FirstName,
2466 PipelineText)
2467 .str(),
2469
2470 if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
2471 return Err;
2472 return Error::success();
2473}
2474
2475// Primary pass pipeline description parsing routine for a \c LoopPassManager
2477 StringRef PipelineText) {
2478 auto Pipeline = parsePipelineText(PipelineText);
2479 if (!Pipeline || Pipeline->empty())
2480 return make_error<StringError>(
2481 formatv("invalid pipeline '{}'", PipelineText).str(),
2483
2484 if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
2485 return Err;
2486
2487 return Error::success();
2488}
2489
2491 StringRef PipelineText) {
2492 auto Pipeline = parsePipelineText(PipelineText);
2493 if (!Pipeline || Pipeline->empty())
2494 return make_error<StringError>(
2495 formatv("invalid machine pass pipeline '{}'", PipelineText).str(),
2497
2498 if (auto Err = parseMachinePassPipeline(MFPM, *Pipeline))
2499 return Err;
2500
2501 return Error::success();
2502}
2503
2505 // If the pipeline just consists of the word 'default' just replace the AA
2506 // manager with our default one.
2507 if (PipelineText == "default") {
2509 return Error::success();
2510 }
2511
2512 while (!PipelineText.empty()) {
2514 std::tie(Name, PipelineText) = PipelineText.split(',');
2515 if (!parseAAPassName(AA, Name))
2516 return make_error<StringError>(
2517 formatv("unknown alias analysis name '{}'", Name).str(),
2519 }
2520
2521 return Error::success();
2522}
2523
2524std::optional<RegAllocFilterFunc>
2526 if (FilterName == "all")
2527 return nullptr;
2528 for (auto &C : RegClassFilterParsingCallbacks)
2529 if (auto F = C(FilterName))
2530 return F;
2531 return std::nullopt;
2532}
2533
2535 OS << " " << PassName << "\n";
2536}
2538 raw_ostream &OS) {
2539 OS << " " << PassName << "<" << Params << ">\n";
2540}
2541
2543 // TODO: print pass descriptions when they are available
2544
2545 OS << "Module passes:\n";
2546#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2547#include "PassRegistry.def"
2548
2549 OS << "Module passes with params:\n";
2550#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2551 printPassName(NAME, PARAMS, OS);
2552#include "PassRegistry.def"
2553
2554 OS << "Module analyses:\n";
2555#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2556#include "PassRegistry.def"
2557
2558 OS << "Module alias analyses:\n";
2559#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2560#include "PassRegistry.def"
2561
2562 OS << "CGSCC passes:\n";
2563#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2564#include "PassRegistry.def"
2565
2566 OS << "CGSCC passes with params:\n";
2567#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2568 printPassName(NAME, PARAMS, OS);
2569#include "PassRegistry.def"
2570
2571 OS << "CGSCC analyses:\n";
2572#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2573#include "PassRegistry.def"
2574
2575 OS << "Function passes:\n";
2576#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2577#include "PassRegistry.def"
2578
2579 OS << "Function passes with params:\n";
2580#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2581 printPassName(NAME, PARAMS, OS);
2582#include "PassRegistry.def"
2583
2584 OS << "Function analyses:\n";
2585#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2586#include "PassRegistry.def"
2587
2588 OS << "Function alias analyses:\n";
2589#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2590#include "PassRegistry.def"
2591
2592 OS << "LoopNest passes:\n";
2593#define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2594#include "PassRegistry.def"
2595
2596 OS << "Loop passes:\n";
2597#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2598#include "PassRegistry.def"
2599
2600 OS << "Loop passes with params:\n";
2601#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2602 printPassName(NAME, PARAMS, OS);
2603#include "PassRegistry.def"
2604
2605 OS << "Loop analyses:\n";
2606#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2607#include "PassRegistry.def"
2608
2609 OS << "Machine module passes (WIP):\n";
2610#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2611#include "llvm/Passes/MachinePassRegistry.def"
2612
2613 OS << "Machine function passes (WIP):\n";
2614#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2615#include "llvm/Passes/MachinePassRegistry.def"
2616
2617 OS << "Machine function analyses (WIP):\n";
2618#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2619#include "llvm/Passes/MachinePassRegistry.def"
2620}
2621
2623 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
2624 &C) {
2625 TopLevelPipelineParsingCallbacks.push_back(C);
2626}
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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...
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
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.
Provides analysis for querying information about KnownBits during GISel passes.
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 the IR2Vec vocabulary analysis(IR2VecVocabAnalysis), the core ir2vec::Embedder inte...
This file defines passes to print out IR in various granularities.
This header defines various interfaces for pass management in LLVM.
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.
static LVOptions Options
Definition: LVOptions.cpp:25
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:87
Machine IR instance of the generic uniformity analysis.
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 isLoopNestPassName(StringRef Name, CallbacksT &Callbacks, bool &UseMemorySSA)
static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks)
static Expected< OptimizationLevel > parseOptLevelParam(StringRef S)
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 void setupOptionsForPipelineAlias(PipelineTuningOptions &PTO, OptimizationLevel L)
This file implements the PredicateInfo analysis, which creates an Extended SSA form for operations us...
This pass is required to take advantage of the interprocedural register allocation infrastructure.
This file implements relative lookup table converter that converts lookup tables to relative lookup t...
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:1540
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1562
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:255
bool registerPass(PassBuilderT &&PassBuilder)
Register an analysis pass with the manager.
Definition: PassManager.h:473
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:62
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:233
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
static LLVM_ABI 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:585
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
Definition: PassManager.h:585
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelType.h:43
An RAII based helper class to modify MachineFunctionProperties when running pass.
Properties which a MachineFunction may have at a given point in time.
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:67
static LLVM_ABI const OptimizationLevel O3
Optimize for fast execution as much as possible.
static LLVM_ABI const OptimizationLevel Oz
A very specialized mode that will optimize for code size at any and all costs.
static LLVM_ABI const OptimizationLevel O0
Disable as many optimizations as possible.
static LLVM_ABI const OptimizationLevel Os
Similar to O2 but tries to optimize for small code size instead of fast execution without triggering ...
static LLVM_ABI const OptimizationLevel O2
Optimize for fast execution as much as possible without triggering significant incremental compile ti...
static LLVM_ABI const OptimizationLevel O1
Optimize quickly without destroying debuggability.
This class provides access to building LLVM's passes.
Definition: PassBuilder.h:110
LLVM_ABI void printPassNames(raw_ostream &OS)
Print pass names.
static bool checkParametrizedPassName(StringRef Name, StringRef PassName)
Definition: PassBuilder.h:677
LLVM_ABI AAManager buildDefaultAAPipeline()
Build the default AAManager with the default alias analysis pipeline registered.
LLVM_ABI Error parseAAPipeline(AAManager &AA, StringRef PipelineText)
Parse a textual alias analysis pipeline into the provided AA manager.
LLVM_ABI PassBuilder(TargetMachine *TM=nullptr, PipelineTuningOptions PTO=PipelineTuningOptions(), std::optional< PGOOptions > PGOOpt=std::nullopt, PassInstrumentationCallbacks *PIC=nullptr)
LLVM_ABI void registerLoopAnalyses(LoopAnalysisManager &LAM)
Registers all available loop analysis passes.
LLVM_ABI std::optional< RegAllocFilterFunc > parseRegAllocFilter(StringRef RegAllocFilterName)
Parse RegAllocFilterName to get RegAllocFilterFunc.
LLVM_ABI void crossRegisterProxies(LoopAnalysisManager &LAM, FunctionAnalysisManager &FAM, CGSCCAnalysisManager &CGAM, ModuleAnalysisManager &MAM, MachineFunctionAnalysisManager *MFAM=nullptr)
Cross register the analysis managers through their proxies.
LLVM_ABI Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText)
Parse a textual pass pipeline description into a ModulePassManager.
LLVM_ABI void registerModuleAnalyses(ModuleAnalysisManager &MAM)
Registers all available module analysis passes.
LLVM_ABI void registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM)
Registers all available CGSCC analysis passes.
static LLVM_ABI Expected< bool > parseSinglePassOption(StringRef Params, StringRef OptionName, StringRef PassName)
Handle passes only accept one bool-valued parameter.
LLVM_ABI void registerMachineFunctionAnalyses(MachineFunctionAnalysisManager &MFAM)
Registers all available machine function analysis passes.
LLVM_ABI void registerParseTopLevelPipelineCallback(const std::function< bool(ModulePassManager &, ArrayRef< PipelineElement >)> &C)
Register a callback for a top-level pipeline entry.
LLVM_ABI void registerFunctionAnalyses(FunctionAnalysisManager &FAM)
Registers all available function analysis passes.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
Definition: PassManager.h:196
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:720
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition: Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:118
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:480
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:233
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:269
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
char front() const
front - Get the first character in the string.
Definition: StringRef.h:157
bool consume_front(StringRef Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition: StringRef.h:645
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:43
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:68
R Default(T Value)
Definition: StringSwitch.h:177
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:83
This function has undefined behavior.
self_iterator getIterator()
Definition: ilist_node.h:134
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
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:877
DevirtSCCRepeatedPass createDevirtSCCRepeatedPass(CGSCCPassT &&Pass, int MaxIterations)
A function to deduce a function pass type and wrap it in the templated adaptor.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Definition: PassManager.h:826
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:1751
ModuleToPostOrderCGSCCPassAdaptor createModuleToPostOrderCGSCCPassAdaptor(CGSCCPassT &&Pass)
A function to deduce a function pass type and wrap it in the templated adaptor.
LLVM_ABI cl::opt< bool > PrintPipelinePasses
Common option used by multiple tools to print pipeline passes.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
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:672
FunctionToMachineFunctionPassAdaptor createFunctionToMachineFunctionPassAdaptor(MachineFunctionPassT &&Pass)
InnerAnalysisManagerProxy< MachineFunctionAnalysisManager, Function > MachineFunctionAnalysisManagerFunctionProxy
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.
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.
@ Detailed
Hash with opcode only.
@ CallTargetIgnored
Hash with opcode and operands.
@ Enable
Enable colors.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:29
A set of parameters to control various transforms performed by GVN pass.
Definition: GVN.h:76
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:70
static StringRef name()
Gets the name of the pass we are mixed into.
Definition: PassManager.h:72
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...