diff --git a/llvm/lib/Analysis/InlineOrder.cpp b/llvm/lib/Analysis/InlineOrder.cpp --- a/llvm/lib/Analysis/InlineOrder.cpp +++ b/llvm/lib/Analysis/InlineOrder.cpp @@ -22,7 +22,7 @@ #define DEBUG_TYPE "inline-order" -enum class InlinePriorityMode : int { Size, Cost, CostBenefit }; +enum class InlinePriorityMode : int { Size, Cost, CostBenefit, ML }; static cl::opt UseInlinePriority( "inline-priority-mode", cl::init(InlinePriorityMode::Size), cl::Hidden, @@ -32,7 +32,9 @@ clEnumValN(InlinePriorityMode::Cost, "cost", "Use inline cost priority."), clEnumValN(InlinePriorityMode::CostBenefit, "cost-benefit", - "Use cost-benefit ratio."))); + "Use cost-benefit ratio."), + clEnumValN(InlinePriorityMode::ML, "ml", + "Use ML."))); static cl::opt ModuleInlinerTopPriorityThreshold( "moudle-inliner-top-priority-threshold", cl::Hidden, cl::init(0), @@ -175,6 +177,26 @@ Optional CostBenefit; }; +class MLPriority { +public: + MLPriority() = default; + MLPriority(const CallBase *CB, FunctionAnalysisManager &FAM, + const InlineParams &Params) { + auto IC = getInlineCostWrapper(const_cast(*CB), FAM, Params); + if (IC.isVariable()) + Cost = IC.getCost(); + else + Cost = IC.isNever() ? INT_MAX : INT_MIN; + } + + static bool isMoreDesirable(const MLPriority &P1, const MLPriority &P2) { + return P1.Cost < P2.Cost; + } + +private: + int Cost = INT_MAX; +}; + template class PriorityInlineOrder : public InlineOrder> { using T = std::pair; @@ -274,6 +296,10 @@ LLVM_DEBUG( dbgs() << " Current used priority: cost-benefit priority ---- \n"); return std::make_unique>(FAM, Params); + case InlinePriorityMode::ML: + LLVM_DEBUG( + dbgs() << " Current used priority: ML priority ---- \n"); + return std::make_unique>(FAM, Params); } return nullptr; } diff --git a/llvm/test/Transforms/Inline/module-inliner-basic.ll b/llvm/test/Transforms/Inline/module-inliner-basic.ll --- a/llvm/test/Transforms/Inline/module-inliner-basic.ll +++ b/llvm/test/Transforms/Inline/module-inliner-basic.ll @@ -2,6 +2,7 @@ ; RUN: opt -passes=module-inline -inline-priority-mode=size -S < %s | FileCheck %s ; RUN: opt -passes=module-inline -inline-priority-mode=cost -S < %s | FileCheck %s ; RUN: opt -passes=module-inline -inline-priority-mode=cost-benefit -S < %s | FileCheck %s +; RUN: opt -passes=module-inline -inline-priority-mode=ml -S < %s | FileCheck %s define i32 @callee(i32 %a) { entry: