Use the PotDoms map to memoize 'dominating value' lookup. With this patch,

LCSSA is still the slowest pass when gccas'ing 252.eon, but now it only takes
39s instead of 289s. :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28776 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-06-14 01:13:57 +00:00
parent 50c997e26a
commit 13a68e4257

View File

@ -74,8 +74,12 @@ namespace {
private: private:
SetVector<Instruction*> getLoopValuesUsedOutsideLoop(Loop *L); SetVector<Instruction*> getLoopValuesUsedOutsideLoop(Loop *L);
Instruction *getValueDominatingBlock(BasicBlock *BB, Instruction *getValueDominatingBlock(BasicBlock *BB,
std::map<BasicBlock*, Instruction*>& PotDoms) {
return getValueDominatingDTNode(DT->getNode(BB), PotDoms);
}
Instruction *getValueDominatingDTNode(DominatorTree::Node *Node,
std::map<BasicBlock*, Instruction*>& PotDoms); std::map<BasicBlock*, Instruction*>& PotDoms);
/// inLoop - returns true if the given block is within the current loop /// inLoop - returns true if the given block is within the current loop
const bool inLoop(BasicBlock* B) { const bool inLoop(BasicBlock* B) {
return std::binary_search(LoopBlocks.begin(), LoopBlocks.end(), B); return std::binary_search(LoopBlocks.begin(), LoopBlocks.end(), B);
@ -237,8 +241,8 @@ void LCSSA::processInstruction(Instruction* Instr,
} }
} }
} else { } else {
Value *NewVal = getValueDominatingBlock((*II)->getParent(), Phis); Value *NewVal = getValueDominatingBlock((*II)->getParent(), Phis);
(*II)->replaceUsesOfWith(Instr, NewVal); (*II)->replaceUsesOfWith(Instr, NewVal);
} }
} }
} }
@ -275,19 +279,12 @@ SetVector<Instruction*> LCSSA::getLoopValuesUsedOutsideLoop(Loop *L) {
/// getValueDominatingBlock - Return the value within the potential dominators /// getValueDominatingBlock - Return the value within the potential dominators
/// map that dominates the given block. /// map that dominates the given block.
Instruction *LCSSA::getValueDominatingBlock(BasicBlock *BB, Instruction *LCSSA::getValueDominatingDTNode(DominatorTree::Node *Node,
std::map<BasicBlock*, Instruction*>& PotDoms) { std::map<BasicBlock*, Instruction*>& PotDoms) {
DominatorTree::Node* bbNode = DT->getNode(BB); assert(Node != 0 && "Didn't find dom value?");
while (bbNode != 0) { Instruction *&CacheSlot = PotDoms[Node->getBlock()];
std::map<BasicBlock*, Instruction*>::iterator I = if (CacheSlot) return CacheSlot;
PotDoms.find(bbNode->getBlock());
if (I != PotDoms.end()) {
return (*I).second;
}
bbNode = bbNode->getIDom();
}
assert(0 && "No dominating value found."); // Otherwise, return the value of the idom and remember this for next time.
return CacheSlot = getValueDominatingDTNode(Node->getIDom(), PotDoms);
return 0;
} }