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