xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Analysis/InlineOrder.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1 //===- InlineOrder.h - Inlining order abstraction -*- C++ ---*-------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 #ifndef LLVM_ANALYSIS_INLINEORDER_H
10 #define LLVM_ANALYSIS_INLINEORDER_H
11 
12 #include "llvm/ADT/STLFunctionalExtras.h"
13 #include "llvm/Analysis/InlineCost.h"
14 #include <utility>
15 
16 namespace llvm {
17 class CallBase;
18 
19 template <typename T> class InlineOrder {
20 public:
21   virtual ~InlineOrder() = default;
22 
23   virtual size_t size() = 0;
24 
25   virtual void push(const T &Elt) = 0;
26 
27   virtual T pop() = 0;
28 
29   virtual void erase_if(function_ref<bool(T)> Pred) = 0;
30 
empty()31   bool empty() { return !size(); }
32 };
33 
34 std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>>
35 getDefaultInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params,
36                       ModuleAnalysisManager &MAM, Module &M);
37 
38 std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>>
39 getInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params,
40                ModuleAnalysisManager &MAM, Module &M);
41 
42 /// Used for dynamically loading instances of InlineOrder as plugins
43 ///
44 /// Plugins must implement an InlineOrderFactory, for an example refer to:
45 /// llvm/unittests/Analysis/InlineOrderPlugin/InlineOrderPlugin.cpp
46 ///
47 /// If a PluginInlineOrderAnalysis has been registered with the
48 /// current ModuleAnalysisManager, llvm::getInlineOrder returns an
49 /// InlineOrder created by the PluginInlineOrderAnalysis' Factory.
50 ///
51 class PluginInlineOrderAnalysis
52     : public AnalysisInfoMixin<PluginInlineOrderAnalysis> {
53 public:
54   static AnalysisKey Key;
55 
56   typedef std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> (
57       *InlineOrderFactory)(FunctionAnalysisManager &FAM,
58                            const InlineParams &Params,
59                            ModuleAnalysisManager &MAM, Module &M);
60 
PluginInlineOrderAnalysis(InlineOrderFactory Factory)61   PluginInlineOrderAnalysis(InlineOrderFactory Factory) : Factory(Factory) {
62     HasBeenRegistered = true;
63     assert(Factory != nullptr &&
64            "The plugin inline order factory should not be a null pointer.");
65   }
66 
67   struct Result {
68     InlineOrderFactory Factory;
69   };
70 
run(Module &,ModuleAnalysisManager &)71   Result run(Module &, ModuleAnalysisManager &) { return {Factory}; }
getResult()72   Result getResult() { return {Factory}; }
73 
isRegistered()74   static bool isRegistered() { return HasBeenRegistered; }
unregister()75   static void unregister() { HasBeenRegistered = false; }
76 
77 private:
78   static bool HasBeenRegistered;
79   InlineOrderFactory Factory;
80 };
81 
82 } // namespace llvm
83 #endif // LLVM_ANALYSIS_INLINEORDER_H
84