Skip to content

Commit

Permalink
[InlineAdvisor] Update documentation for `PluginInlineAdvisorAnalysis…
Browse files Browse the repository at this point in the history
…` (NFC). (llvm#116715)

This commit updates the documentation for `PluginInlineAdvisorAnalysis`
based on the feedback in PR#114615 suggesting that
`registerAnalysisRegistrationCallback` should be the preferred method to
register the plugin inline advisor analysis.
  • Loading branch information
michele-scandale authored Nov 19, 2024
1 parent 197e012 commit c84a99d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
27 changes: 10 additions & 17 deletions llvm/include/llvm/Analysis/InlineAdvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,37 +247,30 @@ class DefaultInlineAdvisor : public InlineAdvisor {
///
/// namespace {
///
/// InlineAdvisor *defaultAdvisorFactory(Module &M, FunctionAnalysisManager
/// &FAM,
/// InlineParams Params, InlineContext IC)
/// {
/// InlineAdvisor *defaultAdvisorFactory(Module &M,
/// FunctionAnalysisManager &FAM,
/// InlineParams Params,
/// InlineContext IC) {
/// return new DefaultInlineAdvisor(M, FAM, Params, IC);
/// }
///
/// struct DefaultDynamicAdvisor : PassInfoMixin<DefaultDynamicAdvisor> {
/// PreservedAnalyses run(Module &, ModuleAnalysisManager &MAM) {
/// PluginInlineAdvisorAnalysis PA(defaultAdvisorFactory);
/// MAM.registerPass([&] { return PA; });
/// return PreservedAnalyses::all();
/// }
/// };
///
/// } // namespace
///
/// extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
/// llvmGetPassPluginInfo() {
/// return {LLVM_PLUGIN_API_VERSION, "DynamicDefaultAdvisor",
/// LLVM_VERSION_STRING,
/// LLVM_VERSION_STRING,
/// [](PassBuilder &PB) {
/// PB.registerPipelineStartEPCallback(
/// [](ModulePassManager &MPM, OptimizationLevel Level) {
/// MPM.addPass(DefaultDynamicAdvisor());
/// PB.registerAnalysisRegistrationCallback(
/// [](ModuleAnalysisManager &MAM) {
/// PluginInlineAdvisorAnalysis PA(defaultAdvisorFactory);
/// MAM.registerPass([&] { return PA; });
/// });
/// }};
/// }
///
/// A plugin must implement an AdvisorFactory and register it with a
/// PluginInlineAdvisorAnlysis to the provided ModuleanAlysisManager.
/// PluginInlineAdvisorAnlysis to the provided ModuleAnalysisManager.
///
/// If such a plugin has been registered
/// InlineAdvisorAnalysis::Result::tryCreate will return the dynamically loaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,16 @@ InlineAdvisor *DefaultAdvisorFactory(Module &M, FunctionAnalysisManager &FAM,
return new DefaultInlineAdvisor(M, FAM, Params, IC);
}

struct DefaultDynamicAdvisor : PassInfoMixin<DefaultDynamicAdvisor> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) {
PluginInlineAdvisorAnalysis DA(DefaultAdvisorFactory);
MAM.registerPass([&] { return DA; });
return PreservedAnalyses::all();
}
};

} // namespace

/* New PM Registration */
llvm::PassPluginLibraryInfo getDefaultDynamicAdvisorPluginInfo() {
return {LLVM_PLUGIN_API_VERSION, "DynamicDefaultAdvisor", LLVM_VERSION_STRING,
[](PassBuilder &PB) {
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(DefaultDynamicAdvisor());
});
PB.registerPipelineParsingCallback(
[](StringRef Name, ModulePassManager &PM,
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
if (Name == "dynamic-inline-advisor") {
PM.addPass(DefaultDynamicAdvisor());
return true;
}
return false;
PB.registerAnalysisRegistrationCallback(
[](ModuleAnalysisManager &MAM) {
PluginInlineAdvisorAnalysis PA(DefaultAdvisorFactory);
MAM.registerPass([&] { return PA; });
});
}};
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/unittests/Analysis/PluginInlineAdvisorAnalysisTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ struct CompilerInstance {
Expected<PassPlugin> Plugin = PassPlugin::Load(PluginPath);
ASSERT_TRUE(!!Plugin) << "Plugin path: " << PluginPath;
Plugin->registerPassBuilderCallbacks(PB);
ASSERT_THAT_ERROR(PB.parsePassPipeline(MPM, "dynamic-inline-advisor"),
Succeeded());
}

// connect the FooOnlyInlineAdvisor to our compiler instance
Expand Down

0 comments on commit c84a99d

Please sign in to comment.