| 1 |
#include "llvm/IR/Function.h" |
| 2 |
#include "llvm/IR/Module.h" |
| 3 |
#include "llvm/Pass.h" |
| 4 |
#include "llvm/Passes/PassBuilder.h" |
| 5 |
#include "llvm/Passes/PassPlugin.h" |
| 6 |
#include "llvm/Support/CommandLine.h" |
| 7 |
#include "llvm/Support/raw_ostream.h" |
| 8 |
|
| 9 |
#include "llvm/Analysis/InlineAdvisor.h" |
| 10 |
|
| 11 |
using namespace llvm; |
| 12 |
|
| 13 |
namespace { |
| 14 |
|
| 15 |
InlineAdvisor *DefaultAdvisorFactory(Module &M, FunctionAnalysisManager &FAM, |
| 16 |
InlineParams Params, InlineContext IC) { |
| 17 |
return new DefaultInlineAdvisor(M, FAM, Params, IC); |
| 18 |
} |
| 19 |
|
| 20 |
struct DefaultDynamicAdvisor : PassInfoMixin<DefaultDynamicAdvisor> { |
| 21 |
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM) { |
| 22 |
PluginInlineAdvisorAnalysis DA(DefaultAdvisorFactory); |
| 23 |
MAM.registerPass([&] { return DA; }); |
| 24 |
return PreservedAnalyses::all(); |
| 25 |
} |
| 26 |
}; |
| 27 |
|
| 28 |
} // namespace |
| 29 |
|
| 30 |
/* New PM Registration */ |
| 31 |
llvm::PassPluginLibraryInfo getDefaultDynamicAdvisorPluginInfo() { |
| 32 |
return {LLVM_PLUGIN_API_VERSION, "DynamicDefaultAdvisor", LLVM_VERSION_STRING, |
| 33 |
[](PassBuilder &PB) { |
| 34 |
PB.registerPipelineStartEPCallback( |
| 35 |
[](ModulePassManager &MPM, OptimizationLevel Level) { |
| 36 |
MPM.addPass(DefaultDynamicAdvisor()); |
| 37 |
}); |
| 38 |
PB.registerPipelineParsingCallback( |
| 39 |
[](StringRef Name, ModulePassManager &PM, |
| 40 |
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) { |
| 41 |
if (Name == "dynamic-inline-advisor") { |
| 42 |
PM.addPass(DefaultDynamicAdvisor()); |
| 43 |
return true; |
| 44 |
} |
| 45 |
return false; |
| 46 |
}); |
| 47 |
}}; |
| 48 |
} |
| 49 |
|
| 50 |
extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo |
| 51 |
llvmGetPassPluginInfo() { |
| 52 |
return getDefaultDynamicAdvisorPluginInfo(); |
| 53 |
} |