diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-13 19:58:07 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-13 19:58:07 +0000 |
commit | e7f0ed5aceed27d6f46521ec6e4c139986c5b489 (patch) | |
tree | 902599507907be4c4ef07b59809a98730ca7a988 /include/llvm/Analysis | |
parent | d452ea6a6417e4ce7e110249c5e74bcc6ab1ae49 (diff) | |
download | external_llvm-e7f0ed5aceed27d6f46521ec6e4c139986c5b489.zip external_llvm-e7f0ed5aceed27d6f46521ec6e4c139986c5b489.tar.gz external_llvm-e7f0ed5aceed27d6f46521ec6e4c139986c5b489.tar.bz2 |
Split code not specific to Function inlining out into a separate class,
named CodeMetrics. Move it to be a non-nested class. Rename RegionInfo
back to FunctionInfo.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84013 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r-- | include/llvm/Analysis/InlineCost.h | 80 |
1 files changed, 44 insertions, 36 deletions
diff --git a/include/llvm/Analysis/InlineCost.h b/include/llvm/Analysis/InlineCost.h index e26edfb..d723e75 100644 --- a/include/llvm/Analysis/InlineCost.h +++ b/include/llvm/Analysis/InlineCost.h @@ -28,6 +28,40 @@ namespace llvm { template<class PtrType, unsigned SmallSize> class SmallPtrSet; + // CodeMetrics - Calculate size and a few similar metrics for a set of + // basic blocks. + struct CodeMetrics { + /// NeverInline - True if this callee should never be inlined into a + /// caller. + bool NeverInline; + + /// usesDynamicAlloca - True if this function calls alloca (in the C sense). + bool usesDynamicAlloca; + + /// NumInsts, NumBlocks - Keep track of how large each function is, which + /// is used to estimate the code size cost of inlining it. + unsigned NumInsts, NumBlocks; + + /// NumVectorInsts - Keep track of how many instructions produce vector + /// values. The inliner is being more aggressive with inlining vector + /// kernels. + unsigned NumVectorInsts; + + /// NumRets - Keep track of how many Ret instructions the block contains. + unsigned NumRets; + + CodeMetrics() : NeverInline(false), usesDynamicAlloca(false), NumInsts(0), + NumBlocks(0), NumVectorInsts(0), NumRets(0) {} + + /// analyzeBasicBlock - Add information about the specified basic block + /// to the current structure. + void analyzeBasicBlock(const BasicBlock *BB); + + /// analyzeFunction - Add information about the specified function + /// to the current structure. + void analyzeFunction(Function *F); + }; + namespace InlineConstants { // Various magic constants used to adjust heuristics. const int CallPenalty = 5; @@ -97,58 +131,32 @@ namespace llvm { : ConstantWeight(CWeight), AllocaWeight(AWeight) {} }; - // RegionInfo - Calculate size and a few related metrics for a set of - // basic blocks. - struct RegionInfo { - /// NeverInline - True if this callee should never be inlined into a - /// caller. - bool NeverInline; - - /// usesDynamicAlloca - True if this function calls alloca (in the C sense). - bool usesDynamicAlloca; - - /// NumInsts, NumBlocks - Keep track of how large each function is, which - /// is used to estimate the code size cost of inlining it. - unsigned NumInsts, NumBlocks; - - /// NumVectorInsts - Keep track of how many instructions produce vector - /// values. The inliner is being more aggressive with inlining vector - /// kernels. - unsigned NumVectorInsts; - - /// NumRets - Keep track of how many Ret instructions the block contains. - unsigned NumRets; + struct FunctionInfo { + CodeMetrics Metrics; /// ArgumentWeights - Each formal argument of the function is inspected to /// see if it is used in any contexts where making it a constant or alloca /// would reduce the code size. If so, we add some value to the argument /// entry here. std::vector<ArgInfo> ArgumentWeights; - - RegionInfo() : NeverInline(false), usesDynamicAlloca(false), NumInsts(0), - NumBlocks(0), NumVectorInsts(0), NumRets(0) {} - - /// analyzeBasicBlock - Add information about the specified basic block - /// to the current structure. - void analyzeBasicBlock(const BasicBlock *BB); - - /// analyzeFunction - Add information about the specified function - /// to the current structure. - void analyzeFunction(Function *F); - + /// CountCodeReductionForConstant - Figure out an approximation for how /// many instructions will be constant folded if the specified value is /// constant. unsigned CountCodeReductionForConstant(Value *V); - + /// CountCodeReductionForAlloca - Figure out an approximation of how much /// smaller the function will be if it is inlined into a context where an /// argument becomes an alloca. /// unsigned CountCodeReductionForAlloca(Value *V); + + /// analyzeFunction - Add information about the specified function + /// to the current structure. + void analyzeFunction(Function *F); }; - std::map<const Function *, RegionInfo> CachedFunctionInfo; + std::map<const Function *, FunctionInfo> CachedFunctionInfo; public: @@ -164,7 +172,7 @@ namespace llvm { /// resetCachedFunctionInfo - erase any cached cost info for this function. void resetCachedCostInfo(Function* Caller) { - CachedFunctionInfo[Caller].NumBlocks = 0; + CachedFunctionInfo[Caller].Metrics.NumBlocks = 0; } }; } |