diff options
author | Chris Lattner <sabre@nondot.org> | 2006-09-09 20:40:44 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-09-09 20:40:44 +0000 |
commit | 7b166d9969670665d9f093f20ed3381057427256 (patch) | |
tree | 6ba34deed01a94e7e9558bdc57ee0574597a958b /lib/Transforms | |
parent | 8e49e08f4b82ce9fa88a5342ae0f40532a022486 (diff) | |
download | llvm-7b166d9969670665d9f093f20ed3381057427256.tar.gz llvm-7b166d9969670665d9f093f20ed3381057427256.tar.bz2 llvm-7b166d9969670665d9f093f20ed3381057427256.tar.xz |
Make inlining costs more accurate.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30231 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/InlineSimple.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index 6436684835..c2aa4cb380 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -138,9 +138,32 @@ void FunctionInfo::analyzeFunction(Function *F) { // each instruction counts as 10. for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { for (BasicBlock::const_iterator II = BB->begin(), E = BB->end(); - II != E; ++II) - if (!isa<DbgInfoIntrinsic>(II)) - ++NumInsts; + II != E; ++II) { + if (isa<DbgInfoIntrinsic>(II)) continue; // Debug intrinsics don't count. + + // Noop casts don't count. + if (const CastInst *CI = dyn_cast<CastInst>(II)) { + const Type *OpTy = CI->getOperand(0)->getType(); + if (CI->getType()->isLosslesslyConvertibleTo(OpTy)) + continue; + if ((isa<PointerType>(CI->getType()) && OpTy->isInteger()) || + (isa<PointerType>(OpTy) && CI->getType()->isInteger())) + continue; // ptr <-> int is *probably* noop cast. + } else if (const GetElementPtrInst *GEPI = + dyn_cast<GetElementPtrInst>(II)) { + // If a GEP has all constant indices, it will probably be folded with + // a load/store. + bool AllConstant = true; + for (unsigned i = 1, e = GEPI->getNumOperands(); i != e; ++i) + if (!isa<ConstantInt>(GEPI->getOperand(i))) { + AllConstant = false; + break; + } + if (AllConstant) continue; + } + + ++NumInsts; + } ++NumBlocks; } |