diff --git a/include/llvm/Passes/PassBuilder.h b/include/llvm/Passes/PassBuilder.h index 295a5aacfe7..f9b0d939e5f 100644 --- a/include/llvm/Passes/PassBuilder.h +++ b/include/llvm/Passes/PassBuilder.h @@ -515,6 +515,9 @@ public: /// returns false. Error parseAAPipeline(AAManager &AA, StringRef PipelineText); + /// Returns true if the pass name is the name of an alias analysis pass. + bool isAAPassName(StringRef PassName); + /// Register a callback for a default optimizer pipeline extension /// point /// diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index eda5454cdb7..d1900ab3185 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -2657,3 +2657,11 @@ Error PassBuilder::parseAAPipeline(AAManager &AA, StringRef PipelineText) { return Error::success(); } + +bool PassBuilder::isAAPassName(StringRef PassName) { +#define FUNCTION_ALIAS_ANALYSIS(NAME, CREATE_PASS) \ + if (PassName == NAME) \ + return true; +#include "PassRegistry.def" + return false; +} diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp index 32239743834..0b572efc901 100644 --- a/tools/opt/NewPMDriver.cpp +++ b/tools/opt/NewPMDriver.cpp @@ -14,6 +14,7 @@ #include "NewPMDriver.h" #include "PassPrinters.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/CGSCCPassManager.h" @@ -306,9 +307,26 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, // Specially handle the alias analysis manager so that we can register // a custom pipeline of AA passes with it. AAManager AA; - if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) { - errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; - return false; + if (!AAPipeline.empty()) { + assert(Passes.empty() && + "--aa-pipeline and -foo-pass should not both be specified"); + if (auto Err = PB.parseAAPipeline(AA, AAPipeline)) { + errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; + return false; + } + } + // For compatibility with legacy pass manager. + // Alias analyses are not specially specified when using the legacy PM. + SmallVector NonAAPasses; + for (auto PassName : Passes) { + if (PB.isAAPassName(PassName)) { + if (auto Err = PB.parseAAPipeline(AA, PassName)) { + errs() << Arg0 << ": " << toString(std::move(Err)) << "\n"; + return false; + } + } else { + NonAAPasses.push_back(PassName); + } } LoopAnalysisManager LAM(DebugPM); @@ -341,7 +359,7 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, return false; } } - for (auto PassName : Passes) { + for (auto PassName : NonAAPasses) { if (auto Err = PB.parsePassPipeline(MPM, PassName, VerifyEachPass, DebugPM)) { errs() << Arg0 << ": " << toString(std::move(Err)) << "\n";