Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InlineAdvisor] Allow loading advisors as plugins
Adds the ability to load InlineAdvisors as plugins. This allows developing and distributing inlining heuristics outside of tree. The PluginInlineAdvisorAnalysis class serves as the entry point for dynamic advisors. Plugins must register instances of this class to provide their own InliningAdvisor. Reviewed By: mtrofin Differential Revision: https://reviews.llvm.org/D139644
- Loading branch information
Showing
5 changed files
with
484 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Passes/PassBuilder.h" | ||
#include "llvm/Passes/PassPlugin.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
#include "llvm/Analysis/InlineAdvisor.h" | ||
|
||
using namespace llvm; | ||
|
||
namespace { | ||
|
||
InlineAdvisor *DefaultAdvisorFactory(Module &M, FunctionAnalysisManager &FAM, | ||
InlineParams Params, InlineContext IC) { | ||
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; | ||
}); | ||
}}; | ||
} | ||
|
||
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo | ||
llvmGetPassPluginInfo() { | ||
return getDefaultDynamicAdvisorPluginInfo(); | ||
} |
Oops, something went wrong.