diff options
author | David Green <david.green@arm.com> | 2018-11-05 14:54:34 +0000 |
---|---|---|
committer | David Green <david.green@arm.com> | 2018-11-05 14:54:34 +0000 |
commit | ba9f245b0df90a7214293f937ae0c6748c6503f0 (patch) | |
tree | f74f6ef7566dcac60d22d32f3680f32531862d14 /llvm/lib/Analysis/InlineCost.cpp | |
parent | 8d7c351799692a93621bb44ceec744c853c41942 (diff) | |
download | bcm5719-llvm-ba9f245b0df90a7214293f937ae0c6748c6503f0.tar.gz bcm5719-llvm-ba9f245b0df90a7214293f937ae0c6748c6503f0.zip |
[Inliner] Penalise inlining of calls with loops at Oz
We currently seem to underestimate the size of functions with loops in them,
both in terms of absolute code size and in the difficulties of dealing with
such code. (Calls, for example, can be tail merged to further reduce
codesize). At -Oz, we can then increase code size by inlining small loops
multiple times.
This attempts to penalise functions with loops at -Oz by adding a CallPenalty
for each top level loop in the function. It uses LI (and hence DT) to calculate
the number of loops. As we are dealing with minsize, the inline threshold is
small and functions at this point should be relatively small, making the
construction of these cheap.
Differential Revision: https://reviews.llvm.org/D52716
llvm-svn: 346134
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 923dbe59e86..a3347dbcb93 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -23,6 +23,7 @@ #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/CFG.h" #include "llvm/Analysis/InstructionSimplify.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/ValueTracking.h" @@ -30,6 +31,7 @@ #include "llvm/IR/CallSite.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/Dominators.h" #include "llvm/IR/GetElementPtrTypeIterator.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/InstVisitor.h" @@ -1885,6 +1887,24 @@ InlineResult CallAnalyzer::analyzeCall(CallSite CS) { if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall) return "noduplicate"; + // Loops generally act a lot like calls in that they act like barriers to + // movement, require a certain amount of setup, etc. So when optimising for + // size, we penalise any call sites that perform loops. We do this after all + // other costs here, so will likely only be dealing with relatively small + // functions (and hence DT and LI will hopefully be cheap). + if (Caller->optForMinSize()) { + DominatorTree DT(F); + LoopInfo LI(DT); + int NumLoops = 0; + for (Loop *L : LI) { + // Ignore loops that will not be executed + if (DeadBlocks.count(L->getHeader())) + continue; + NumLoops++; + } + Cost += NumLoops * InlineConstants::CallPenalty; + } + // We applied the maximum possible vector bonus at the beginning. Now, // subtract the excess bonus, if any, from the Threshold before // comparing against Cost. |