diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -515,6 +515,9 @@ /// 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/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -2657,3 +2657,11 @@ 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/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/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 @@ // 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 @@ 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";