Speed up Loop::isLCSSAForm by using a hash table instead of a sorted vector.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34900 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2007-03-04 04:06:39 +00:00
parent ab8fea5283
commit b1f5d8bf6f

View File

@ -22,6 +22,7 @@
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Support/Streams.h" #include "llvm/Support/Streams.h"
#include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"
#include <algorithm> #include <algorithm>
#include <ostream> #include <ostream>
using namespace llvm; using namespace llvm;
@ -565,25 +566,22 @@ Value *Loop::getTripCount() const {
bool Loop::isLCSSAForm() const { bool Loop::isLCSSAForm() const {
// Sort the blocks vector so that we can use binary search to do quick // Sort the blocks vector so that we can use binary search to do quick
// lookups. // lookups.
std::vector<BasicBlock*> LoopBBs(block_begin(), block_end()); SmallPtrSet<BasicBlock*, 16> LoopBBs(block_begin(), block_end());
std::sort(LoopBBs.begin(), LoopBBs.end());
for (unsigned i = 0, e = LoopBBs.size(); i != e; ++i) { for (block_iterator BI = block_begin(), E = block_end(); BI != E; ++BI) {
BasicBlock *BB = LoopBBs[i]; BasicBlock *BB = *BI;
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E; for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
++UI) { ++UI) {
BasicBlock *UserBB = cast<Instruction>(*UI)->getParent(); BasicBlock *UserBB = cast<Instruction>(*UI)->getParent();
if (PHINode* p = dyn_cast<PHINode>(*UI)) { if (PHINode *P = dyn_cast<PHINode>(*UI)) {
unsigned OperandNo = UI.getOperandNo(); unsigned OperandNo = UI.getOperandNo();
UserBB = p->getIncomingBlock(OperandNo/2); UserBB = P->getIncomingBlock(OperandNo/2);
} }
// Check the current block, as a fast-path. Most values are used in the // Check the current block, as a fast-path. Most values are used in the
// same block they are defined in. // same block they are defined in.
if (UserBB != BB && if (UserBB != BB && !LoopBBs.count(UserBB))
// Otherwise, binary search LoopBBs for this block.
!std::binary_search(LoopBBs.begin(), LoopBBs.end(), UserBB))
return false; return false;
} }
} }