[llvm] r265852 - Refactor Threshold computation. NFC.
Easwaran Raman via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 8 14:28:02 PDT 2016
Author: eraman
Date: Fri Apr 8 16:28:02 2016
New Revision: 265852
URL: http://llvm.org/viewvc/llvm-project?rev=265852&view=rev
Log:
Refactor Threshold computation. NFC.
This is part of changes reviewed in http://reviews.llvm.org/D17584.
Modified:
llvm/trunk/lib/Analysis/InlineCost.cpp
Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=265852&r1=265851&r2=265852&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Fri Apr 8 16:28:02 2016
@@ -154,6 +154,9 @@ class CallAnalyzer : public InstVisitor<
/// analysis.
void updateThreshold(CallSite CS, Function &Callee);
+ /// Return true if size growth is allowed when inlining the callee at CS.
+ bool allowSizeGrowth(CallSite CS);
+
// Custom analysis routines.
bool analyzeBlock(BasicBlock *BB, SmallPtrSetImpl<const Value *> &EphValues);
@@ -572,7 +575,39 @@ bool CallAnalyzer::isKnownNonNullInCalle
return false;
}
+bool CallAnalyzer::allowSizeGrowth(CallSite CS) {
+ // If the normal destination of the invoke or the parent block of the call
+ // site is unreachable-terminated, there is little point in inlining this
+ // unless there is literally zero cost.
+ // FIXME: Note that it is possible that an unreachable-terminated block has a
+ // hot entry. For example, in below scenario inlining hot_call_X() may be
+ // beneficial :
+ // main() {
+ // hot_call_1();
+ // ...
+ // hot_call_N()
+ // exit(0);
+ // }
+ // For now, we are not handling this corner case here as it is rare in real
+ // code. In future, we should elaborate this based on BPI and BFI in more
+ // general threshold adjusting heuristics in updateThreshold().
+ Instruction *Instr = CS.getInstruction();
+ if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
+ if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
+ return false;
+ } else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
+ return false;
+
+ return true;
+}
+
void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) {
+ // If no size growth is allowed for this inlining, set Threshold to 0.
+ if (!allowSizeGrowth(CS)) {
+ Threshold = 0;
+ return;
+ }
+
// If -inline-threshold is not given, listen to the optsize and minsize
// attributes when they would decrease the threshold.
Function *Caller = CS.getCaller();
@@ -1214,28 +1249,6 @@ bool CallAnalyzer::analyzeCall(CallSite
if (OnlyOneCallAndLocalLinkage)
Cost += InlineConstants::LastCallToStaticBonus;
- // If the normal destination of the invoke or the parent block of the call
- // site is unreachable-terminated, there is little point in inlining this
- // unless there is literally zero cost.
- // FIXME: Note that it is possible that an unreachable-terminated block has a
- // hot entry. For example, in below scenario inlining hot_call_X() may be
- // beneficial :
- // main() {
- // hot_call_1();
- // ...
- // hot_call_N()
- // exit(0);
- // }
- // For now, we are not handling this corner case here as it is rare in real
- // code. In future, we should elaborate this based on BPI and BFI in more
- // general threshold adjusting heuristics in updateThreshold().
- Instruction *Instr = CS.getInstruction();
- if (InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
- if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
- Threshold = 0;
- } else if (isa<UnreachableInst>(Instr->getParent()->getTerminator()))
- Threshold = 0;
-
// If this function uses the coldcc calling convention, prefer not to inline
// it.
if (F.getCallingConv() == CallingConv::Cold)
More information about the llvm-commits
mailing list