From 9ea9a6cf4100a99d99babf7a6b578697e5661d61 Mon Sep 17 00:00:00 2001 From: theraven Date: Sat, 1 May 2010 15:54:27 +0000 Subject: [PATCH] Made inlining conditional on inlining actually being sensible. --- opts/ClassMethodInliner.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/opts/ClassMethodInliner.cpp b/opts/ClassMethodInliner.cpp index 0a68bae..9741fb9 100644 --- a/opts/ClassMethodInliner.cpp +++ b/opts/ClassMethodInliner.cpp @@ -8,6 +8,7 @@ #include "llvm/GlobalVariable.h" #include "llvm/Support/IRBuilder.h" #include "llvm/Analysis/LoopInfo.h" +#include "llvm/Analysis/InlineCost.h" #include "IMPCacher.h" #include @@ -39,6 +40,8 @@ namespace virtual bool runOnModule(Module &M) { unsigned MessageSendMDKind = M.getContext().getMDKindID("GNUObjCMessageSend"); + InlineCostAnalyzer CA; + SmallPtrSet NeverInline; GNUstep::IMPCacher cacher = GNUstep::IMPCacher(M.getContext(), this); // FIXME: ILP64 @@ -79,7 +82,13 @@ namespace if (0 == method || method->isDeclaration()) { continue; } - cacher.SpeculativelyInline((*i).getInstruction(), method); + InlineCost IC = CA.getInlineCost((*i), method, NeverInline); + // FIXME: 200 is a random number. Pick a better one! + if (IC.isAlways() || (IC.isVariable() && IC.getValue() < 200)) { + cacher.SpeculativelyInline((*i).getInstruction(), method); + i->getInstruction()->setMetadata(MessageSendMDKind, 0); + modified = true; + } } } return modified;