diff options
author | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2013-05-15 21:43:59 +0200 |
---|---|---|
committer | Abdoulaye Walsimou Gaye <awg@embtoolkit.org> | 2013-05-15 21:43:59 +0200 |
commit | b2e3c7da703d4c3dda41d4f1e18cd976e6c4381a (patch) | |
tree | 7462cd2988228ae24c40b37a9382d35874bbf099 /lib/IR/Value.cpp | |
parent | 23d8d191eff180ba312a4d1b4fec8597e5a988d5 (diff) | |
parent | 4ef61f2ad4ff509ee05c7051d359009511f81226 (diff) | |
download | llvm-b2e3c7da703d4c3dda41d4f1e18cd976e6c4381a.tar.gz llvm-b2e3c7da703d4c3dda41d4f1e18cd976e6c4381a.tar.bz2 llvm-b2e3c7da703d4c3dda41d4f1e18cd976e6c4381a.tar.xz |
Merge branch 'master' into embtk-support-masterembtk-support-master
Diffstat (limited to 'lib/IR/Value.cpp')
-rw-r--r-- | lib/IR/Value.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/IR/Value.cpp b/lib/IR/Value.cpp index 89a3c0578c..81d7efa774 100644 --- a/lib/IR/Value.cpp +++ b/lib/IR/Value.cpp @@ -112,21 +112,20 @@ 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()) + // This can be computed either by scanning the instructions in BB, or by + // scanning the use list of this Value. Both lists can be very long, but + // usually one is quite short. + // + // Scan both lists simultaneously until one is exhausted. This limits the + // search to the shorter list. + BasicBlock::const_iterator BI = BB->begin(), BE = BB->end(); + const_use_iterator UI = use_begin(), UE = use_end(); + for (; BI != BE && UI != UE; ++BI, ++UI) { + // Scan basic block: Check if this Value is used by the instruction at BI. + if (std::find(BI->op_begin(), BI->op_end(), this) != BI->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); + // Scan use list: Check if the use at UI is in BB. + const Instruction *User = dyn_cast<Instruction>(*UI); if (User && User->getParent() == BB) return true; } |