[PATCH] D139140: [ModuleInliner] Add MLPriority
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 13:44:52 PST 2022
kazu updated this revision to Diff 479740.
kazu added a comment.
Add a test. Also, initialize Cost.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139140/new/
https://reviews.llvm.org/D139140
Files:
llvm/lib/Analysis/InlineOrder.cpp
llvm/test/Transforms/Inline/module-inliner-basic.ll
Index: llvm/test/Transforms/Inline/module-inliner-basic.ll
===================================================================
--- llvm/test/Transforms/Inline/module-inliner-basic.ll
+++ 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:
Index: llvm/lib/Analysis/InlineOrder.cpp
===================================================================
--- llvm/lib/Analysis/InlineOrder.cpp
+++ 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<InlinePriorityMode> 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<int> ModuleInlinerTopPriorityThreshold(
"moudle-inliner-top-priority-threshold", cl::Hidden, cl::init(0),
@@ -175,6 +177,26 @@
Optional<CostBenefitPair> CostBenefit;
};
+class MLPriority {
+public:
+ MLPriority() = default;
+ MLPriority(const CallBase *CB, FunctionAnalysisManager &FAM,
+ const InlineParams &Params) {
+ auto IC = getInlineCostWrapper(const_cast<CallBase &>(*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 <typename PriorityT>
class PriorityInlineOrder : public InlineOrder<std::pair<CallBase *, int>> {
using T = std::pair<CallBase *, int>;
@@ -274,6 +296,10 @@
LLVM_DEBUG(
dbgs() << " Current used priority: cost-benefit priority ---- \n");
return std::make_unique<PriorityInlineOrder<CostBenefitPriority>>(FAM, Params);
+ case InlinePriorityMode::ML:
+ LLVM_DEBUG(
+ dbgs() << " Current used priority: ML priority ---- \n");
+ return std::make_unique<PriorityInlineOrder<MLPriority>>(FAM, Params);
}
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139140.479740.patch
Type: text/x-patch
Size: 2886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/6d4e73be/attachment.bin>
More information about the llvm-commits
mailing list