Avoid excessive calls to find_leader when calculating AVAIL_OUT. This reduces the time to optimize 403.gcc from 23.5s to 21.9s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37702 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2007-06-22 03:14:03 +00:00
parent 0b2ce1fc19
commit 124084604d

View File

@ -367,45 +367,47 @@ namespace {
// Helper fuctions // Helper fuctions
// FIXME: eliminate or document these better // FIXME: eliminate or document these better
void dump(const SmallPtrSet<Value*, 32>& s) const; void dump(const SmallPtrSet<Value*, 32>& s) const __attribute__((noinline));
void clean(SmallPtrSet<Value*, 32>& set); void clean(SmallPtrSet<Value*, 32>& set) __attribute__((noinline));
Value* find_leader(SmallPtrSet<Value*, 32>& vals, Value* find_leader(SmallPtrSet<Value*, 32>& vals,
uint32_t v); uint32_t v) __attribute__((noinline));
Value* phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ); Value* phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) __attribute__((noinline));
void phi_translate_set(SmallPtrSet<Value*, 32>& anticIn, BasicBlock* pred, void phi_translate_set(SmallPtrSet<Value*, 32>& anticIn, BasicBlock* pred,
BasicBlock* succ, SmallPtrSet<Value*, 32>& out) ; BasicBlock* succ, SmallPtrSet<Value*, 32>& out) __attribute__((noinline));
void topo_sort(SmallPtrSet<Value*, 32>& set, void topo_sort(SmallPtrSet<Value*, 32>& set,
std::vector<Value*>& vec); std::vector<Value*>& vec) __attribute__((noinline));
void cleanup(); void cleanup() __attribute__((noinline));
bool elimination(); bool elimination() __attribute__((noinline));
void val_insert(SmallPtrSet<Value*, 32>& s, Value* v); void val_insert(SmallPtrSet<Value*, 32>& s, Value* v) __attribute__((noinline));
void val_replace(SmallPtrSet<Value*, 32>& s, Value* v); void val_replace(SmallPtrSet<Value*, 32>& s, Value* v) __attribute__((noinline));
bool dependsOnInvoke(Value* V); bool dependsOnInvoke(Value* V) __attribute__((noinline));
void buildsets_availout(BasicBlock::iterator I, void buildsets_availout(BasicBlock::iterator I,
SmallPtrSet<Value*, 32>& currAvail, SmallPtrSet<Value*, 32>& currAvail,
SmallPtrSet<PHINode*, 32>& currPhis, SmallPtrSet<PHINode*, 32>& currPhis,
SmallPtrSet<Value*, 32>& currExps, SmallPtrSet<Value*, 32>& currExps,
SmallPtrSet<Value*, 32>& currTemps); SmallPtrSet<Value*, 32>& currTemps,
BitVector& availNumbers,
BitVector& expNumbers) __attribute__((noinline));
bool buildsets_anticout(BasicBlock* BB, bool buildsets_anticout(BasicBlock* BB,
SmallPtrSet<Value*, 32>& anticOut, SmallPtrSet<Value*, 32>& anticOut,
std::set<BasicBlock*>& visited); std::set<BasicBlock*>& visited) __attribute__((noinline));
unsigned buildsets_anticin(BasicBlock* BB, unsigned buildsets_anticin(BasicBlock* BB,
SmallPtrSet<Value*, 32>& anticOut, SmallPtrSet<Value*, 32>& anticOut,
SmallPtrSet<Value*, 32>& currExps, SmallPtrSet<Value*, 32>& currExps,
SmallPtrSet<Value*, 32>& currTemps, SmallPtrSet<Value*, 32>& currTemps,
std::set<BasicBlock*>& visited); std::set<BasicBlock*>& visited) __attribute__((noinline));
unsigned buildsets(Function& F); unsigned buildsets(Function& F) __attribute__((noinline));
void insertion_pre(Value* e, BasicBlock* BB, void insertion_pre(Value* e, BasicBlock* BB,
std::map<BasicBlock*, Value*>& avail, std::map<BasicBlock*, Value*>& avail,
SmallPtrSet<Value*, 32>& new_set); SmallPtrSet<Value*, 32>& new_set) __attribute__((noinline));
unsigned insertion_mergepoint(std::vector<Value*>& workList, unsigned insertion_mergepoint(std::vector<Value*>& workList,
df_iterator<DomTreeNode*>& D, df_iterator<DomTreeNode*>& D,
SmallPtrSet<Value*, 32>& new_set); SmallPtrSet<Value*, 32>& new_set) __attribute__((noinline));
bool insertion(Function& F); bool insertion(Function& F) __attribute__((noinline));
}; };
@ -795,10 +797,15 @@ void GVNPRE::buildsets_availout(BasicBlock::iterator I,
SmallPtrSet<Value*, 32>& currAvail, SmallPtrSet<Value*, 32>& currAvail,
SmallPtrSet<PHINode*, 32>& currPhis, SmallPtrSet<PHINode*, 32>& currPhis,
SmallPtrSet<Value*, 32>& currExps, SmallPtrSet<Value*, 32>& currExps,
SmallPtrSet<Value*, 32>& currTemps) { SmallPtrSet<Value*, 32>& currTemps,
BitVector& availNumbers,
BitVector& expNumbers) {
// Handle PHI nodes... // Handle PHI nodes...
if (PHINode* p = dyn_cast<PHINode>(I)) { if (PHINode* p = dyn_cast<PHINode>(I)) {
VN.lookup_or_add(p); VN.lookup_or_add(p);
expNumbers.resize(VN.size());
availNumbers.resize(VN.size());
currPhis.insert(p); currPhis.insert(p);
// Handle binary ops... // Handle binary ops...
@ -806,13 +813,26 @@ void GVNPRE::buildsets_availout(BasicBlock::iterator I,
Value* leftValue = BO->getOperand(0); Value* leftValue = BO->getOperand(0);
Value* rightValue = BO->getOperand(1); Value* rightValue = BO->getOperand(1);
VN.lookup_or_add(BO); unsigned num = VN.lookup_or_add(BO);
expNumbers.resize(VN.size());
availNumbers.resize(VN.size());
if (isa<Instruction>(leftValue)) if (isa<Instruction>(leftValue))
val_insert(currExps, leftValue); if (!expNumbers.test(VN.lookup(leftValue)-1)) {
currExps.insert(leftValue);
expNumbers.set(VN.lookup(leftValue)-1);
}
if (isa<Instruction>(rightValue)) if (isa<Instruction>(rightValue))
val_insert(currExps, rightValue); if (!expNumbers.test(VN.lookup(rightValue)-1)) {
val_insert(currExps, BO); currExps.insert(rightValue);
expNumbers.set(VN.lookup(rightValue)-1);
}
if (!expNumbers.test(VN.lookup(BO)-1)) {
currExps.insert(BO);
expNumbers.set(num-1);
}
// Handle cmp ops... // Handle cmp ops...
} else if (CmpInst* C = dyn_cast<CmpInst>(I)) { } else if (CmpInst* C = dyn_cast<CmpInst>(I)) {
@ -821,20 +841,40 @@ void GVNPRE::buildsets_availout(BasicBlock::iterator I,
VN.lookup_or_add(C); VN.lookup_or_add(C);
unsigned num = VN.lookup_or_add(C);
expNumbers.resize(VN.size());
availNumbers.resize(VN.size());
if (isa<Instruction>(leftValue)) if (isa<Instruction>(leftValue))
val_insert(currExps, leftValue); if (!expNumbers.test(VN.lookup(leftValue)-1)) {
currExps.insert(leftValue);
expNumbers.set(VN.lookup(leftValue)-1);
}
if (isa<Instruction>(rightValue)) if (isa<Instruction>(rightValue))
val_insert(currExps, rightValue); if (!expNumbers.test(VN.lookup(rightValue)-1)) {
val_insert(currExps, C); currExps.insert(rightValue);
expNumbers.set(VN.lookup(rightValue)-1);
}
if (!expNumbers.test(VN.lookup(C)-1)) {
currExps.insert(C);
expNumbers.set(num-1);
}
// Handle unsupported ops // Handle unsupported ops
} else if (!I->isTerminator()){ } else if (!I->isTerminator()){
VN.lookup_or_add(I); VN.lookup_or_add(I);
expNumbers.resize(VN.size());
availNumbers.resize(VN.size());
currTemps.insert(I); currTemps.insert(I);
} }
if (!I->isTerminator()) if (!I->isTerminator())
val_insert(currAvail, I); if (!availNumbers.test(VN.lookup(I)-1)) {
currAvail.insert(I);
availNumbers.set(VN.lookup(I)-1);
}
} }
/// buildsets_anticout - When walking the postdom tree, calculate the ANTIC_OUT /// buildsets_anticout - When walking the postdom tree, calculate the ANTIC_OUT
@ -953,10 +993,16 @@ unsigned GVNPRE::buildsets(Function& F) {
currAvail.insert(availableOut[DI->getIDom()->getBlock()].begin(), currAvail.insert(availableOut[DI->getIDom()->getBlock()].begin(),
availableOut[DI->getIDom()->getBlock()].end()); availableOut[DI->getIDom()->getBlock()].end());
BitVector availNumbers(VN.size());
for (SmallPtrSet<Value*, 32>::iterator I = currAvail.begin(),
E = currAvail.end(); I != E; ++I)
availNumbers.set(VN.lookup(*I));
BitVector expNumbers(VN.size());
for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); for (BasicBlock::iterator BI = BB->begin(), BE = BB->end();
BI != BE; ++BI) BI != BE; ++BI)
buildsets_availout(BI, currAvail, currPhis, currExps, currTemps); buildsets_availout(BI, currAvail, currPhis, currExps,
currTemps, availNumbers, expNumbers);
} }