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 Param) {
1497 if (Param.empty())
1498 return CodeGenOptLevel::None;
1499
1500 // Parse a CodeGenOptLevel, e.g. "O1", "O2", "O3".
1501 auto [Prefix, Digit] = Param.split('O');
1502
1503 uint8_t N;
1504 if (!Prefix.empty() || Digit.getAsInteger(10, N))
1505 return createStringError("invalid expand-fp pass parameter '%s'",
1506 Param.str().c_str());
1507
1508 std::optional<CodeGenOptLevel> Level = CodeGenOpt::getLevel(N);
1509 if (!Level.has_value())
1510 return createStringError(
1511 "invalid optimization level for expand-fp pass: %s",
1512 Digit.str().c_str());
1513
1514 return *Level;
1515}
1516
1518parseRegAllocGreedyFilterFunc(PassBuilder &PB, StringRef Params) {
1519 if (Params.empty() || Params == "all")
1520 return RAGreedyPass::Options();
1521
1522 std::optional<RegAllocFilterFunc> Filter = PB.parseRegAllocFilter(Params);
1523 if (Filter)
1524 return RAGreedyPass::Options{*Filter, Params};
1525
1527 formatv("invalid regallocgreedy register filter '{}'", Params).str(),
1529}
1530
1531Expected<bool> parseMachineSinkingPassOptions(StringRef Params) {
1532 return PassBuilder::parseSinglePassOption(Params, "enable-sink-fold",
1533 "MachineSinkingPass");
1534}
1535
1536Expected<bool> parseMachineBlockPlacementPassOptions(StringRef Params) {
1537 bool AllowTailMerge = true;
1538 if (!Params.empty()) {
1539 AllowTailMerge = !Params.consume_front("no-");
1540 if (Params != "tail-merge")
1542 formatv("invalid MachineBlockPlacementPass parameter '{}'", Params)
1543 .str(),
1545 }
1546 return AllowTailMerge;
1547}
1548
1549Expected<bool> parseVirtRegRewriterPassOptions(StringRef Params) {
1550 bool ClearVirtRegs = true;
1551 if (!Params.empty()) {
1552 ClearVirtRegs = !Params.consume_front("no-");
1553 if (Params != "clear-vregs")
1555 formatv("invalid VirtRegRewriter pass parameter '{}'", Params).str(),
1557 }
1558 return ClearVirtRegs;
1559}
1560
1561struct FatLTOOptions {
1562 OptimizationLevel OptLevel;
1563 bool ThinLTO = false;
1564 bool EmitSummary = false;
1565};
1566
1567Expected<FatLTOOptions> parseFatLTOOptions(StringRef Params) {
1568 FatLTOOptions Result;
1569 bool HaveOptLevel = false;
1570 while (!Params.empty()) {
1571 StringRef ParamName;
1572 std::tie(ParamName, Params) = Params.split(';');
1573
1574 if (ParamName == "thinlto") {
1575 Result.ThinLTO = true;
1576 } else if (ParamName == "emit-summary") {
1577 Result.EmitSummary = true;
1578 } else if (std::optional<OptimizationLevel> OptLevel =
1579 parseOptLevel(ParamName)) {
1580 Result.OptLevel = *OptLevel;
1581 HaveOptLevel = true;
1582 } else {
1584 formatv("invalid fatlto-pre-link pass parameter '{}'", ParamName)
1585 .str(),
1587 }
1588 }
1589 if (!HaveOptLevel)
1591 "missing optimization level for fatlto-pre-link pipeline",
1593 return Result;
1594}
1595
1596} // namespace
1597
1598/// Tests whether registered callbacks will accept a given pass name.
1599///
1600/// When parsing a pipeline text, the type of the outermost pipeline may be
1601/// omitted, in which case the type is automatically determined from the first
1602/// pass name in the text. This may be a name that is handled through one of the
1603/// callbacks. We check this through the oridinary parsing callbacks by setting
1604/// up a dummy PassManager in order to not force the client to also handle this
1605/// type of query.
1606template <typename PassManagerT, typename CallbacksT>
1607static bool callbacksAcceptPassName(StringRef Name, CallbacksT &Callbacks) {
1608 if (!Callbacks.empty()) {
1609 PassManagerT DummyPM;
1610 for (auto &CB : Callbacks)
1611 if (CB(Name, DummyPM, {}))
1612 return true;
1613 }
1614 return false;
1615}
1616
1617template <typename CallbacksT>
1618static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
1619 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1620
1621 // Explicitly handle pass manager names.
1622 if (Name == "module")
1623 return true;
1624 if (Name == "cgscc")
1625 return true;
1626 if (NameNoBracket == "function")
1627 return true;
1628 if (Name == "coro-cond")
1629 return true;
1630
1631#define MODULE_PASS(NAME, CREATE_PASS) \
1632 if (Name == NAME) \
1633 return true;
1634#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1635 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1636 return true;
1637#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1638 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1639 return true;
1640#include "PassRegistry.def"
1641
1642 return callbacksAcceptPassName<ModulePassManager>(Name, Callbacks);
1643}
1644
1645template <typename CallbacksT>
1646static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
1647 // Explicitly handle pass manager names.
1648 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1649 if (Name == "cgscc")
1650 return true;
1651 if (NameNoBracket == "function")
1652 return true;
1653
1654 // Explicitly handle custom-parsed pass names.
1655 if (parseDevirtPassName(Name))
1656 return true;
1657
1658#define CGSCC_PASS(NAME, CREATE_PASS) \
1659 if (Name == NAME) \
1660 return true;
1661#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1662 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1663 return true;
1664#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
1665 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1666 return true;
1667#include "PassRegistry.def"
1668
1669 return callbacksAcceptPassName<CGSCCPassManager>(Name, Callbacks);
1670}
1671
1672template <typename CallbacksT>
1673static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1674 // Explicitly handle pass manager names.
1675 StringRef NameNoBracket = Name.take_until([](char C) { return C == '<'; });
1676 if (NameNoBracket == "function")
1677 return true;
1678 if (Name == "loop" || Name == "loop-mssa" || Name == "machine-function")
1679 return true;
1680
1681#define FUNCTION_PASS(NAME, CREATE_PASS) \
1682 if (Name == NAME) \
1683 return true;
1684#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1685 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1686 return true;
1687#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1688 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1689 return true;
1690#include "PassRegistry.def"
1691
1692 return callbacksAcceptPassName<FunctionPassManager>(Name, Callbacks);
1693}
1694
1695template <typename CallbacksT>
1696static bool isMachineFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
1697 // Explicitly handle pass manager names.
1698 if (Name == "machine-function")
1699 return true;
1700
1701#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
1702 if (Name == NAME) \
1703 return true;
1704#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
1705 PARAMS) \
1706 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1707 return true;
1708
1709#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
1710 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1711 return true;
1712
1713#include "llvm/Passes/MachinePassRegistry.def"
1714
1716}
1717
1718template <typename CallbacksT>
1719static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
1720 bool &UseMemorySSA) {
1721 UseMemorySSA = false;
1722
1723 if (PassBuilder::checkParametrizedPassName(Name, "lnicm")) {
1724 UseMemorySSA = true;
1725 return true;
1726 }
1727
1728#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1729 if (Name == NAME) \
1730 return true;
1731#include "PassRegistry.def"
1732
1733 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1734}
1735
1736template <typename CallbacksT>
1737static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
1738 bool &UseMemorySSA) {
1739 UseMemorySSA = false;
1740
1741 if (PassBuilder::checkParametrizedPassName(Name, "licm")) {
1742 UseMemorySSA = true;
1743 return true;
1744 }
1745
1746#define LOOP_PASS(NAME, CREATE_PASS) \
1747 if (Name == NAME) \
1748 return true;
1749#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1750 if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
1751 return true;
1752#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
1753 if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
1754 return true;
1755#include "PassRegistry.def"
1756
1757 return callbacksAcceptPassName<LoopPassManager>(Name, Callbacks);
1758}
1759
1760std::optional<std::vector<PassBuilder::PipelineElement>>
1761PassBuilder::parsePipelineText(StringRef Text) {
1762 std::vector<PipelineElement> ResultPipeline;
1763
1764 SmallVector<std::vector<PipelineElement> *, 4> PipelineStack = {
1765 &ResultPipeline};
1766 for (;;) {
1767 std::vector<PipelineElement> &Pipeline = *PipelineStack.back();
1768 size_t Pos = Text.find_first_of(",()");
1769 Pipeline.push_back({Text.substr(0, Pos), {}});
1770
1771 // If we have a single terminating name, we're done.
1772 if (Pos == Text.npos)
1773 break;
1774
1775 char Sep = Text[Pos];
1776 Text = Text.substr(Pos + 1);
1777 if (Sep == ',')
1778 // Just a name ending in a comma, continue.
1779 continue;
1780
1781 if (Sep == '(') {
1782 // Push the inner pipeline onto the stack to continue processing.
1783 PipelineStack.push_back(&Pipeline.back().InnerPipeline);
1784 continue;
1785 }
1786
1787 assert(Sep == ')' && "Bogus separator!");
1788 // When handling the close parenthesis, we greedily consume them to avoid
1789 // empty strings in the pipeline.
1790 do {
1791 // If we try to pop the outer pipeline we have unbalanced parentheses.
1792 if (PipelineStack.size() == 1)
1793 return std::nullopt;
1794
1795 PipelineStack.pop_back();
1796 } while (Text.consume_front(")"));
1797
1798 // Check if we've finished parsing.
1799 if (Text.empty())
1800 break;
1801
1802 // Otherwise, the end of an inner pipeline always has to be followed by
1803 // a comma, and then we can continue.
1804 if (!Text.consume_front(","))
1805 return std::nullopt;
1806 }
1807
1808 if (PipelineStack.size() > 1)
1809 // Unbalanced paretheses.
1810 return std::nullopt;
1811
1812 assert(PipelineStack.back() == &ResultPipeline &&
1813 "Wrong pipeline at the bottom of the stack!");
1814 return {std::move(ResultPipeline)};
1815}
1816
1819 // This is consistent with old pass manager invoked via opt, but
1820 // inconsistent with clang. Clang doesn't enable loop vectorization
1821 // but does enable slp vectorization at Oz.
1822 PTO.LoopVectorization = L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1823 PTO.SLPVectorization = L.getSpeedupLevel() > 1 && L != OptimizationLevel::Oz;
1824}
1825
1826Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1827 const PipelineElement &E) {
1828 auto &Name = E.Name;
1829 auto &InnerPipeline = E.InnerPipeline;
1830
1831 // First handle complex passes like the pass managers which carry pipelines.
1832 if (!InnerPipeline.empty()) {
1833 if (Name == "module") {
1834 ModulePassManager NestedMPM;
1835 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1836 return Err;
1837 MPM.addPass(std::move(NestedMPM));
1838 return Error::success();
1839 }
1840 if (Name == "coro-cond") {
1841 ModulePassManager NestedMPM;
1842 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline))
1843 return Err;
1844 MPM.addPass(CoroConditionalWrapper(std::move(NestedMPM)));
1845 return Error::success();
1846 }
1847 if (Name == "cgscc") {
1848 CGSCCPassManager CGPM;
1849 if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline))
1850 return Err;
1852 return Error::success();
1853 }
1854 if (auto Params = parseFunctionPipelineName(Name)) {
1855 if (Params->second)
1857 "cannot have a no-rerun module to function adaptor",
1860 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1861 return Err;
1862 MPM.addPass(
1863 createModuleToFunctionPassAdaptor(std::move(FPM), Params->first));
1864 return Error::success();
1865 }
1866
1867 for (auto &C : ModulePipelineParsingCallbacks)
1868 if (C(Name, MPM, InnerPipeline))
1869 return Error::success();
1870
1871 // Normal passes can't have pipelines.
1873 formatv("invalid use of '{}' pass as module pipeline", Name).str(),
1875 ;
1876 }
1877
1878 // Finally expand the basic registered passes from the .inc file.
1879#define MODULE_PASS(NAME, CREATE_PASS) \
1880 if (Name == NAME) { \
1881 MPM.addPass(CREATE_PASS); \
1882 return Error::success(); \
1883 }
1884#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1885 if (checkParametrizedPassName(Name, NAME)) { \
1886 auto Params = parsePassParameters(PARSER, Name, NAME); \
1887 if (!Params) \
1888 return Params.takeError(); \
1889 MPM.addPass(CREATE_PASS(Params.get())); \
1890 return Error::success(); \
1891 }
1892#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
1893 if (Name == "require<" NAME ">") { \
1894 MPM.addPass( \
1895 RequireAnalysisPass< \
1896 std::remove_reference_t<decltype(CREATE_PASS)>, Module>()); \
1897 return Error::success(); \
1898 } \
1899 if (Name == "invalidate<" NAME ">") { \
1900 MPM.addPass(InvalidateAnalysisPass< \
1901 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
1902 return Error::success(); \
1903 }
1904#define CGSCC_PASS(NAME, CREATE_PASS) \
1905 if (Name == NAME) { \
1906 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \
1907 return Error::success(); \
1908 }
1909#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1910 if (checkParametrizedPassName(Name, NAME)) { \
1911 auto Params = parsePassParameters(PARSER, Name, NAME); \
1912 if (!Params) \
1913 return Params.takeError(); \
1914 MPM.addPass( \
1915 createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \
1916 return Error::success(); \
1917 }
1918#define FUNCTION_PASS(NAME, CREATE_PASS) \
1919 if (Name == NAME) { \
1920 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \
1921 return Error::success(); \
1922 }
1923#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1924 if (checkParametrizedPassName(Name, NAME)) { \
1925 auto Params = parsePassParameters(PARSER, Name, NAME); \
1926 if (!Params) \
1927 return Params.takeError(); \
1928 MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
1929 return Error::success(); \
1930 }
1931#define LOOPNEST_PASS(NAME, CREATE_PASS) \
1932 if (Name == NAME) { \
1933 MPM.addPass(createModuleToFunctionPassAdaptor( \
1934 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1935 return Error::success(); \
1936 }
1937#define LOOP_PASS(NAME, CREATE_PASS) \
1938 if (Name == NAME) { \
1939 MPM.addPass(createModuleToFunctionPassAdaptor( \
1940 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
1941 return Error::success(); \
1942 }
1943#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
1944 if (checkParametrizedPassName(Name, NAME)) { \
1945 auto Params = parsePassParameters(PARSER, Name, NAME); \
1946 if (!Params) \
1947 return Params.takeError(); \
1948 MPM.addPass( \
1949 createModuleToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
1950 CREATE_PASS(Params.get()), false, false))); \
1951 return Error::success(); \
1952 }
1953#include "PassRegistry.def"
1954
1955 for (auto &C : ModulePipelineParsingCallbacks)
1956 if (C(Name, MPM, InnerPipeline))
1957 return Error::success();
1959 formatv("unknown module pass '{}'", Name).str(),
1961}
1962
1963Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1964 const PipelineElement &E) {
1965 auto &Name = E.Name;
1966 auto &InnerPipeline = E.InnerPipeline;
1967
1968 // First handle complex passes like the pass managers which carry pipelines.
1969 if (!InnerPipeline.empty()) {
1970 if (Name == "cgscc") {
1971 CGSCCPassManager NestedCGPM;
1972 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1973 return Err;
1974 // Add the nested pass manager with the appropriate adaptor.
1975 CGPM.addPass(std::move(NestedCGPM));
1976 return Error::success();
1977 }
1978 if (auto Params = parseFunctionPipelineName(Name)) {
1980 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline))
1981 return Err;
1982 // Add the nested pass manager with the appropriate adaptor.
1984 std::move(FPM), Params->first, Params->second));
1985 return Error::success();
1986 }
1987 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
1988 CGSCCPassManager NestedCGPM;
1989 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline))
1990 return Err;
1991 CGPM.addPass(
1992 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1993 return Error::success();
1994 }
1995
1996 for (auto &C : CGSCCPipelineParsingCallbacks)
1997 if (C(Name, CGPM, InnerPipeline))
1998 return Error::success();
1999
2000 // Normal passes can't have pipelines.
2002 formatv("invalid use of '{}' pass as cgscc pipeline", Name).str(),
2004 }
2005
2006// Now expand the basic registered passes from the .inc file.
2007#define CGSCC_PASS(NAME, CREATE_PASS) \
2008 if (Name == NAME) { \
2009 CGPM.addPass(CREATE_PASS); \
2010 return Error::success(); \
2011 }
2012#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2013 if (checkParametrizedPassName(Name, NAME)) { \
2014 auto Params = parsePassParameters(PARSER, Name, NAME); \
2015 if (!Params) \
2016 return Params.takeError(); \
2017 CGPM.addPass(CREATE_PASS(Params.get())); \
2018 return Error::success(); \
2019 }
2020#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
2021 if (Name == "require<" NAME ">") { \
2022 CGPM.addPass(RequireAnalysisPass< \
2023 std::remove_reference_t<decltype(CREATE_PASS)>, \
2024 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
2025 CGSCCUpdateResult &>()); \
2026 return Error::success(); \
2027 } \
2028 if (Name == "invalidate<" NAME ">") { \
2029 CGPM.addPass(InvalidateAnalysisPass< \
2030 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2031 return Error::success(); \
2032 }
2033#define FUNCTION_PASS(NAME, CREATE_PASS) \
2034 if (Name == NAME) { \
2035 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \
2036 return Error::success(); \
2037 }
2038#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2039 if (checkParametrizedPassName(Name, NAME)) { \
2040 auto Params = parsePassParameters(PARSER, Name, NAME); \
2041 if (!Params) \
2042 return Params.takeError(); \
2043 CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS(Params.get()))); \
2044 return Error::success(); \
2045 }
2046#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2047 if (Name == NAME) { \
2048 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
2049 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
2050 return Error::success(); \
2051 }
2052#define LOOP_PASS(NAME, CREATE_PASS) \
2053 if (Name == NAME) { \
2054 CGPM.addPass(createCGSCCToFunctionPassAdaptor( \
2055 createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \
2056 return Error::success(); \
2057 }
2058#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2059 if (checkParametrizedPassName(Name, NAME)) { \
2060 auto Params = parsePassParameters(PARSER, Name, NAME); \
2061 if (!Params) \
2062 return Params.takeError(); \
2063 CGPM.addPass( \
2064 createCGSCCToFunctionPassAdaptor(createFunctionToLoopPassAdaptor( \
2065 CREATE_PASS(Params.get()), false, false))); \
2066 return Error::success(); \
2067 }
2068#include "PassRegistry.def"
2069
2070 for (auto &C : CGSCCPipelineParsingCallbacks)
2071 if (C(Name, CGPM, InnerPipeline))
2072 return Error::success();
2073 return make_error<StringError>(formatv("unknown cgscc pass '{}'", Name).str(),
2075}
2076
2077Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
2078 const PipelineElement &E) {
2079 auto &Name = E.Name;
2080 auto &InnerPipeline = E.InnerPipeline;
2081
2082 // First handle complex passes like the pass managers which carry pipelines.
2083 if (!InnerPipeline.empty()) {
2084 if (Name == "function") {
2085 FunctionPassManager NestedFPM;
2086 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline))
2087 return Err;
2088 // Add the nested pass manager with the appropriate adaptor.
2089 FPM.addPass(std::move(NestedFPM));
2090 return Error::success();
2091 }
2092 if (Name == "loop" || Name == "loop-mssa") {
2093 LoopPassManager LPM;
2094 if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline))
2095 return Err;
2096 // Add the nested pass manager with the appropriate adaptor.
2097 bool UseMemorySSA = (Name == "loop-mssa");
2098 bool UseBFI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
2099 return Pipeline.Name.contains("simple-loop-unswitch");
2100 });
2101 bool UseBPI = llvm::any_of(InnerPipeline, [](auto Pipeline) {
2102 return Pipeline.Name == "loop-predication";
2103 });
2104 FPM.addPass(createFunctionToLoopPassAdaptor(std::move(LPM), UseMemorySSA,
2105 UseBFI, UseBPI));
2106 return Error::success();
2107 }
2108 if (Name == "machine-function") {
2110 if (auto Err = parseMachinePassPipeline(MFPM, InnerPipeline))
2111 return Err;
2113 return Error::success();
2114 }
2115
2116 for (auto &C : FunctionPipelineParsingCallbacks)
2117 if (C(Name, FPM, InnerPipeline))
2118 return Error::success();
2119
2120 // Normal passes can't have pipelines.
2122 formatv("invalid use of '{}' pass as function pipeline", Name).str(),
2124 }
2125
2126// Now expand the basic registered passes from the .inc file.
2127#define FUNCTION_PASS(NAME, CREATE_PASS) \
2128 if (Name == NAME) { \
2129 FPM.addPass(CREATE_PASS); \
2130 return Error::success(); \
2131 }
2132#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2133 if (checkParametrizedPassName(Name, NAME)) { \
2134 auto Params = parsePassParameters(PARSER, Name, NAME); \
2135 if (!Params) \
2136 return Params.takeError(); \
2137 FPM.addPass(CREATE_PASS(Params.get())); \
2138 return Error::success(); \
2139 }
2140#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
2141 if (Name == "require<" NAME ">") { \
2142 FPM.addPass( \
2143 RequireAnalysisPass< \
2144 std::remove_reference_t<decltype(CREATE_PASS)>, Function>()); \
2145 return Error::success(); \
2146 } \
2147 if (Name == "invalidate<" NAME ">") { \
2148 FPM.addPass(InvalidateAnalysisPass< \
2149 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2150 return Error::success(); \
2151 }
2152// FIXME: UseMemorySSA is set to false. Maybe we could do things like:
2153// bool UseMemorySSA = !("canon-freeze" || "loop-predication" ||
2154// "guard-widening");
2155// The risk is that it may become obsolete if we're not careful.
2156#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2157 if (Name == NAME) { \
2158 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
2159 return Error::success(); \
2160 }
2161#define LOOP_PASS(NAME, CREATE_PASS) \
2162 if (Name == NAME) { \
2163 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \
2164 return Error::success(); \
2165 }
2166#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2167 if (checkParametrizedPassName(Name, NAME)) { \
2168 auto Params = parsePassParameters(PARSER, Name, NAME); \
2169 if (!Params) \
2170 return Params.takeError(); \
2171 FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS(Params.get()), \
2172 false, false)); \
2173 return Error::success(); \
2174 }
2175#include "PassRegistry.def"
2176
2177 for (auto &C : FunctionPipelineParsingCallbacks)
2178 if (C(Name, FPM, InnerPipeline))
2179 return Error::success();
2181 formatv("unknown function pass '{}'", Name).str(),
2183}
2184
2185Error PassBuilder::parseLoopPass(LoopPassManager &LPM,
2186 const PipelineElement &E) {
2187 StringRef Name = E.Name;
2188 auto &InnerPipeline = E.InnerPipeline;
2189
2190 // First handle complex passes like the pass managers which carry pipelines.
2191 if (!InnerPipeline.empty()) {
2192 if (Name == "loop") {
2193 LoopPassManager NestedLPM;
2194 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline))
2195 return Err;
2196 // Add the nested pass manager with the appropriate adaptor.
2197 LPM.addPass(std::move(NestedLPM));
2198 return Error::success();
2199 }
2200
2201 for (auto &C : LoopPipelineParsingCallbacks)
2202 if (C(Name, LPM, InnerPipeline))
2203 return Error::success();
2204
2205 // Normal passes can't have pipelines.
2207 formatv("invalid use of '{}' pass as loop pipeline", Name).str(),
2209 }
2210
2211// Now expand the basic registered passes from the .inc file.
2212#define LOOPNEST_PASS(NAME, CREATE_PASS) \
2213 if (Name == NAME) { \
2214 LPM.addPass(CREATE_PASS); \
2215 return Error::success(); \
2216 }
2217#define LOOP_PASS(NAME, CREATE_PASS) \
2218 if (Name == NAME) { \
2219 LPM.addPass(CREATE_PASS); \
2220 return Error::success(); \
2221 }
2222#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2223 if (checkParametrizedPassName(Name, NAME)) { \
2224 auto Params = parsePassParameters(PARSER, Name, NAME); \
2225 if (!Params) \
2226 return Params.takeError(); \
2227 LPM.addPass(CREATE_PASS(Params.get())); \
2228 return Error::success(); \
2229 }
2230#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
2231 if (Name == "require<" NAME ">") { \
2232 LPM.addPass(RequireAnalysisPass< \
2233 std::remove_reference_t<decltype(CREATE_PASS)>, Loop, \
2234 LoopAnalysisManager, LoopStandardAnalysisResults &, \
2235 LPMUpdater &>()); \
2236 return Error::success(); \
2237 } \
2238 if (Name == "invalidate<" NAME ">") { \
2239 LPM.addPass(InvalidateAnalysisPass< \
2240 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2241 return Error::success(); \
2242 }
2243#include "PassRegistry.def"
2244
2245 for (auto &C : LoopPipelineParsingCallbacks)
2246 if (C(Name, LPM, InnerPipeline))
2247 return Error::success();
2248 return make_error<StringError>(formatv("unknown loop pass '{}'", Name).str(),
2250}
2251
2252Error PassBuilder::parseMachinePass(MachineFunctionPassManager &MFPM,
2253 const PipelineElement &E) {
2254 StringRef Name = E.Name;
2255 // Handle any nested pass managers.
2256 if (!E.InnerPipeline.empty()) {
2257 if (E.Name == "machine-function") {
2259 if (auto Err = parseMachinePassPipeline(NestedPM, E.InnerPipeline))
2260 return Err;
2261 MFPM.addPass(std::move(NestedPM));
2262 return Error::success();
2263 }
2264 return make_error<StringError>("invalid pipeline",
2266 }
2267
2268#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) \
2269 if (Name == NAME) { \
2270 MFPM.addPass(CREATE_PASS); \
2271 return Error::success(); \
2272 }
2273#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) \
2274 if (Name == NAME) { \
2275 MFPM.addPass(CREATE_PASS); \
2276 return Error::success(); \
2277 }
2278#define MACHINE_FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, \
2279 PARAMS) \
2280 if (checkParametrizedPassName(Name, NAME)) { \
2281 auto Params = parsePassParameters(PARSER, Name, NAME); \
2282 if (!Params) \
2283 return Params.takeError(); \
2284 MFPM.addPass(CREATE_PASS(Params.get())); \
2285 return Error::success(); \
2286 }
2287#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
2288 if (Name == "require<" NAME ">") { \
2289 MFPM.addPass( \
2290 RequireAnalysisPass<std::remove_reference_t<decltype(CREATE_PASS)>, \
2291 MachineFunction>()); \
2292 return Error::success(); \
2293 } \
2294 if (Name == "invalidate<" NAME ">") { \
2295 MFPM.addPass(InvalidateAnalysisPass< \
2296 std::remove_reference_t<decltype(CREATE_PASS)>>()); \
2297 return Error::success(); \
2298 }
2299#include "llvm/Passes/MachinePassRegistry.def"
2300
2301 for (auto &C : MachineFunctionPipelineParsingCallbacks)
2302 if (C(Name, MFPM, E.InnerPipeline))
2303 return Error::success();
2305 formatv("unknown machine pass '{}'", Name).str(),
2307}
2308
2309bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
2310#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2311 if (Name == NAME) { \
2312 AA.registerModuleAnalysis< \
2313 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
2314 return true; \
2315 }
2316#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \
2317 if (Name == NAME) { \
2318 AA.registerFunctionAnalysis< \
2319 std::remove_reference_t<decltype(CREATE_PASS)>>(); \
2320 return true; \
2321 }
2322#include "PassRegistry.def"
2323
2324 for (auto &C : AAParsingCallbacks)
2325 if (C(Name, AA))
2326 return true;
2327 return false;
2328}
2329
2330Error PassBuilder::parseMachinePassPipeline(
2332 for (const auto &Element : Pipeline) {
2333 if (auto Err = parseMachinePass(MFPM, Element))
2334 return Err;
2335 }
2336 return Error::success();
2337}
2338
2339Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
2340 ArrayRef<PipelineElement> Pipeline) {
2341 for (const auto &Element : Pipeline) {
2342 if (auto Err = parseLoopPass(LPM, Element))
2343 return Err;
2344 }
2345 return Error::success();
2346}
2347
2348Error PassBuilder::parseFunctionPassPipeline(
2350 for (const auto &Element : Pipeline) {
2351 if (auto Err = parseFunctionPass(FPM, Element))
2352 return Err;
2353 }
2354 return Error::success();
2355}
2356
2357Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
2358 ArrayRef<PipelineElement> Pipeline) {
2359 for (const auto &Element : Pipeline) {
2360 if (auto Err = parseCGSCCPass(CGPM, Element))
2361 return Err;
2362 }
2363 return Error::success();
2364}
2365
2371 MAM.registerPass([&] { return FunctionAnalysisManagerModuleProxy(FAM); });
2372 MAM.registerPass([&] { return CGSCCAnalysisManagerModuleProxy(CGAM); });
2373 CGAM.registerPass([&] { return ModuleAnalysisManagerCGSCCProxy(MAM); });
2374 FAM.registerPass([&] { return CGSCCAnalysisManagerFunctionProxy(CGAM); });
2375 FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
2376 FAM.registerPass([&] { return LoopAnalysisManagerFunctionProxy(LAM); });
2377 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
2378 if (MFAM) {
2379 MAM.registerPass(
2380 [&] { return MachineFunctionAnalysisManagerModuleProxy(*MFAM); });
2381 FAM.registerPass(
2382 [&] { return MachineFunctionAnalysisManagerFunctionProxy(*MFAM); });
2383 MFAM->registerPass(
2385 MFAM->registerPass(
2387 }
2388}
2389
2390Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
2391 ArrayRef<PipelineElement> Pipeline) {
2392 for (const auto &Element : Pipeline) {
2393 if (auto Err = parseModulePass(MPM, Element))
2394 return Err;
2395 }
2396 return Error::success();
2397}
2398
2399// Primary pass pipeline description parsing routine for a \c ModulePassManager
2400// FIXME: Should this routine accept a TargetMachine or require the caller to
2401// pre-populate the analysis managers with target-specific stuff?
2403 StringRef PipelineText) {
2404 auto Pipeline = parsePipelineText(PipelineText);
2405 if (!Pipeline || Pipeline->empty())
2407 formatv("invalid pipeline '{}'", PipelineText).str(),
2409
2410 // If the first name isn't at the module layer, wrap the pipeline up
2411 // automatically.
2412 StringRef FirstName = Pipeline->front().Name;
2413
2414 if (!isModulePassName(FirstName, ModulePipelineParsingCallbacks)) {
2415 bool UseMemorySSA;
2416 if (isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks)) {
2417 Pipeline = {{"cgscc", std::move(*Pipeline)}};
2418 } else if (isFunctionPassName(FirstName,
2419 FunctionPipelineParsingCallbacks)) {
2420 Pipeline = {{"function", std::move(*Pipeline)}};
2421 } else if (isLoopNestPassName(FirstName, LoopPipelineParsingCallbacks,
2422 UseMemorySSA)) {
2423 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2424 std::move(*Pipeline)}}}};
2425 } else if (isLoopPassName(FirstName, LoopPipelineParsingCallbacks,
2426 UseMemorySSA)) {
2427 Pipeline = {{"function", {{UseMemorySSA ? "loop-mssa" : "loop",
2428 std::move(*Pipeline)}}}};
2429 } else if (isMachineFunctionPassName(
2430 FirstName, MachineFunctionPipelineParsingCallbacks)) {
2431 Pipeline = {{"function", {{"machine-function", std::move(*Pipeline)}}}};
2432 } else {
2433 for (auto &C : TopLevelPipelineParsingCallbacks)
2434 if (C(MPM, *Pipeline))
2435 return Error::success();
2436
2437 // Unknown pass or pipeline name!
2438 auto &InnerPipeline = Pipeline->front().InnerPipeline;
2440 formatv("unknown {} name '{}'",
2441 (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
2442 .str(),
2444 }
2445 }
2446
2447 if (auto Err = parseModulePassPipeline(MPM, *Pipeline))
2448 return Err;
2449 return Error::success();
2450}
2451
2452// Primary pass pipeline description parsing routine for a \c CGSCCPassManager
2454 StringRef PipelineText) {
2455 auto Pipeline = parsePipelineText(PipelineText);
2456 if (!Pipeline || Pipeline->empty())
2458 formatv("invalid pipeline '{}'", PipelineText).str(),
2460
2461 StringRef FirstName = Pipeline->front().Name;
2462 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
2464 formatv("unknown cgscc pass '{}' in pipeline '{}'", FirstName,
2465 PipelineText)
2466 .str(),
2468
2469 if (auto Err = parseCGSCCPassPipeline(CGPM, *Pipeline))
2470 return Err;
2471 return Error::success();
2472}
2473
2474// Primary pass pipeline description parsing routine for a \c
2475// FunctionPassManager
2477 StringRef PipelineText) {
2478 auto Pipeline = parsePipelineText(PipelineText);
2479 if (!Pipeline || Pipeline->empty())
2481 formatv("invalid pipeline '{}'", PipelineText).str(),
2483
2484 StringRef FirstName = Pipeline->front().Name;
2485 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
2487 formatv("unknown function pass '{}' in pipeline '{}'", FirstName,
2488 PipelineText)
2489 .str(),
2491
2492 if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline))
2493 return Err;
2494 return Error::success();
2495}
2496
2497// Primary pass pipeline description parsing routine for a \c LoopPassManager
2499 StringRef PipelineText) {
2500 auto Pipeline = parsePipelineText(PipelineText);
2501 if (!Pipeline || Pipeline->empty())
2503 formatv("invalid pipeline '{}'", PipelineText).str(),
2505
2506 if (auto Err = parseLoopPassPipeline(CGPM, *Pipeline))
2507 return Err;
2508
2509 return Error::success();
2510}
2511
2513 StringRef PipelineText) {
2514 auto Pipeline = parsePipelineText(PipelineText);
2515 if (!Pipeline || Pipeline->empty())
2517 formatv("invalid machine pass pipeline '{}'", PipelineText).str(),
2519
2520 if (auto Err = parseMachinePassPipeline(MFPM, *Pipeline))
2521 return Err;
2522
2523 return Error::success();
2524}
2525
2527 // If the pipeline just consists of the word 'default' just replace the AA
2528 // manager with our default one.
2529 if (PipelineText == "default") {
2531 return Error::success();
2532 }
2533
2534 while (!PipelineText.empty()) {
2535 StringRef Name;
2536 std::tie(Name, PipelineText) = PipelineText.split(',');
2537 if (!parseAAPassName(AA, Name))
2539 formatv("unknown alias analysis name '{}'", Name).str(),
2541 }
2542
2543 return Error::success();
2544}
2545
2546std::optional<RegAllocFilterFunc>
2548 if (FilterName == "all")
2549 return nullptr;
2550 for (auto &C : RegClassFilterParsingCallbacks)
2551 if (auto F = C(FilterName))
2552 return F;
2553 return std::nullopt;
2554}
2555
2557 OS << " " << PassName << "\n";
2558}
2560 raw_ostream &OS) {
2561 OS << " " << PassName << "<" << Params << ">\n";
2562}
2563
2565 // TODO: print pass descriptions when they are available
2566
2567 OS << "Module passes:\n";
2568#define MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2569#include "PassRegistry.def"
2570
2571 OS << "Module passes with params:\n";
2572#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2573 printPassName(NAME, PARAMS, OS);
2574#include "PassRegistry.def"
2575
2576 OS << "Module analyses:\n";
2577#define MODULE_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2578#include "PassRegistry.def"
2579
2580 OS << "Module alias analyses:\n";
2581#define MODULE_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2582#include "PassRegistry.def"
2583
2584 OS << "CGSCC passes:\n";
2585#define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2586#include "PassRegistry.def"
2587
2588 OS << "CGSCC passes with params:\n";
2589#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2590 printPassName(NAME, PARAMS, OS);
2591#include "PassRegistry.def"
2592
2593 OS << "CGSCC analyses:\n";
2594#define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2595#include "PassRegistry.def"
2596
2597 OS << "Function passes:\n";
2598#define FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2599#include "PassRegistry.def"
2600
2601 OS << "Function passes with params:\n";
2602#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2603 printPassName(NAME, PARAMS, OS);
2604#include "PassRegistry.def"
2605
2606 OS << "Function analyses:\n";
2607#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2608#include "PassRegistry.def"
2609
2610 OS << "Function alias analyses:\n";
2611#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2612#include "PassRegistry.def"
2613
2614 OS << "LoopNest passes:\n";
2615#define LOOPNEST_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2616#include "PassRegistry.def"
2617
2618 OS << "Loop passes:\n";
2619#define LOOP_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2620#include "PassRegistry.def"
2621
2622 OS << "Loop passes with params:\n";
2623#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
2624 printPassName(NAME, PARAMS, OS);
2625#include "PassRegistry.def"
2626
2627 OS << "Loop analyses:\n";
2628#define LOOP_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2629#include "PassRegistry.def"
2630
2631 OS << "Machine module passes (WIP):\n";
2632#define MACHINE_MODULE_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2633#include "llvm/Passes/MachinePassRegistry.def"
2634
2635 OS << "Machine function passes (WIP):\n";
2636#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS) printPassName(NAME, OS);
2637#include "llvm/Passes/MachinePassRegistry.def"
2638
2639 OS << "Machine function analyses (WIP):\n";
2640#define MACHINE_FUNCTION_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS);
2641#include "llvm/Passes/MachinePassRegistry.def"
2642}
2643
2645 const std::function<bool(ModulePassManager &, ArrayRef<PipelineElement>)>
2646 &C) {
2647 TopLevelPipelineParsingCallbacks.push_back(C);
2648}
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