[PATCH] D139140: [ModuleInliner] Add MLPriority
Kazu Hirata via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 1 13:20:09 PST 2022
kazu created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This patch adds MLPriority as the first step toward the ML-based
function inlining with the module inliner.
For now, MLPriority is completely identical to CostPriority.
Once this patch lands, I'm planning to:
- integrate NoInferenceModelRunner,
- memoize the priority computation so that the priority remains the same for given values of metrics even with the noise injected during training, and
- port/take more features into account.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D139140
Files:
llvm/lib/Analysis/InlineOrder.cpp
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;
+};
+
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.479401.patch
Type: text/x-patch
Size: 2213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221201/3c36e699/attachment.bin>
More information about the llvm-commits
mailing list