diff options
author | Gabor Greif <ggreif@gmail.com> | 2010-04-14 18:13:29 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2010-04-14 18:13:29 +0000 |
commit | fefdd426440c365236e0ffb93e86258cfb7e655e (patch) | |
tree | 364c30036ea7afdcd3d69efef6b829d1f33b33a6 | |
parent | fea9ba18ff66ce134a3d965c01885f92b375abd0 (diff) | |
download | bcm5719-llvm-fefdd426440c365236e0ffb93e86258cfb7e655e.tar.gz bcm5719-llvm-fefdd426440c365236e0ffb93e86258cfb7e655e.zip |
performance: cache the dereferenced use_iterator
llvm-svn: 101265
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index c599e907eb6..da1238685bc 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -24,28 +24,29 @@ using namespace llvm; unsigned InlineCostAnalyzer::FunctionInfo:: CountCodeReductionForConstant(Value *V) { unsigned Reduction = 0; - for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E; ++UI) - if (isa<BranchInst>(*UI) || isa<SwitchInst>(*UI)) { + for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){ + User *U = *UI; + if (isa<BranchInst>(U) || isa<SwitchInst>(U)) { // We will be able to eliminate all but one of the successors. - const TerminatorInst &TI = cast<TerminatorInst>(**UI); + const TerminatorInst &TI = cast<TerminatorInst>(*U); const unsigned NumSucc = TI.getNumSuccessors(); unsigned Instrs = 0; for (unsigned I = 0; I != NumSucc; ++I) Instrs += Metrics.NumBBInsts[TI.getSuccessor(I)]; // We don't know which blocks will be eliminated, so use the average size. Reduction += InlineConstants::InstrCost*Instrs*(NumSucc-1)/NumSucc; - } else if (CallInst *CI = dyn_cast<CallInst>(*UI)) { + } else if (CallInst *CI = dyn_cast<CallInst>(U)) { // Turning an indirect call into a direct call is a BIG win if (CI->getCalledValue() == V) Reduction += InlineConstants::IndirectCallBonus; - } else if (InvokeInst *II = dyn_cast<InvokeInst>(*UI)) { + } else if (InvokeInst *II = dyn_cast<InvokeInst>(U)) { // Turning an indirect call into a direct call is a BIG win if (II->getCalledValue() == V) Reduction += InlineConstants::IndirectCallBonus; } else { // Figure out if this instruction will be removed due to simple constant // propagation. - Instruction &Inst = cast<Instruction>(**UI); + Instruction &Inst = cast<Instruction>(*U); // We can't constant propagate instructions which have effects or // read memory. @@ -74,7 +75,7 @@ CountCodeReductionForConstant(Value *V) { Reduction += CountCodeReductionForConstant(&Inst); } } - + } return Reduction; } |