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