diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-31 14:54:17 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-31 14:54:17 +0000 |
commit | a2aabe38ae442fa00f51526a8a149ecde417c83c (patch) | |
tree | bcf9ac94ea730cec145ba3a484cee46adaa106f9 /lib/Transforms/Scalar/LoopUnrollPass.cpp | |
parent | b56c966019db6b186221ff7dd695603ac1d0bc70 (diff) |
Replace LoopUnrollPass.cpp's custom code-size estimation code using
the new common CodeMetrics code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85663 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/LoopUnrollPass.cpp')
-rw-r--r-- | lib/Transforms/Scalar/LoopUnrollPass.cpp | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index 094a86e4fb..c2bf9f2c58 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -16,6 +16,7 @@ #include "llvm/IntrinsicInst.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Analysis/LoopPass.h" +#include "llvm/Analysis/InlineCost.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -76,37 +77,11 @@ Pass *llvm::createLoopUnrollPass() { return new LoopUnroll(); } /// ApproximateLoopSize - Approximate the size of the loop. static unsigned ApproximateLoopSize(const Loop *L) { - unsigned Size = 0; + CodeMetrics Metrics; for (Loop::block_iterator I = L->block_begin(), E = L->block_end(); - I != E; ++I) { - BasicBlock *BB = *I; - Instruction *Term = BB->getTerminator(); - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { - if (isa<PHINode>(I) && BB == L->getHeader()) { - // Ignore PHI nodes in the header. - } else if (I->hasOneUse() && I->use_back() == Term) { - // Ignore instructions only used by the loop terminator. - } else if (isa<DbgInfoIntrinsic>(I)) { - // Ignore debug instructions - } else if (isa<GetElementPtrInst>(I) && I->hasOneUse()) { - // Ignore GEP as they generally are subsumed into a load or store. - } else if (isa<CallInst>(I)) { - // Estimate size overhead introduced by call instructions which - // is higher than other instructions. Here 3 and 10 are magic - // numbers that help one isolated test case from PR2067 without - // negatively impacting measured benchmarks. - Size += isa<IntrinsicInst>(I) ? 3 : 10; - } else { - ++Size; - } - - // TODO: Ignore expressions derived from PHI and constants if inval of phi - // is a constant, or if operation is associative. This will get induction - // variables. - } - } - - return Size; + I != E; ++I) + Metrics.analyzeBasicBlock(*I); + return Metrics.NumInsts; } bool LoopUnroll::runOnLoop(Loop *L, LPPassManager &LPM) { |