llvm.org GIT mirror llvm / bce0a9a
[NewPM] teach -passes= to emit meaningful error messages Summary: All the PassBuilder::parse interfaces now return descriptive StringError instead of a plain bool. It allows to make -passes/aa-pipeline parsing errors context-specific and thus less confusing. TODO: ideally we should also make suggestions for misspelled pass names, but that requires some extensions to PassBuilder. Reviewed By: philip.pfaffe, chandlerc Differential Revision: https://reviews.llvm.org/D53246 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344519 91177308-0d34-0410-b5e6-96231b3b80d8 Fedor Sergeev 10 months ago
12 changed file(s) with 414 addition(s) and 286 deletion(s). Raw diff Collapse all Expand all
1818 #include "llvm/ADT/Optional.h"
1919 #include "llvm/Analysis/CGSCCPassManager.h"
2020 #include "llvm/IR/PassManager.h"
21 #include "llvm/Support/Error.h"
2122 #include "llvm/Transforms/Instrumentation.h"
2223 #include "llvm/Transforms/Scalar/LoopPassManager.h"
2324 #include
383384 /// If the sequence of passes aren't all the exact same kind of pass, it will
384385 /// be an error. You cannot mix different levels implicitly, you must
385386 /// explicitly form a pass manager in which to nest passes.
386 bool parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
387 bool VerifyEachPass = true, bool DebugLogging = false);
387 Error parsePassPipeline(ModulePassManager &MPM, StringRef PipelineText,
388 bool VerifyEachPass = true,
389 bool DebugLogging = false);
388390
389391 /// {{@ Parse a textual pass pipeline description into a specific PassManager
390392 ///
393395 /// this is the valid pipeline text:
394396 ///
395397 /// function(lpass)
396 bool parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
397 bool VerifyEachPass = true, bool DebugLogging = false);
398 bool parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
399 bool VerifyEachPass = true, bool DebugLogging = false);
400 bool parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
401 bool VerifyEachPass = true, bool DebugLogging = false);
398 Error parsePassPipeline(CGSCCPassManager &CGPM, StringRef PipelineText,
399 bool VerifyEachPass = true,
400 bool DebugLogging = false);
401 Error parsePassPipeline(FunctionPassManager &FPM, StringRef PipelineText,
402 bool VerifyEachPass = true,
403 bool DebugLogging = false);
404 Error parsePassPipeline(LoopPassManager &LPM, StringRef PipelineText,
405 bool VerifyEachPass = true,
406 bool DebugLogging = false);
402407 /// @}}
403408
404409 /// Parse a textual alias analysis pipeline into the provided AA manager.
416421 /// Returns false if the text cannot be parsed cleanly. The specific state of
417422 /// the \p AA manager is unspecified if such an error is encountered and this
418423 /// returns false.
419 bool parseAAPipeline(AAManager &AA, StringRef PipelineText);
424 Error parseAAPipeline(AAManager &AA, StringRef PipelineText);
420425
421426 /// Register a callback for a default optimizer pipeline extension
422427 /// point
564569 static Optional>
565570 parsePipelineText(StringRef Text);
566571
567 bool parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
572 Error parseModulePass(ModulePassManager &MPM, const PipelineElement &E,
573 bool VerifyEachPass, bool DebugLogging);
574 Error parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
568575 bool VerifyEachPass, bool DebugLogging);
569 bool parseCGSCCPass(CGSCCPassManager &CGPM, const PipelineElement &E,
576 Error parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
577 bool VerifyEachPass, bool DebugLogging);
578 Error parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
570579 bool VerifyEachPass, bool DebugLogging);
571 bool parseFunctionPass(FunctionPassManager &FPM, const PipelineElement &E,
572 bool VerifyEachPass, bool DebugLogging);
573 bool parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
574 bool VerifyEachPass, bool DebugLogging);
575580 bool parseAAPassName(AAManager &AA, StringRef Name);
576581
577 bool parseLoopPassPipeline(LoopPassManager &LPM,
578 ArrayRef Pipeline,
579 bool VerifyEachPass, bool DebugLogging);
580 bool parseFunctionPassPipeline(FunctionPassManager &FPM,
581 ArrayRef Pipeline,
582 bool VerifyEachPass, bool DebugLogging);
583 bool parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
582 Error parseLoopPassPipeline(LoopPassManager &LPM,
584583 ArrayRef Pipeline,
585584 bool VerifyEachPass, bool DebugLogging);
586 bool parseModulePassPipeline(ModulePassManager &MPM,
585 Error parseFunctionPassPipeline(FunctionPassManager &FPM,
586 ArrayRef Pipeline,
587 bool VerifyEachPass, bool DebugLogging);
588 Error parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
587589 ArrayRef Pipeline,
588590 bool VerifyEachPass, bool DebugLogging);
591 Error parseModulePassPipeline(ModulePassManager &MPM,
592 ArrayRef Pipeline,
593 bool VerifyEachPass, bool DebugLogging);
589594
590595 void addPGOInstrPasses(ModulePassManager &MPM, bool DebugLogging,
591596 OptimizationLevel Level, bool RunProfileGen,
161161 AAManager AA;
162162
163163 // Parse a custom AA pipeline if asked to.
164 if (!PB.parseAAPipeline(AA, "default"))
164 if (auto Err = PB.parseAAPipeline(AA, "default"))
165165 report_fatal_error("Error parsing default AA pipeline");
166166
167167 LoopAnalysisManager LAM(Conf.DebugPassManager);
220220
221221 // Parse a custom AA pipeline if asked to.
222222 if (!AAPipelineDesc.empty())
223 if (!PB.parseAAPipeline(AA, AAPipelineDesc))
224 report_fatal_error("unable to parse AA pipeline description: " +
225 AAPipelineDesc);
223 if (auto Err = PB.parseAAPipeline(AA, AAPipelineDesc))
224 report_fatal_error("unable to parse AA pipeline description '" +
225 AAPipelineDesc + "': " + toString(std::move(Err)));
226226
227227 LoopAnalysisManager LAM;
228228 FunctionAnalysisManager FAM;
245245 MPM.addPass(VerifierPass());
246246
247247 // Now, add all the passes we've been requested to.
248 if (!PB.parsePassPipeline(MPM, PipelineDesc))
249 report_fatal_error("unable to parse pass pipeline description: " +
250 PipelineDesc);
248 if (auto Err = PB.parsePassPipeline(MPM, PipelineDesc))
249 report_fatal_error("unable to parse pass pipeline description '" +
250 PipelineDesc + "': " + toString(std::move(Err)));
251251
252252 if (!DisableVerify)
253253 MPM.addPass(VerifierPass());
5757 #include "llvm/IR/PassManager.h"
5858 #include "llvm/IR/Verifier.h"
5959 #include "llvm/Support/Debug.h"
60 #include "llvm/Support/FormatVariadic.h"
6061 #include "llvm/Support/Regex.h"
6162 #include "llvm/Target/TargetMachine.h"
6263 #include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
14011402 return {std::move(ResultPipeline)};
14021403 }
14031404
1404 bool PassBuilder::parseModulePass(ModulePassManager &MPM,
1405 const PipelineElement &E, bool VerifyEachPass,
1406 bool DebugLogging) {
1405 Error PassBuilder::parseModulePass(ModulePassManager &MPM,
1406 const PipelineElement &E,
1407 bool VerifyEachPass, bool DebugLogging) {
14071408 auto &Name = E.Name;
14081409 auto &InnerPipeline = E.InnerPipeline;
14091410
14111412 if (!InnerPipeline.empty()) {
14121413 if (Name == "module") {
14131414 ModulePassManager NestedMPM(DebugLogging);
1414 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1415 DebugLogging))
1416 return false;
1415 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1416 VerifyEachPass, DebugLogging))
1417 return Err;
14171418 MPM.addPass(std::move(NestedMPM));
1418 return true;
1419 return Error::success();
14191420 }
14201421 if (Name == "cgscc") {
14211422 CGSCCPassManager CGPM(DebugLogging);
1422 if (!parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1423 DebugLogging))
1424 return false;
1423 if (auto Err = parseCGSCCPassPipeline(CGPM, InnerPipeline, VerifyEachPass,
1424 DebugLogging))
1425 return Err;
14251426 MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
1426 return true;
1427 return Error::success();
14271428 }
14281429 if (Name == "function") {
14291430 FunctionPassManager FPM(DebugLogging);
1430 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1431 DebugLogging))
1432 return false;
1431 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1432 VerifyEachPass, DebugLogging))
1433 return Err;
14331434 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1434 return true;
1435 return Error::success();
14351436 }
14361437 if (auto Count = parseRepeatPassName(Name)) {
14371438 ModulePassManager NestedMPM(DebugLogging);
1438 if (!parseModulePassPipeline(NestedMPM, InnerPipeline, VerifyEachPass,
1439 DebugLogging))
1440 return false;
1439 if (auto Err = parseModulePassPipeline(NestedMPM, InnerPipeline,
1440 VerifyEachPass, DebugLogging))
1441 return Err;
14411442 MPM.addPass(createRepeatedPass(*Count, std::move(NestedMPM)));
1442 return true;
1443 return Error::success();
14431444 }
14441445
14451446 for (auto &C : ModulePipelineParsingCallbacks)
14461447 if (C(Name, MPM, InnerPipeline))
1447 return true;
1448 return Error::success();
14481449
14491450 // Normal passes can't have pipelines.
1450 return false;
1451 return make_error(
1452 formatv("invalid use of '{0}' pass as module pipeline", Name).str(),
1453 inconvertibleErrorCode());
1454 ;
14511455 }
14521456
14531457 // Manually handle aliases for pre-configured pipeline fragments.
14541458 if (startsWithDefaultPipelineAliasPrefix(Name)) {
14551459 SmallVector Matches;
14561460 if (!DefaultAliasRegex.match(Name, &Matches))
1457 return false;
1461 return make_error(
1462 formatv("unknown default pipeline alias '{0}'", Name).str(),
1463 inconvertibleErrorCode());
1464
14581465 assert(Matches.size() == 3 && "Must capture two matched strings!");
14591466
14601467 OptimizationLevel L = StringSwitch(Matches[2])
14661473 .Case("Oz", Oz);
14671474 if (L == O0)
14681475 // At O0 we do nothing at all!
1469 return true;
1476 return Error::success();
14701477
14711478 if (Matches[1] == "default") {
14721479 MPM.addPass(buildPerModuleDefaultPipeline(L, DebugLogging));
14801487 assert(Matches[1] == "lto" && "Not one of the matched options!");
14811488 MPM.addPass(buildLTODefaultPipeline(L, DebugLogging, nullptr));
14821489 }
1483 return true;
1490 return Error::success();
14841491 }
14851492
14861493 // Finally expand the basic registered passes from the .inc file.
14871494 #define MODULE_PASS(NAME, CREATE_PASS) \
14881495 if (Name == NAME) { \
14891496 MPM.addPass(CREATE_PASS); \
1490 return true; \
1497 return Error::success(); \
14911498 }
14921499 #define MODULE_ANALYSIS(NAME, CREATE_PASS) \
14931500 if (Name == "require<" NAME ">") { \
14941501 MPM.addPass( \
14951502 RequireAnalysisPass< \
14961503 std::remove_reference::type, Module>()); \
1497 return true; \
1504 return Error::success(); \
14981505 } \
14991506 if (Name == "invalidate<" NAME ">") { \
15001507 MPM.addPass(InvalidateAnalysisPass< \
15011508 std::remove_reference::type>()); \
1502 return true; \
1509 return Error::success(); \
15031510 }
15041511 #include "PassRegistry.def"
15051512
15061513 for (auto &C : ModulePipelineParsingCallbacks)
15071514 if (C(Name, MPM, InnerPipeline))
1508 return true;
1509 return false;
1510 }
1511
1512 bool PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1513 const PipelineElement &E, bool VerifyEachPass,
1514 bool DebugLogging) {
1515 return Error::success();
1516 return make_error(
1517 formatv("unknown module pass '{0}'", Name).str(),
1518 inconvertibleErrorCode());
1519 }
1520
1521 Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM,
1522 const PipelineElement &E, bool VerifyEachPass,
1523 bool DebugLogging) {
15151524 auto &Name = E.Name;
15161525 auto &InnerPipeline = E.InnerPipeline;
15171526
15191528 if (!InnerPipeline.empty()) {
15201529 if (Name == "cgscc") {
15211530 CGSCCPassManager NestedCGPM(DebugLogging);
1522 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1523 DebugLogging))
1524 return false;
1531 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1532 VerifyEachPass, DebugLogging))
1533 return Err;
15251534 // Add the nested pass manager with the appropriate adaptor.
15261535 CGPM.addPass(std::move(NestedCGPM));
1527 return true;
1536 return Error::success();
15281537 }
15291538 if (Name == "function") {
15301539 FunctionPassManager FPM(DebugLogging);
1531 if (!parseFunctionPassPipeline(FPM, InnerPipeline, VerifyEachPass,
1532 DebugLogging))
1533 return false;
1540 if (auto Err = parseFunctionPassPipeline(FPM, InnerPipeline,
1541 VerifyEachPass, DebugLogging))
1542 return Err;
15341543 // Add the nested pass manager with the appropriate adaptor.
15351544 CGPM.addPass(createCGSCCToFunctionPassAdaptor(std::move(FPM)));
1536 return true;
1545 return Error::success();
15371546 }
15381547 if (auto Count = parseRepeatPassName(Name)) {
15391548 CGSCCPassManager NestedCGPM(DebugLogging);
1540 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1541 DebugLogging))
1542 return false;
1549 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1550 VerifyEachPass, DebugLogging))
1551 return Err;
15431552 CGPM.addPass(createRepeatedPass(*Count, std::move(NestedCGPM)));
1544 return true;
1553 return Error::success();
15451554 }
15461555 if (auto MaxRepetitions = parseDevirtPassName(Name)) {
15471556 CGSCCPassManager NestedCGPM(DebugLogging);
1548 if (!parseCGSCCPassPipeline(NestedCGPM, InnerPipeline, VerifyEachPass,
1549 DebugLogging))
1550 return false;
1557 if (auto Err = parseCGSCCPassPipeline(NestedCGPM, InnerPipeline,
1558 VerifyEachPass, DebugLogging))
1559 return Err;
15511560 CGPM.addPass(
15521561 createDevirtSCCRepeatedPass(std::move(NestedCGPM), *MaxRepetitions));
1553 return true;
1562 return Error::success();
15541563 }
15551564
15561565 for (auto &C : CGSCCPipelineParsingCallbacks)
15571566 if (C(Name, CGPM, InnerPipeline))
1558 return true;
1567 return Error::success();
15591568
15601569 // Normal passes can't have pipelines.
1561 return false;
1570 return make_error(
1571 formatv("invalid use of '{0}' pass as cgscc pipeline", Name).str(),
1572 inconvertibleErrorCode());
15621573 }
15631574
15641575 // Now expand the basic registered passes from the .inc file.
15651576 #define CGSCC_PASS(NAME, CREATE_PASS) \
15661577 if (Name == NAME) { \
15671578 CGPM.addPass(CREATE_PASS); \
1568 return true; \
1579 return Error::success(); \
15691580 }
15701581 #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
15711582 if (Name == "require<" NAME ">") { \
15731584 std::remove_reference::type, \
15741585 LazyCallGraph::SCC, CGSCCAnalysisManager, LazyCallGraph &, \
15751586 CGSCCUpdateResult &>()); \
1576 return true; \
1587 return Error::success(); \
15771588 } \
15781589 if (Name == "invalidate<" NAME ">") { \
15791590 CGPM.addPass(InvalidateAnalysisPass< \
15801591 std::remove_reference::type>()); \
1581 return true; \
1592 return Error::success(); \
15821593 }
15831594 #include "PassRegistry.def"
15841595
15851596 for (auto &C : CGSCCPipelineParsingCallbacks)
15861597 if (C(Name, CGPM, InnerPipeline))
1587 return true;
1588 return false;
1589 }
1590
1591 bool PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1592 const PipelineElement &E,
1593 bool VerifyEachPass, bool DebugLogging) {
1598 return Error::success();
1599 return make_error(
1600 formatv("unknown cgscc pass '{0}'", Name).str(),
1601 inconvertibleErrorCode());
1602 }
1603
1604 Error PassBuilder::parseFunctionPass(FunctionPassManager &FPM,
1605 const PipelineElement &E,
1606 bool VerifyEachPass, bool DebugLogging) {
15941607 auto &Name = E.Name;
15951608 auto &InnerPipeline = E.InnerPipeline;
15961609
15981611 if (!InnerPipeline.empty()) {
15991612 if (Name == "function") {
16001613 FunctionPassManager NestedFPM(DebugLogging);
1601 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1602 DebugLogging))
1603 return false;
1614 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1615 VerifyEachPass, DebugLogging))
1616 return Err;
16041617 // Add the nested pass manager with the appropriate adaptor.
16051618 FPM.addPass(std::move(NestedFPM));
1606 return true;
1619 return Error::success();
16071620 }
16081621 if (Name == "loop") {
16091622 LoopPassManager LPM(DebugLogging);
1610 if (!parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1611 DebugLogging))
1612 return false;
1623 if (auto Err = parseLoopPassPipeline(LPM, InnerPipeline, VerifyEachPass,
1624 DebugLogging))
1625 return Err;
16131626 // Add the nested pass manager with the appropriate adaptor.
16141627 FPM.addPass(
16151628 createFunctionToLoopPassAdaptor(std::move(LPM), DebugLogging));
1616 return true;
1629 return Error::success();
16171630 }
16181631 if (auto Count = parseRepeatPassName(Name)) {
16191632 FunctionPassManager NestedFPM(DebugLogging);
1620 if (!parseFunctionPassPipeline(NestedFPM, InnerPipeline, VerifyEachPass,
1621 DebugLogging))
1622 return false;
1633 if (auto Err = parseFunctionPassPipeline(NestedFPM, InnerPipeline,
1634 VerifyEachPass, DebugLogging))
1635 return Err;
16231636 FPM.addPass(createRepeatedPass(*Count, std::move(NestedFPM)));
1624 return true;
1637 return Error::success();
16251638 }
16261639
16271640 for (auto &C : FunctionPipelineParsingCallbacks)
16281641 if (C(Name, FPM, InnerPipeline))
1629 return true;
1642 return Error::success();
16301643
16311644 // Normal passes can't have pipelines.
1632 return false;
1645 return make_error(
1646 formatv("invalid use of '{0}' pass as function pipeline", Name).str(),
1647 inconvertibleErrorCode());
16331648 }
16341649
16351650 // Now expand the basic registered passes from the .inc file.
16361651 #define FUNCTION_PASS(NAME, CREATE_PASS) \
16371652 if (Name == NAME) { \
16381653 FPM.addPass(CREATE_PASS); \
1639 return true; \
1654 return Error::success(); \
16401655 }
16411656 #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
16421657 if (Name == "require<" NAME ">") { \
16431658 FPM.addPass( \
16441659 RequireAnalysisPass< \
16451660 std::remove_reference::type, Function>()); \
1646 return true; \
1661 return Error::success(); \
16471662 } \
16481663 if (Name == "invalidate<" NAME ">") { \
16491664 FPM.addPass(InvalidateAnalysisPass< \
16501665 std::remove_reference::type>()); \
1651 return true; \
1666 return Error::success(); \
16521667 }
16531668 #include "PassRegistry.def"
16541669
16551670 for (auto &C : FunctionPipelineParsingCallbacks)
16561671 if (C(Name, FPM, InnerPipeline))
1657 return true;
1658 return false;
1659 }
1660
1661 bool PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
1662 bool VerifyEachPass, bool DebugLogging) {
1672 return Error::success();
1673 return make_error(
1674 formatv("unknown function pass '{0}'", Name).str(),
1675 inconvertibleErrorCode());
1676 }
1677
1678 Error PassBuilder::parseLoopPass(LoopPassManager &LPM, const PipelineElement &E,
1679 bool VerifyEachPass, bool DebugLogging) {
16631680 StringRef Name = E.Name;
16641681 auto &InnerPipeline = E.InnerPipeline;
16651682
16671684 if (!InnerPipeline.empty()) {
16681685 if (Name == "loop") {
16691686 LoopPassManager NestedLPM(DebugLogging);
1670 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1671 DebugLogging))
1672 return false;
1687 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
1688 VerifyEachPass, DebugLogging))
1689 return Err;
16731690 // Add the nested pass manager with the appropriate adaptor.
16741691 LPM.addPass(std::move(NestedLPM));
1675 return true;
1692 return Error::success();
16761693 }
16771694 if (auto Count = parseRepeatPassName(Name)) {
16781695 LoopPassManager NestedLPM(DebugLogging);
1679 if (!parseLoopPassPipeline(NestedLPM, InnerPipeline, VerifyEachPass,
1680 DebugLogging))
1681 return false;
1696 if (auto Err = parseLoopPassPipeline(NestedLPM, InnerPipeline,
1697 VerifyEachPass, DebugLogging))
1698 return Err;
16821699 LPM.addPass(createRepeatedPass(*Count, std::move(NestedLPM)));
1683 return true;
1700 return Error::success();
16841701 }
16851702
16861703 for (auto &C : LoopPipelineParsingCallbacks)
16871704 if (C(Name, LPM, InnerPipeline))
1688 return true;
1705 return Error::success();
16891706
16901707 // Normal passes can't have pipelines.
1691 return false;
1708 return make_error(
1709 formatv("invalid use of '{0}' pass as loop pipeline", Name).str(),
1710 inconvertibleErrorCode());
16921711 }
16931712
16941713 // Now expand the basic registered passes from the .inc file.
16951714 #define LOOP_PASS(NAME, CREATE_PASS) \
16961715 if (Name == NAME) { \
16971716 LPM.addPass(CREATE_PASS); \
1698 return true; \
1717 return Error::success(); \
16991718 }
17001719 #define LOOP_ANALYSIS(NAME, CREATE_PASS) \
17011720 if (Name == "require<" NAME ">") { \
17031722 std::remove_reference::type, Loop, \
17041723 LoopAnalysisManager, LoopStandardAnalysisResults &, \
17051724 LPMUpdater &>()); \
1706 return true; \
1725 return Error::success(); \
17071726 } \
17081727 if (Name == "invalidate<" NAME ">") { \
17091728 LPM.addPass(InvalidateAnalysisPass< \
17101729 std::remove_reference::type>()); \
1711 return true; \
1730 return Error::success(); \
17121731 }
17131732 #include "PassRegistry.def"
17141733
17151734 for (auto &C : LoopPipelineParsingCallbacks)
17161735 if (C(Name, LPM, InnerPipeline))
1717 return true;
1718 return false;
1736 return Error::success();
1737 return make_error(formatv("unknown loop pass '{0}'", Name).str(),
1738 inconvertibleErrorCode());
17191739 }
17201740
17211741 bool PassBuilder::parseAAPassName(AAManager &AA, StringRef Name) {
17391759 return false;
17401760 }
17411761
1742 bool PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
1743 ArrayRef Pipeline,
1744 bool VerifyEachPass,
1745 bool DebugLogging) {
1746 for (const auto &Element : Pipeline) {
1747 if (!parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1748 return false;
1749 // FIXME: No verifier support for Loop passes!
1750 }
1751 return true;
1752 }
1753
1754 bool PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
1755 ArrayRef Pipeline,
1756 bool VerifyEachPass,
1757 bool DebugLogging) {
1758 for (const auto &Element : Pipeline) {
1759 if (!parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1760 return false;
1761 if (VerifyEachPass)
1762 FPM.addPass(VerifierPass());
1763 }
1764 return true;
1765 }
1766
1767 bool PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1762 Error PassBuilder::parseLoopPassPipeline(LoopPassManager &LPM,
17681763 ArrayRef Pipeline,
17691764 bool VerifyEachPass,
17701765 bool DebugLogging) {
17711766 for (const auto &Element : Pipeline) {
1772 if (!parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1773 return false;
1767 if (auto Err = parseLoopPass(LPM, Element, VerifyEachPass, DebugLogging))
1768 return Err;
1769 // FIXME: No verifier support for Loop passes!
1770 }
1771 return Error::success();
1772 }
1773
1774 Error PassBuilder::parseFunctionPassPipeline(FunctionPassManager &FPM,
1775 ArrayRef Pipeline,
1776 bool VerifyEachPass,
1777 bool DebugLogging) {
1778 for (const auto &Element : Pipeline) {
1779 if (auto Err =
1780 parseFunctionPass(FPM, Element, VerifyEachPass, DebugLogging))
1781 return Err;
1782 if (VerifyEachPass)
1783 FPM.addPass(VerifierPass());
1784 }
1785 return Error::success();
1786 }
1787
1788 Error PassBuilder::parseCGSCCPassPipeline(CGSCCPassManager &CGPM,
1789 ArrayRef Pipeline,
1790 bool VerifyEachPass,
1791 bool DebugLogging) {
1792 for (const auto &Element : Pipeline) {
1793 if (auto Err = parseCGSCCPass(CGPM, Element, VerifyEachPass, DebugLogging))
1794 return Err;
17741795 // FIXME: No verifier support for CGSCC passes!
17751796 }
1776 return true;
1797 return Error::success();
17771798 }
17781799
17791800 void PassBuilder::crossRegisterProxies(LoopAnalysisManager &LAM,
17891810 LAM.registerPass([&] { return FunctionAnalysisManagerLoopProxy(FAM); });
17901811 }
17911812
1792 bool PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1793 ArrayRef Pipeline,
1794 bool VerifyEachPass,
1795 bool DebugLogging) {
1813 Error PassBuilder::parseModulePassPipeline(ModulePassManager &MPM,
1814 ArrayRef Pipeline,
1815 bool VerifyEachPass,
1816 bool DebugLogging) {
17961817 for (const auto &Element : Pipeline) {
1797 if (!parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1798 return false;
1818 if (auto Err = parseModulePass(MPM, Element, VerifyEachPass, DebugLogging))
1819 return Err;
17991820 if (VerifyEachPass)
18001821 MPM.addPass(VerifierPass());
18011822 }
1802 return true;
1823 return Error::success();
18031824 }
18041825
18051826 // Primary pass pipeline description parsing routine for a \c ModulePassManager
18061827 // FIXME: Should this routine accept a TargetMachine or require the caller to
18071828 // pre-populate the analysis managers with target-specific stuff?
1808 bool PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1809 StringRef PipelineText, bool VerifyEachPass,
1810 bool DebugLogging) {
1829 Error PassBuilder::parsePassPipeline(ModulePassManager &MPM,
1830 StringRef PipelineText,
1831 bool VerifyEachPass, bool DebugLogging) {
18111832 auto Pipeline = parsePipelineText(PipelineText);
18121833 if (!Pipeline || Pipeline->empty())
1813 return false;
1834 return make_error(
1835 formatv("invalid pipeline '{0}'", PipelineText).str(),
1836 inconvertibleErrorCode());
18141837
18151838 // If the first name isn't at the module layer, wrap the pipeline up
18161839 // automatically.
18271850 } else {
18281851 for (auto &C : TopLevelPipelineParsingCallbacks)
18291852 if (C(MPM, *Pipeline, VerifyEachPass, DebugLogging))
1830 return true;
1831
1832 // Unknown pass name!
1833 return false;
1853 return Error::success();
1854
1855 // Unknown pass or pipeline name!
1856 auto &InnerPipeline = Pipeline->front().InnerPipeline;
1857 return make_error(
1858 formatv("unknown {0} name '{1}'",
1859 (InnerPipeline.empty() ? "pass" : "pipeline"), FirstName)
1860 .str(),
1861 inconvertibleErrorCode());
18341862 }
18351863 }
18361864
1837 return parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging);
1865 if (auto Err =
1866 parseModulePassPipeline(MPM, *Pipeline, VerifyEachPass, DebugLogging))
1867 return Err;
1868 return Error::success();
18381869 }
18391870
18401871 // Primary pass pipeline description parsing routine for a \c CGSCCPassManager
1841 bool PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM,
1842 StringRef PipelineText, bool VerifyEachPass,
1843 bool DebugLogging) {
1872 Error PassBuilder::parsePassPipeline(CGSCCPassManager &CGPM,
1873 StringRef PipelineText,
1874 bool VerifyEachPass, bool DebugLogging) {
18441875 auto Pipeline = parsePipelineText(PipelineText);
18451876 if (!Pipeline || Pipeline->empty())
1846 return false;
1877 return make_error(
1878 formatv("invalid pipeline '{0}'", PipelineText).str(),
1879 inconvertibleErrorCode());
18471880
18481881 StringRef FirstName = Pipeline->front().Name;
18491882 if (!isCGSCCPassName(FirstName, CGSCCPipelineParsingCallbacks))
1850 return false;
1851
1852 return parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1883 return make_error(
1884 formatv("unknown cgscc pass '{0}' in pipeline '{1}'", FirstName,
1885 PipelineText)
1886 .str(),
1887 inconvertibleErrorCode());
1888
1889 if (auto Err =
1890 parseCGSCCPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
1891 return Err;
1892 return Error::success();
18531893 }
18541894
18551895 // Primary pass pipeline description parsing routine for a \c
18561896 // FunctionPassManager
1857 bool PassBuilder::parsePassPipeline(FunctionPassManager &FPM,
1858 StringRef PipelineText, bool VerifyEachPass,
1859 bool DebugLogging) {
1897 Error PassBuilder::parsePassPipeline(FunctionPassManager &FPM,
1898 StringRef PipelineText,
1899 bool VerifyEachPass, bool DebugLogging) {
18601900 auto Pipeline = parsePipelineText(PipelineText);
18611901 if (!Pipeline || Pipeline->empty())
1862 return false;
1902 return make_error(
1903 formatv("invalid pipeline '{0}'", PipelineText).str(),
1904 inconvertibleErrorCode());
18631905
18641906 StringRef FirstName = Pipeline->front().Name;
18651907 if (!isFunctionPassName(FirstName, FunctionPipelineParsingCallbacks))
1866 return false;
1867
1868 return parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
1869 DebugLogging);
1908 return make_error(
1909 formatv("unknown function pass '{0}' in pipeline '{1}'", FirstName,
1910 PipelineText)
1911 .str(),
1912 inconvertibleErrorCode());
1913
1914 if (auto Err = parseFunctionPassPipeline(FPM, *Pipeline, VerifyEachPass,
1915 DebugLogging))
1916 return Err;
1917 return Error::success();
18701918 }
18711919
18721920 // Primary pass pipeline description parsing routine for a \c LoopPassManager
1873 bool PassBuilder::parsePassPipeline(LoopPassManager &CGPM,
1874 StringRef PipelineText, bool VerifyEachPass,
1875 bool DebugLogging) {
1921 Error PassBuilder::parsePassPipeline(LoopPassManager &CGPM,
1922 StringRef PipelineText,
1923 bool VerifyEachPass, bool DebugLogging) {
18761924 auto Pipeline = parsePipelineText(PipelineText);
18771925 if (!Pipeline || Pipeline->empty())
1878 return false;
1879
1880 return parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging);
1881 }
1882
1883 bool PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
1926 return make_error(
1927 formatv("invalid pipeline '{0}'", PipelineText).str(),
1928 inconvertibleErrorCode());
1929
1930 if (auto Err =
1931 parseLoopPassPipeline(CGPM, *Pipeline, VerifyEachPass, DebugLogging))
1932 return Err;
1933
1934 return Error::success();
1935 }
1936
1937 Error PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) {
18841938 // If the pipeline just consists of the word 'default' just replace the AA
18851939 // manager with our default one.
18861940 if (PipelineText == "default") {
18871941 AA = buildDefaultAAPipeline();
1888 return true;
1942 return Error::success();
18891943 }
18901944
18911945 while (!PipelineText.empty()) {
18921946 StringRef Name;
18931947 std::tie(Name, PipelineText) = PipelineText.split(',');
18941948 if (!parseAAPassName(AA, Name))
1895 return false;
1896 }
1897
1898 return true;
1899 }
1949 return make_error(
1950 formatv("unknown alias analysis name '{0}'", Name).str(),
1951 inconvertibleErrorCode());
1952 }
1953
1954 return Error::success();
1955 }
5353 ; RUN: not opt -disable-output -debug-pass-manager \
5454 ; RUN: -passes='no-op-module)' %s 2>&1 \
5555 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED1
56 ; CHECK-UNBALANCED1: unable to parse pass pipeline description
56 ; CHECK-UNBALANCED1: invalid pipeline 'no-op-module)'
5757
5858 ; RUN: not opt -disable-output -debug-pass-manager \
5959 ; RUN: -passes='module(no-op-module))' %s 2>&1 \
6060 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED2
61 ; CHECK-UNBALANCED2: unable to parse pass pipeline description
61 ; CHECK-UNBALANCED2: invalid pipeline 'module(no-op-module))'
6262
6363 ; RUN: not opt -disable-output -debug-pass-manager \
6464 ; RUN: -passes='module(no-op-module' %s 2>&1 \
6565 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED3
66 ; CHECK-UNBALANCED3: unable to parse pass pipeline description
66 ; CHECK-UNBALANCED3: invalid pipeline 'module(no-op-module'
6767
6868 ; RUN: not opt -disable-output -debug-pass-manager \
6969 ; RUN: -passes='no-op-function)' %s 2>&1 \
7070 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED4
71 ; CHECK-UNBALANCED4: unable to parse pass pipeline description
71 ; CHECK-UNBALANCED4: invalid pipeline 'no-op-function)'
7272
7373 ; RUN: not opt -disable-output -debug-pass-manager \
7474 ; RUN: -passes='function(no-op-function))' %s 2>&1 \
7575 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED5
76 ; CHECK-UNBALANCED5: unable to parse pass pipeline description
76 ; CHECK-UNBALANCED5: invalid pipeline 'function(no-op-function))'
7777
7878 ; RUN: not opt -disable-output -debug-pass-manager \
7979 ; RUN: -passes='function(function(no-op-function)))' %s 2>&1 \
8080 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED6
81 ; CHECK-UNBALANCED6: unable to parse pass pipeline description
81 ; CHECK-UNBALANCED6: invalid pipeline 'function(function(no-op-function)))'
8282
8383 ; RUN: not opt -disable-output -debug-pass-manager \
8484 ; RUN: -passes='function(no-op-function' %s 2>&1 \
8585 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED7
86 ; CHECK-UNBALANCED7: unable to parse pass pipeline description
86 ; CHECK-UNBALANCED7: invalid pipeline 'function(no-op-function'
8787
8888 ; RUN: not opt -disable-output -debug-pass-manager \
8989 ; RUN: -passes='function(function(no-op-function)' %s 2>&1 \
9090 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED8
91 ; CHECK-UNBALANCED8: unable to parse pass pipeline description
91 ; CHECK-UNBALANCED8: invalid pipeline 'function(function(no-op-function)'
9292
9393 ; RUN: not opt -disable-output -debug-pass-manager \
9494 ; RUN: -passes='no-op-module,)' %s 2>&1 \
9595 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED9
96 ; CHECK-UNBALANCED9: unable to parse pass pipeline description
96 ; CHECK-UNBALANCED9: invalid pipeline 'no-op-module,)'
9797
9898 ; RUN: not opt -disable-output -debug-pass-manager \
9999 ; RUN: -passes='no-op-function,)' %s 2>&1 \
100100 ; RUN: | FileCheck %s --check-prefix=CHECK-UNBALANCED10
101 ; CHECK-UNBALANCED10: unable to parse pass pipeline description
101 ; CHECK-UNBALANCED10: invalid pipeline 'no-op-function,)'
102102
103103 ; RUN: opt -disable-output -debug-pass-manager \
104104 ; RUN: -passes=no-op-cgscc,no-op-cgscc %s 2>&1 \
175175 ; RUN: not opt -disable-output -debug-pass-manager \
176176 ; RUN: -passes='function(no-op-function)function(no-op-function)' %s 2>&1 \
177177 ; RUN: | FileCheck %s --check-prefix=CHECK-MISSING-COMMA1
178 ; CHECK-MISSING-COMMA1: unable to parse pass pipeline description
178 ; CHECK-MISSING-COMMA1: invalid pipeline 'function(no-op-function)function(no-op-function)'
179179
180180 ; RUN: not opt -disable-output -debug-pass-manager \
181181 ; RUN: -passes='function()' %s 2>&1 \
182182 ; RUN: | FileCheck %s --check-prefix=CHECK-EMPTY-INNER-PIPELINE
183 ; CHECK-EMPTY-INNER-PIPELINE: unable to parse pass pipeline description
183 ; CHECK-EMPTY-INNER-PIPELINE: unknown function pass ''
184184
185185 ; RUN: not opt -disable-output -debug-pass-manager \
186186 ; RUN: -passes='no-op-module(no-op-module,whatever)' %s 2>&1 \
187187 ; RUN: | FileCheck %s --check-prefix=CHECK-PIPELINE-ON-MODULE-PASS
188 ; CHECK-PIPELINE-ON-MODULE-PASS: unable to parse pass pipeline description
188 ; CHECK-PIPELINE-ON-MODULE-PASS: invalid use of 'no-op-module' pass as module pipeline
189189
190190 ; RUN: not opt -disable-output -debug-pass-manager \
191191 ; RUN: -passes='no-op-cgscc(no-op-cgscc,whatever)' %s 2>&1 \
192192 ; RUN: | FileCheck %s --check-prefix=CHECK-PIPELINE-ON-CGSCC-PASS
193 ; CHECK-PIPELINE-ON-CGSCC-PASS: unable to parse pass pipeline description
193 ; CHECK-PIPELINE-ON-CGSCC-PASS: invalid use of 'no-op-cgscc' pass as cgscc pipeline
194194
195195 ; RUN: not opt -disable-output -debug-pass-manager \
196196 ; RUN: -passes='no-op-function(no-op-function,whatever)' %s 2>&1 \
197197 ; RUN: | FileCheck %s --check-prefix=CHECK-PIPELINE-ON-FUNCTION-PASS
198 ; CHECK-PIPELINE-ON-FUNCTION-PASS: unable to parse pass pipeline description
198 ; CHECK-PIPELINE-ON-FUNCTION-PASS: invalid use of 'no-op-function' pass as function pipeline
199199
200200 ; RUN: not opt -disable-output -debug-pass-manager \
201201 ; RUN: -passes='no-op-loop(no-op-loop,whatever)' %s 2>&1 \
202202 ; RUN: | FileCheck %s --check-prefix=CHECK-PIPELINE-ON-LOOP-PASS
203 ; CHECK-PIPELINE-ON-LOOP-PASS: unable to parse pass pipeline description
203 ; CHECK-PIPELINE-ON-LOOP-PASS: invalid use of 'no-op-loop' pass as loop pipeline
204204
205205 ; RUN: not opt -disable-output -debug-pass-manager \
206206 ; RUN: -passes='no-op-function()' %s 2>&1 \
207207 ; RUN: | FileCheck %s --check-prefix=CHECK-EMPTY-PIPELINE-ON-PASS
208 ; CHECK-EMPTY-PIPELINE-ON-PASS: unable to parse pass pipeline description
208 ; CHECK-EMPTY-PIPELINE-ON-PASS: invalid use of 'no-op-function' pass as function pipeline
209
210 ; RUN: not opt -passes='no-op-module,bad' \
211 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-MODULE
212 ; CHECK-UNKNOWN-MODULE: opt: unknown module pass 'bad'
213
214 ; RUN: not opt -passes='no-op-loop,bad' \
215 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-LOOP
216 ; CHECK-UNKNOWN-LOOP: opt: unknown loop pass 'bad'
217
218 ; RUN: not opt -passes='no-op-cgscc,bad' \
219 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-CGSCC
220 ; CHECK-UNKNOWN-CGSCC: opt: unknown cgscc pass 'bad'
221
222 ; RUN: not opt -passes='no-op-function,bad' \
223 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-FUNCTION
224 ; RUN: not opt -passes='function(bad,pipeline,text)' \
225 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-FUNCTION
226 ; RUN: not opt -passes='module(no-op-module,function(bad,pipeline,text))' \
227 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-FUNCTION
228 ; RUN: not opt -passes='no-op-module,function(bad,pipeline,text)' \
229 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-FUNCTION
230 ; RUN: not opt -passes='module(cgscc(function(bad,pipeline,text)))' \
231 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=CHECK-UNKNOWN-FUNCTION
232 ; CHECK-UNKNOWN-FUNCTION: opt: unknown function pass 'bad'
233
234 ; RUN: not opt -aa-pipeline=bad -passes=no-op-function \
235 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=AA-PIPELINE-ERR
236 ; AA-PIPELINE-ERR: unknown alias analysis name 'bad'
237 ; RUN: opt -passes-ep-peephole=bad -passes=no-op-function \
238 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-PEEPHOLE-ERR
239 ; PASSES-EP-PEEPHOLE-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
240 ; RUN: opt -passes-ep-late-loop-optimizations=bad -passes=no-op-function \
241 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-LATELOOPOPT-ERR
242 ; PASSES-EP-LATELOOPOPT-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
243 ; RUN: opt -passes-ep-loop-optimizer-end=bad -passes=no-op-function \
244 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-LOOPOPTEND-ERR
245 ; PASSES-EP-LOOPOPTEND-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
246 ; RUN: opt -passes-ep-scalar-optimizer-late=bad -passes=no-op-function \
247 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-SCALAROPTLATE-ERR
248 ; PASSES-EP-SCALAROPTLATE-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
249 ; RUN: opt -passes-ep-cgscc-optimizer-late=bad -passes=no-op-function \
250 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-CGSCCOPTLATE-ERR
251 ; PASSES-EP-CGSCCOPTLATE-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
252 ; RUN: opt -passes-ep-vectorizer-start=bad -passes=no-op-function \
253 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-VECTORIZERSTART-ERR
254 ; PASSES-EP-VECTORIZERSTART-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
255 ; RUN: opt -passes-ep-pipeline-start=bad -passes=no-op-function \
256 ; RUN: /dev/null -disable-output 2>&1 | FileCheck %s -check-prefix=PASSES-EP-PIPELINESTART-ERR
257 ; PASSES-EP-PIPELINESTART-ERR: Could not parse pipeline 'bad'. I'm going to ignore it.
209258
210259 define void @f() {
211260 entry:
3131 ; RUN: -r %t1.bc,patatino,px -opt-pipeline foogoo 2>&1 | \
3232 ; RUN: FileCheck %s --check-prefix=ERR
3333
34 ; ERR: LLVM ERROR: unable to parse pass pipeline description: foogoo
34 ; ERR: LLVM ERROR: unable to parse pass pipeline description 'foogoo': unknown pass name 'foogoo'
3535
3636 ; RUN: not llvm-lto2 run %t1.bc -o %t.o \
3737 ; RUN: -r %t1.bc,patatino,px -aa-pipeline patatino \
3838 ; RUN: -opt-pipeline loweratomic 2>&1 | \
3939 ; RUN: FileCheck %s --check-prefix=AAERR
4040
41 ; AAERR: LLVM ERROR: unable to parse AA pipeline description: patatino
41 ; AAERR: LLVM ERROR: unable to parse AA pipeline description 'patatino': unknown alias analysis name 'patatino'
1212
1313 ; Don't start with incorrect passes specified
1414 ; RUN: not llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 -passes no-pass 2>&1 | FileCheck -check-prefix=PIPELINE %s
15 ; PIPELINE: can't parse pass pipeline
15 ; PIPELINE: unknown pass name 'no-pass'
1616
1717 ; Correct command line
1818 ; RUN: llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 -passes instcombine 2>&1 | FileCheck -check-prefix=CORRECT %s
143143 PB.registerLoopAnalyses(LAM);
144144 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
145145
146 bool Ok = PB.parsePassPipeline(MPM, PassPipeline, false, false);
147 assert(Ok && "Should have been checked during fuzzer initialization");
148 (void)Ok; // silence unused variable warning on release builds
146 auto Err = PB.parsePassPipeline(MPM, PassPipeline, false, false);
147 assert(!Err && "Should have been checked during fuzzer initialization");
148 // Only fail with assert above, otherwise ignore the parsing error.
149 consumeError(std::move(Err));
149150
150151 // Run passes which we need to test
151152 //
234235
235236 PassBuilder PB(TM.get());
236237 ModulePassManager MPM;
237 if (!PB.parsePassPipeline(MPM, PassPipeline, false, false)) {
238 errs() << *argv[0] << ": can't parse pass pipeline\n";
238 if (auto Err = PB.parsePassPipeline(MPM, PassPipeline, false, false)) {
239 errs() << *argv[0] << ": " << toString(std::move(Err)) << "\n";
239240 exit(1);
240241 }
241242
123123
124124 // Verify the pipeline is parseable:
125125 PassManagerT PM;
126 if (PB.parsePassPipeline(PM, PipelineText))
127 return true;
128
129 errs() << "Could not parse pipeline '" << PipelineText
130 << "'. I'm going to igore it.\n";
131 return false;
126 if (auto Err = PB.parsePassPipeline(PM, PipelineText)) {
127 errs() << "Could not parse pipeline '" << PipelineText
128 << "'. I'm going to ignore it.\n";
129 return false;
130 }
131 return true;
132132 }
133133
134134 /// If one of the EPPipeline command line options was given, register callbacks
136136 static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
137137 bool DebugLogging) {
138138 if (tryParsePipelineText(PB, PeepholeEPPipeline))
139 PB.registerPeepholeEPCallback([&PB, VerifyEachPass, DebugLogging](
140 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
141 PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
142 DebugLogging);
143 });
139 PB.registerPeepholeEPCallback(
140 [&PB, VerifyEachPass, DebugLogging](
141 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
142 ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
143 Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
144 DebugLogging));
145 });
144146 if (tryParsePipelineText(PB,
145147 LateLoopOptimizationsEPPipeline))
146148 PB.registerLateLoopOptimizationsEPCallback(
147149 [&PB, VerifyEachPass, DebugLogging](
148150 LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
149 PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
150 VerifyEachPass, DebugLogging);
151 ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
152 Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
153 VerifyEachPass, DebugLogging));
151154 });
152155 if (tryParsePipelineText(PB, LoopOptimizerEndEPPipeline))
153 PB.registerLoopOptimizerEndEPCallback([&PB, VerifyEachPass, DebugLogging](
154 LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
155 PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline, VerifyEachPass,
156 DebugLogging);
157 });
156 PB.registerLoopOptimizerEndEPCallback(
157 [&PB, VerifyEachPass, DebugLogging](
158 LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
159 ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: ");
160 Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline,
161 VerifyEachPass, DebugLogging));
162 });
158163 if (tryParsePipelineText(PB,
159164 ScalarOptimizerLateEPPipeline))
160165 PB.registerScalarOptimizerLateEPCallback(
161166 [&PB, VerifyEachPass, DebugLogging](
162167 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
163 PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline,
164 VerifyEachPass, DebugLogging);
168 ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: ");
169 Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline,
170 VerifyEachPass, DebugLogging));
165171 });
166172 if (tryParsePipelineText(PB, CGSCCOptimizerLateEPPipeline))
167 PB.registerCGSCCOptimizerLateEPCallback([&PB, VerifyEachPass, DebugLogging](
168 CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) {
169 PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline, VerifyEachPass,
170 DebugLogging);
171 });
173 PB.registerCGSCCOptimizerLateEPCallback(
174 [&PB, VerifyEachPass, DebugLogging](
175 CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) {
176 ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: ");
177 Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline,
178 VerifyEachPass, DebugLogging));
179 });
172180 if (tryParsePipelineText(PB, VectorizerStartEPPipeline))
173 PB.registerVectorizerStartEPCallback([&PB, VerifyEachPass, DebugLogging](
174 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
175 PB.parsePassPipeline(PM, VectorizerStartEPPipeline, VerifyEachPass,
176 DebugLogging);
177 });
181 PB.registerVectorizerStartEPCallback(
182 [&PB, VerifyEachPass, DebugLogging](
183 FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
184 ExitOnError Err("Unable to parse VectorizerStartEP pipeline: ");
185 Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline,
186 VerifyEachPass, DebugLogging));
187 });
178188 if (tryParsePipelineText(PB, PipelineStartEPPipeline))
179189 PB.registerPipelineStartEPCallback(
180190 [&PB, VerifyEachPass, DebugLogging](ModulePassManager &PM) {
181 PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass,
182 DebugLogging);
191 ExitOnError Err("Unable to parse PipelineStartEP pipeline: ");
192 Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline, VerifyEachPass,
193 DebugLogging));
183194 });
184195 }
185196
257268 // Specially handle the alias analysis manager so that we can register
258269 // a custom pipeline of AA passes with it.
259270 AAManager AA;
260 if (!PB.parseAAPipeline(AA, AAPipeline)) {
261 errs() << Arg0 << ": unable to parse AA pipeline description.\n";
271 if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) {
272 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
262273 return false;
263274 }
264275
283294 if (EnableDebugify)
284295 MPM.addPass(NewPMDebugifyPass());
285296
286 if (!PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
287 errs() << Arg0 << ": unable to parse pass pipeline description.\n";
297 if (auto Err =
298 PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
299 errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";
288300 return false;
289301 }
290302
3939 VerifierTest.cpp
4040 WaymarkTest.cpp
4141 )
42
43 target_link_libraries(IRTests PRIVATE LLVMTestingSupport)
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "llvm/Testing/Support/Error.h"
910 #include
1011 #include
1112 #include
459460 .WillOnce(Invoke(getAnalysisResult));
460461
461462 StringRef PipelineText = "test-transform";
462 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
463 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
463464 << "Pipeline was: " << PipelineText;
464465
465466 PM.run(*M, AM);
493494 .InSequence(PISequence);
494495
495496 StringRef PipelineText = "test-transform";
496 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
497 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
497498 << "Pipeline was: " << PipelineText;
498499
499500 PM.run(*M, AM);
524525 .Times(0);
525526
526527 StringRef PipelineText = "test-transform";
527 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
528 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
528529 << "Pipeline was: " << PipelineText;
529530
530531 PM.run(*M, AM);
536537 .WillOnce(Invoke(getAnalysisResult));
537538
538539 StringRef PipelineText = "test-transform";
539 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
540 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
540541 << "Pipeline was: " << PipelineText;
541542 PM.run(*M, AM);
542543 }
570571 .InSequence(PISequence);
571572
572573 StringRef PipelineText = "test-transform";
573 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
574 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
574575 << "Pipeline was: " << PipelineText;
575576 PM.run(*M, AM);
576577 }
603604 .Times(0);
604605
605606 StringRef PipelineText = "test-transform";
606 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
607 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
607608 << "Pipeline was: " << PipelineText;
608609 PM.run(*M, AM);
609610 }
614615 .WillOnce(WithArgs<0, 1, 2>(Invoke(getAnalysisResult)));
615616
616617 StringRef PipelineText = "test-transform";
617 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
618 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
618619 << "Pipeline was: " << PipelineText;
619620 PM.run(*M, AM);
620621 }
649650 .InSequence(PISequence);
650651
651652 StringRef PipelineText = "test-transform";
652 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
653 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
653654 << "Pipeline was: " << PipelineText;
654655 PM.run(*M, AM);
655656 }
681682 .Times(0);
682683
683684 StringRef PipelineText = "test-transform";
684 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
685 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
685686 << "Pipeline was: " << PipelineText;
686687 PM.run(*M, AM);
687688 }
692693 .WillOnce(WithArgs<0, 1, 2>(Invoke(getAnalysisResult)));
693694
694695 StringRef PipelineText = "test-transform";
695 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
696 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
696697 << "Pipeline was: " << PipelineText;
697698 PM.run(*M, AM);
698699 }
726727 .InSequence(PISequence);
727728
728729 StringRef PipelineText = "test-transform";
729 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
730 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
730731 << "Pipeline was: " << PipelineText;
731732 PM.run(*M, AM);
732733 }
758759 .Times(0);
759760
760761 StringRef PipelineText = "test-transform";
761 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
762 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
762763 << "Pipeline was: " << PipelineText;
763764 PM.run(*M, AM);
764765 }
773774 EXPECT_CALL(AnalysisHandle, invalidate(HasName(""), _, _));
774775
775776 StringRef PipelineText = "require,invalidate";
776 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
777 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
777778 << "Pipeline was: " << PipelineText;
778779 PM.run(*M, AM);
779780 }
783784 EXPECT_CALL(AnalysisHandle, invalidate(HasName("(foo)"), _, _));
784785
785786 StringRef PipelineText = "require,invalidate";
786 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
787 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
787788 << "Pipeline was: " << PipelineText;
788789 PM.run(*M, AM);
789790 }
793794 EXPECT_CALL(AnalysisHandle, invalidate(HasName("foo"), _, _));
794795
795796 StringRef PipelineText = "require,invalidate";
796 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
797 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
797798 << "Pipeline was: " << PipelineText;
798799 PM.run(*M, AM);
799800 }
804805
805806 StringRef PipelineText = "require,invalidate";
806807
807 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
808 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
808809 << "Pipeline was: " << PipelineText;
809810 PM.run(*M, AM);
810811 }
844845
845846 StringRef PipelineText =
846847 "another-pipeline(test-transform,invalidate)";
847 ASSERT_TRUE(PB.parsePassPipeline(PM, PipelineText, true))
848 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Succeeded())
848849 << "Pipeline was: " << PipelineText;
849850 PM.run(*M, AM);
850851
851852 /// Test the negative case
852853 PipelineText = "another-pipeline(instcombine)";
853 ASSERT_FALSE(PB.parsePassPipeline(PM, PipelineText, true))
854 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, PipelineText, true), Failed())
854855 << "Pipeline was: " << PipelineText;
855856 }
856857 } // end anonymous namespace
1111 PluginsTest.cpp
1212 )
1313 export_executable_symbols(PluginsTests)
14 target_link_libraries(PluginsTests PRIVATE LLVMTestingSupport)
1415
1516 set(LLVM_LINK_COMPONENTS)
1617 add_llvm_loadable_module(TestPlugin
1414 #include "llvm/Support/FileSystem.h"
1515 #include "llvm/Support/ManagedStatic.h"
1616 #include "llvm/Support/Path.h"
17 #include "llvm/Testing/Support/Error.h"
1718 #include "llvm/Transforms/Scalar/LoopPassManager.h"
1819 #include "gtest/gtest.h"
1920
5354
5455 PassBuilder PB;
5556 ModulePassManager PM;
56 ASSERT_FALSE(PB.parsePassPipeline(PM, "plugin-pass"));
57 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, "plugin-pass"), Failed());
5758
5859 Plugin->registerPassBuilderCallbacks(PB);
59 ASSERT_TRUE(PB.parsePassPipeline(PM, "plugin-pass"));
60 ASSERT_THAT_ERROR(PB.parsePassPipeline(PM, "plugin-pass"), Succeeded());
6061 }