diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-12-05 17:23:27 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-12-05 17:23:27 +0000 |
commit | 13231037f0e9cc4eeb7f0454c35c9c4100760bac (patch) | |
tree | 7f232a6eb23aec6e685e1c30d195f7cbbd638784 /llvm/lib/VMCore/Value.cpp | |
parent | 603825163f4633fae22ec048aa6f17e34f8f6323 (diff) | |
download | bcm5719-llvm-13231037f0e9cc4eeb7f0454c35c9c4100760bac.tar.gz bcm5719-llvm-13231037f0e9cc4eeb7f0454c35c9c4100760bac.zip |
Add a little heuristic to Value::isUsedInBasicBlock to speed it up for small basic blocks.
- Calling getUser in a loop is much more expensive than iterating over a few instructions.
- Use it instead of the open-coded loop in AddrModeMatcher.
- 5% speedup on ARMDisassembler.cpp Release builds.
llvm-svn: 145810
Diffstat (limited to 'llvm/lib/VMCore/Value.cpp')
-rw-r--r-- | llvm/lib/VMCore/Value.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index 291df917706..a5f1918e55d 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -108,6 +108,19 @@ bool Value::hasNUsesOrMore(unsigned N) const { /// isUsedInBasicBlock - Return true if this value is used in the specified /// basic block. bool Value::isUsedInBasicBlock(const BasicBlock *BB) const { + // Start by scanning over the instructions looking for a use before we start + // the expensive use iteration. + unsigned MaxBlockSize = 3; + for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { + if (std::find(I->op_begin(), I->op_end(), this) != I->op_end()) + return true; + if (MaxBlockSize-- == 0) // If the block is larger fall back to use_iterator + break; + } + + if (MaxBlockSize != 0) // We scanned the entire block and found no use. + return false; + for (const_use_iterator I = use_begin(), E = use_end(); I != E; ++I) { const Instruction *User = dyn_cast<Instruction>(*I); if (User && User->getParent() == BB) |