diff options
author | Kazu Hirata <kazu@google.com> | 2022-09-17 20:59:54 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2022-09-17 20:59:54 -0700 |
commit | cf355bf36e39f38c08606a5b91a2cc038e28c700 (patch) | |
tree | dd48243ce742d3532ce06d6ccdd870dc3b447170 /llvm/lib/Analysis/InlineCost.cpp | |
parent | 97b5736975f30d64cf6c447b0f0cb319134fa60b (diff) | |
download | llvm-cf355bf36e39f38c08606a5b91a2cc038e28c700.zip llvm-cf355bf36e39f38c08606a5b91a2cc038e28c700.tar.gz llvm-cf355bf36e39f38c08606a5b91a2cc038e28c700.tar.bz2 |
[Analysis] Introduce isSoleCallToLocalFunction (NFC)
We check to see if a given CallBase is a sole call to a local function
at multiple places in InlineCost.cpp. This patch factors out the
common code.
Differential Revision: https://reviews.llvm.org/D134114
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 86e0b4b..e193cee 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -1063,6 +1063,13 @@ public: bool wasDecidedByCostThreshold() const { return DecidedByCostThreshold; } }; +// Return true if CB is the sole call to local function Callee. +static bool isSoleCallToLocalFunction(const CallBase &CB, + const Function &Callee) { + return Callee.hasLocalLinkage() && Callee.hasOneLiveUse() && + &Callee == CB.getCalledFunction(); +} + class InlineCostFeaturesAnalyzer final : public CallAnalyzer { private: InlineCostFeatures Cost = {}; @@ -1236,8 +1243,7 @@ private: (F.getCallingConv() == CallingConv::Cold)); set(InlineCostFeatureIndex::LastCallToStaticBonus, - (F.hasLocalLinkage() && F.hasOneLiveUse() && - &F == CandidateCall.getCalledFunction())); + isSoleCallToLocalFunction(CandidateCall, F)); // FIXME: we shouldn't repeat this logic in both the Features and Cost // analyzer - instead, we should abstract it to a common method in the @@ -1913,12 +1919,10 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) { SingleBBBonus = Threshold * SingleBBBonusPercent / 100; VectorBonus = Threshold * VectorBonusPercent / 100; - bool OnlyOneCallAndLocalLinkage = F.hasLocalLinkage() && F.hasOneLiveUse() && - &F == Call.getCalledFunction(); // If there is only one call of the function, and it has internal linkage, // the cost of inlining it drops dramatically. It may seem odd to update // Cost in updateThreshold, but the bonus depends on the logic in this method. - if (OnlyOneCallAndLocalLinkage) + if (isSoleCallToLocalFunction(Call, F)) Cost -= LastCallToStaticBonus; } @@ -2712,12 +2716,10 @@ InlineResult CallAnalyzer::analyze() { onBlockAnalyzed(BB); } - bool OnlyOneCallAndLocalLinkage = F.hasLocalLinkage() && F.hasOneLiveUse() && - &F == CandidateCall.getCalledFunction(); // If this is a noduplicate call, we can still inline as long as // inlining this would cause the removal of the caller (so the instruction // is not actually duplicated, just moved). - if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall) + if (!isSoleCallToLocalFunction(CandidateCall, F) && ContainsNoDuplicateCall) return InlineResult::failure("noduplicate"); // If the callee's stack size exceeds the user-specified threshold, |