[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / llvm / unittests / Analysis / InlineOrderPlugin / InlineOrderPlugin.cpp
blob9c46c1b8e22ba5dcae72683f7a926442e2d15d19
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"
9 #include "llvm/Analysis/InlineOrder.h"
11 using namespace llvm;
13 namespace {
15 class NoFooInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
16 public:
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);
35 private:
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,
42 Module &M) {
43 return std::make_unique<NoFooInlineOrder>(FAM, Params, MAM, M);
46 } // namespace
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) {
58 MAM.registerPass([] {
59 // defaultInlineOrderFactory will be
60 // used to create an InlineOrder
61 return PluginInlineOrderAnalysis(NoFooInlineOrderFactory);
62 });
63 });
64 }};
67 extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo
68 llvmGetPassPluginInfo() {
69 return getDefaultDynamicInlineOrderPluginInfo();