1 #include "llvm/IR/Function.h"
2 #include "llvm/IR/Module.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"
9 #include "llvm/Analysis/InlineOrder.h"
15 class NoFooInlineOrder
: public InlineOrder
<std::pair
<CallBase
*, int>> {
17 NoFooInlineOrder(FunctionAnalysisManager
&FAM
, const InlineParams
&Params
,
18 ModuleAnalysisManager
&MAM
, Module
&M
) {
19 DefaultInlineOrder
= getDefaultInlineOrder(FAM
, Params
, MAM
, M
);
21 size_t size() override
{ return DefaultInlineOrder
->size(); }
22 void push(const std::pair
<CallBase
*, int> &Elt
) override
{
23 // We ignore calles named "foo"
24 if (Elt
.first
->getCalledFunction()->getName() == "foo") {
25 DefaultInlineOrder
->push(Elt
);
28 std::pair
<CallBase
*, int> pop() override
{
29 return DefaultInlineOrder
->pop();
31 void erase_if(function_ref
<bool(std::pair
<CallBase
*, int>)> Pred
) override
{
32 DefaultInlineOrder
->erase_if(Pred
);
36 std::unique_ptr
<InlineOrder
<std::pair
<CallBase
*, int>>> DefaultInlineOrder
;
39 std::unique_ptr
<InlineOrder
<std::pair
<CallBase
*, int>>>
40 NoFooInlineOrderFactory(FunctionAnalysisManager
&FAM
,
41 const InlineParams
&Params
, ModuleAnalysisManager
&MAM
,
43 return std::make_unique
<NoFooInlineOrder
>(FAM
, Params
, MAM
, M
);
48 /* New PM Registration */
49 llvm::PassPluginLibraryInfo
getDefaultDynamicInlineOrderPluginInfo() {
50 return {LLVM_PLUGIN_API_VERSION
, "DynamicDefaultInlineOrder",
51 LLVM_VERSION_STRING
, [](PassBuilder
&PB
) {
52 // We use the PassBuilder's callback mechanism
53 // to register our Analysis: this will register
54 // our PluginInlineOrderAnalysis instance with
55 // the ModuleAnalysisManager
56 PB
.registerAnalysisRegistrationCallback(
57 [](ModuleAnalysisManager
&MAM
) {
59 // defaultInlineOrderFactory will be
60 // used to create an InlineOrder
61 return PluginInlineOrderAnalysis(NoFooInlineOrderFactory
);
67 extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
68 llvmGetPassPluginInfo() {
69 return getDefaultDynamicInlineOrderPluginInfo();