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 <utility> 14 15 namespace llvm { 16 class CallBase; 17 template <typename Fn> class function_ref; 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 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 61 PluginInlineOrderAnalysis(InlineOrderFactory Factory) : Factory(Factory) { 62 assert(Factory != nullptr && 63 "The plugin inline order factory should not be a null pointer."); 64 } 65 66 struct Result { 67 InlineOrderFactory Factory; 68 }; 69 70 Result run(Module &, ModuleAnalysisManager &) { return {Factory}; } 71 Result getResult() { return {Factory}; } 72 73 private: 74 InlineOrderFactory Factory; 75 }; 76 77 } // namespace llvm 78 #endif // LLVM_ANALYSIS_INLINEORDER_H 79