[PATCH] D105349: [llvm][Inline] Add interface to return cost-benefit stuff
Liqiang Tao via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 2 07:43:08 PDT 2021
taolq created this revision.
Herald added subscribers: ChuanqiXu, haicheng, hiraditya, eraman.
taolq requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105349
Files:
llvm/include/llvm/Analysis/InlineCost.h
llvm/lib/Analysis/InlineCost.cpp
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -491,6 +491,9 @@
// Whether inlining is decided by cost-benefit analysis.
bool DecidedByCostBenefit = false;
+ // The cost-benefit pair computed by cost-benefit analysis.
+ std::pair<APInt, APInt> CostBenefitPair;
+
bool SingleBB = true;
unsigned SROACostSavings = 0;
@@ -788,6 +791,8 @@
// savings threshold.
Size = Size > InlineSizeAllowance ? Size - InlineSizeAllowance : 1;
+ CostBenefitPair = std::make_pair(APInt(128, Size), CycleSavings);
+
// Return true if the savings justify the cost of inlining. Specifically,
// we evaluate the following inequality:
//
@@ -935,6 +940,7 @@
virtual ~InlineCostCallAnalyzer() {}
int getThreshold() { return Threshold; }
int getCost() { return Cost; }
+ std::pair<APInt, APInt> getCostBenefitPair() { return CostBenefitPair; }
bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; }
};
} // namespace
@@ -2505,6 +2511,47 @@
return CA.getCost();
}
+Optional<std::pair<APInt, APInt>> llvm::getInlineCostBenefitPair(
+ CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
+ function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE) {
+
+ InlineCostCallAnalyzer CA(*Call.getCalledFunction(), Call, Params, CalleeTTI,
+ GetAssumptionCache, GetBFI, PSI, ORE, true,
+ /*IgnoreThreshold*/ true);
+ auto R = CA.analyze();
+ if (!R.isSuccess())
+ return None;
+ return CA.getCostBenefitPair();
+}
+
+Optional<std::pair<APInt, APInt>>
+llvm::getInlineCostBenefitPair(CallBase &CB, FunctionAnalysisManager &FAM,
+ const InlineParams &Params) {
+ Function &Caller = *CB.getCaller();
+ ProfileSummaryInfo *PSI =
+ FAM.getResult<ModuleAnalysisManagerFunctionProxy>(Caller)
+ .getCachedResult<ProfileSummaryAnalysis>(
+ *CB.getParent()->getParent()->getParent());
+
+ auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(Caller);
+ auto GetAssumptionCache = [&](Function &F) -> AssumptionCache & {
+ return FAM.getResult<AssumptionAnalysis>(F);
+ };
+ auto GetBFI = [&](Function &F) -> BlockFrequencyInfo & {
+ return FAM.getResult<BlockFrequencyAnalysis>(F);
+ };
+
+ Function &Callee = *CB.getCalledFunction();
+ auto &CalleeTTI = FAM.getResult<TargetIRAnalysis>(Callee);
+ bool RemarksEnabled =
+ Callee.getContext().getDiagHandlerPtr()->isMissedOptRemarkEnabled(
+ DEBUG_TYPE);
+ return getInlineCostBenefitPair(CB, Params, CalleeTTI, GetAssumptionCache,
+ GetBFI, PSI, RemarksEnabled ? &ORE : nullptr);
+}
+
Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI,
function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
Index: llvm/include/llvm/Analysis/InlineCost.h
===================================================================
--- llvm/include/llvm/Analysis/InlineCost.h
+++ llvm/include/llvm/Analysis/InlineCost.h
@@ -270,6 +270,16 @@
ProfileSummaryInfo *PSI = nullptr,
OptimizationRemarkEmitter *ORE = nullptr);
+Optional<std::pair<APInt, APInt>> getInlineCostBenefitPair(
+ CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI,
+ function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
+ function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
+ ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE);
+
+Optional<std::pair<APInt, APInt>>
+getInlineCostBenefitPair(CallBase &CB, FunctionAnalysisManager &FAM,
+ const InlineParams &Params);
+
/// Minimal filter to detect invalid constructs for inlining.
InlineResult isInlineViable(Function &Callee);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105349.356170.patch
Type: text/x-patch
Size: 4078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210702/8d1be007/attachment.bin>
More information about the llvm-commits
mailing list