summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2010-03-09 22:17:11 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2010-03-09 22:17:11 +0000
commit741dec43e4e73a526c16939a68c65a851813f431 (patch)
tree83abd140ef1dde685e66ce5c6d396f0818ca6d70 /llvm/lib/Analysis
parent5fba36cc1bcc02beaf20b28ecb42e0e3e5cae050 (diff)
downloadbcm5719-llvm-741dec43e4e73a526c16939a68c65a851813f431.tar.gz
bcm5719-llvm-741dec43e4e73a526c16939a68c65a851813f431.zip
Try to keep the cached inliner costs around for a bit longer for big functions.
The Caller cost info would be reset everytime a callee was inlined. If the caller has lots of calls and there is some mutual recursion going on, the caller cost info could be calculated many times. This patch reduces inliner runtime from 240s to 0.5s for a function with 20000 small function calls. llvm-svn: 98089
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/InlineCost.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 140e7daa6d3..09e66487c7a 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -383,3 +383,39 @@ float InlineCostAnalyzer::getInlineFudgeFactor(CallSite CS) {
Factor += 1.5f;
return Factor;
}
+
+/// growCachedCostInfo - update the cached cost info for Caller after Callee has
+/// been inlined.
+void
+InlineCostAnalyzer::growCachedCostInfo(Function* Caller, Function* Callee) {
+ FunctionInfo &CallerFI = CachedFunctionInfo[Caller];
+
+ // For small functions we prefer to recalculate the cost for better accuracy.
+ if (!CallerFI.Metrics.NumBlocks || CallerFI.Metrics.NumInsts < 100) {
+ resetCachedCostInfo(Caller);
+ return;
+ }
+
+ // For large functions, we can save a lot of computation time by skipping
+ // recalculations.
+ if (CallerFI.Metrics.NumCalls > 0)
+ --CallerFI.Metrics.NumCalls;
+
+ if (Callee) {
+ FunctionInfo &CalleeFI = CachedFunctionInfo[Callee];
+ if (!CalleeFI.Metrics.NumBlocks) {
+ resetCachedCostInfo(Caller);
+ return;
+ }
+ CallerFI.Metrics.NeverInline |= CalleeFI.Metrics.NeverInline;
+ CallerFI.Metrics.usesDynamicAlloca |= CalleeFI.Metrics.usesDynamicAlloca;
+
+ CallerFI.Metrics.NumInsts += CalleeFI.Metrics.NumInsts;
+ CallerFI.Metrics.NumBlocks += CalleeFI.Metrics.NumBlocks;
+ CallerFI.Metrics.NumCalls += CalleeFI.Metrics.NumCalls;
+ CallerFI.Metrics.NumVectorInsts += CalleeFI.Metrics.NumVectorInsts;
+ CallerFI.Metrics.NumRets += CalleeFI.Metrics.NumRets;
+ }
+ // We are not updating the argumentweights. We have already determined that
+ // Caller is a fairly large function, so we accept the loss of precision.
+}
OpenPOWER on IntegriCloud