Skip to content

Commit

Permalink
[NewPM] Use the default AA pipeline by default
Browse files Browse the repository at this point in the history
We almost always want to use the default AA pipeline. It's very easy for
users of PassBuilder to forget to customize the AAManager to use the
default AA pipeline (for example, the NewPM C API forgets to do this).

If somebody wants a custom AA pipeline, similar to what is being done
now with the default AA pipeline registration, they can

  FAM.registerPass([&] { return std::move(MyAA); });

before calling

  PB.registerFunctionAnalyses(FAM);

For example, LTOBackend.cpp and NewPMDriver.cpp do this.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D113210
  • Loading branch information
aeubanks committed Nov 4, 2021
1 parent a2639dc commit 1331728
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
3 changes: 0 additions & 3 deletions clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -1312,9 +1312,6 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"

// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });

// Register the target library analysis directly and give it a customized
// preset TLI.
Triple TargetTriple(TheModule->getTargetTriple());
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/LTO/LTOBackend.cpp
Expand Up @@ -251,18 +251,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });

AAManager AA;
// Parse a custom AA pipeline if asked to.
if (!Conf.AAPipeline.empty()) {
AAManager AA;
if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
report_fatal_error(Twine("unable to parse AA pipeline description '") +
Conf.AAPipeline + "': " + toString(std::move(Err)));
}
} else {
AA = PB.buildDefaultAAPipeline();
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });
}
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });

// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/LTO/ThinLTOCodeGenerator.cpp
Expand Up @@ -291,11 +291,6 @@ static void optimizeModuleNewPM(Module &TheModule, TargetMachine &TM,
TLII->disableAllFunctions();
FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });

AAManager AA = PB.buildDefaultAAPipeline();

// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return std::move(AA); });

// Register all the basic analyses with the managers.
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Expand Up @@ -413,6 +413,11 @@ void PassBuilder::registerCGSCCAnalyses(CGSCCAnalysisManager &CGAM) {
}

void PassBuilder::registerFunctionAnalyses(FunctionAnalysisManager &FAM) {
// We almost always want the default alias analysis pipeline.
// If a user wants a different one, they can register their own before calling
// registerFunctionAnalyses().
FAM.registerPass([&] { return buildDefaultAAPipeline(); });

#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
FAM.registerPass([&] { return CREATE_PASS; });
#include "PassRegistry.def"
Expand Down
1 change: 0 additions & 1 deletion llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
Expand Up @@ -144,7 +144,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
ModulePassManager MPM;
ModuleAnalysisManager MAM;

FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
Expand Down

0 comments on commit 1331728

Please sign in to comment.