| 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/Analysis/InlineCost.h" |
| 13 | #include "llvm/Support/Compiler.h" |
| 14 | #include <utility> |
| 15 | |
| 16 | namespace llvm { |
| 17 | class CallBase; |
| 18 | template <typename Fn> class function_ref; |
| 19 | |
| 20 | template <typename T> class InlineOrder { |
| 21 | public: |
| 22 | virtual ~InlineOrder() = default; |
| 23 | |
| 24 | virtual size_t size() = 0; |
| 25 | |
| 26 | virtual void push(const T &Elt) = 0; |
| 27 | |
| 28 | virtual T pop() = 0; |
| 29 | |
| 30 | virtual void erase_if(function_ref<bool(T)> Pred) = 0; |
| 31 | |
| 32 | bool empty() { return !size(); } |
| 33 | }; |
| 34 | |
| 35 | LLVM_ABI std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> |
| 36 | getDefaultInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params, |
| 37 | ModuleAnalysisManager &MAM, Module &M); |
| 38 | |
| 39 | LLVM_ABI std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> |
| 40 | getInlineOrder(FunctionAnalysisManager &FAM, const InlineParams &Params, |
| 41 | ModuleAnalysisManager &MAM, Module &M); |
| 42 | |
| 43 | /// Used for dynamically loading instances of InlineOrder as plugins |
| 44 | /// |
| 45 | /// Plugins must implement an InlineOrderFactory, for an example refer to: |
| 46 | /// llvm/unittests/Analysis/InlineOrderPlugin/InlineOrderPlugin.cpp |
| 47 | /// |
| 48 | /// If a PluginInlineOrderAnalysis has been registered with the |
| 49 | /// current ModuleAnalysisManager, llvm::getInlineOrder returns an |
| 50 | /// InlineOrder created by the PluginInlineOrderAnalysis' Factory. |
| 51 | /// |
| 52 | class PluginInlineOrderAnalysis |
| 53 | : public AnalysisInfoMixin<PluginInlineOrderAnalysis> { |
| 54 | public: |
| 55 | LLVM_ABI static AnalysisKey Key; |
| 56 | |
| 57 | typedef std::unique_ptr<InlineOrder<std::pair<CallBase *, int>>> ( |
| 58 | *InlineOrderFactory)(FunctionAnalysisManager &FAM, |
| 59 | const InlineParams &Params, |
| 60 | ModuleAnalysisManager &MAM, Module &M); |
| 61 | |
| 62 | PluginInlineOrderAnalysis(InlineOrderFactory Factory) : Factory(Factory) { |
| 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 | |
| 71 | Result run(Module &, ModuleAnalysisManager &) { return {.Factory: Factory}; } |
| 72 | Result getResult() { return {.Factory: Factory}; } |
| 73 | |
| 74 | private: |
| 75 | InlineOrderFactory Factory; |
| 76 | }; |
| 77 | |
| 78 | } // namespace llvm |
| 79 | #endif // LLVM_ANALYSIS_INLINEORDER_H |
| 80 | |