mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-18 12:29:21 +00:00
Speed up the predicate used to decide when to inline by caching the size
of callees between executions. On eon, in release mode, this changes the inliner from taking 11.5712s to taking 2.2066s. In debug mode, it went from taking 14.4148s to taking 7.0745s. In release mode, this is a 24.7% speedup of gccas, in debug mode, it's a total speedup of 11.7%. This also makes it slightly more aggressive. This could be because we are not judging the size of the functions quite as accurately as before. When we start looking at the performance of the generated code, this can be investigated further. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8893 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
2c9b913fc0
commit
884d6c4e10
@ -11,7 +11,17 @@
|
|||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct SimpleInliner : public Inliner {
|
// FunctionInfo - For each function, calculate the size of it in blocks and
|
||||||
|
// instructions.
|
||||||
|
struct FunctionInfo {
|
||||||
|
unsigned NumInsts, NumBlocks;
|
||||||
|
|
||||||
|
FunctionInfo() : NumInsts(0), NumBlocks(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SimpleInliner : public Inliner {
|
||||||
|
std::map<const Function*, FunctionInfo> CachedFunctionInfo;
|
||||||
|
public:
|
||||||
int getInlineCost(CallSite CS);
|
int getInlineCost(CallSite CS);
|
||||||
};
|
};
|
||||||
RegisterOpt<SimpleInliner> X("inline", "Function Integration/Inlining");
|
RegisterOpt<SimpleInliner> X("inline", "Function Integration/Inlining");
|
||||||
@ -19,7 +29,6 @@ namespace {
|
|||||||
|
|
||||||
Pass *createFunctionInliningPass() { return new SimpleInliner(); }
|
Pass *createFunctionInliningPass() { return new SimpleInliner(); }
|
||||||
|
|
||||||
|
|
||||||
// getInlineCost - The heuristic used to determine if we should inline the
|
// getInlineCost - The heuristic used to determine if we should inline the
|
||||||
// function call or not.
|
// function call or not.
|
||||||
//
|
//
|
||||||
@ -71,19 +80,25 @@ int SimpleInliner::getInlineCost(CallSite CS) {
|
|||||||
|
|
||||||
// Now that we have considered all of the factors that make the call site more
|
// Now that we have considered all of the factors that make the call site more
|
||||||
// likely to be inlined, look at factors that make us not want to inline it.
|
// likely to be inlined, look at factors that make us not want to inline it.
|
||||||
// As soon as the inline quality gets negative, bail out.
|
FunctionInfo &CalleeFI = CachedFunctionInfo[Callee];
|
||||||
|
|
||||||
// Look at the size of the callee. Each basic block counts as 20 units, and
|
// If we haven't calculated this information yet...
|
||||||
|
if (CalleeFI.NumBlocks == 0) {
|
||||||
|
unsigned NumInsts = 0, NumBlocks = 0;
|
||||||
|
|
||||||
|
// Look at the size of the callee. Each basic block counts as 20 units, and
|
||||||
|
// each instruction counts as 10.
|
||||||
|
for (Function::const_iterator BB = Callee->begin(), E = Callee->end();
|
||||||
|
BB != E; ++BB) {
|
||||||
|
NumInsts += BB->size();
|
||||||
|
NumBlocks++;
|
||||||
|
}
|
||||||
|
CalleeFI.NumBlocks = NumBlocks;
|
||||||
|
CalleeFI.NumInsts = NumInsts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look at the size of the callee. Each basic block counts as 21 units, and
|
||||||
// each instruction counts as 10.
|
// each instruction counts as 10.
|
||||||
for (Function::const_iterator BB = Callee->begin(), E = Callee->end();
|
InlineCost += CalleeFI.NumInsts*10 + CalleeFI.NumBlocks*20;
|
||||||
BB != E; ++BB)
|
|
||||||
InlineCost += BB->size()*10 + 20;
|
|
||||||
|
|
||||||
// Don't inline into something too big, which would make it bigger. Here, we
|
|
||||||
// count each basic block as a single unit.
|
|
||||||
for (Function::const_iterator BB = Caller->begin(), E = Caller->end();
|
|
||||||
BB != E; ++BB)
|
|
||||||
InlineCost++;
|
|
||||||
|
|
||||||
return InlineCost;
|
return InlineCost;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user