1. Correct some comments and clean up some dead code.

2. When calculating ANTIC_IN, only iterate the changed blocks.  For most average
inputs this is a small speedup, but for cases with unusual CFGs, this can be a significant win.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37742 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson
2007-06-26 23:29:41 +00:00
parent c33aa47130
commit 6032a5ba64

View File

@@ -377,7 +377,7 @@ namespace {
SmallPtrSet<Value*, 32>& currExps, SmallPtrSet<Value*, 32>& currExps,
SmallPtrSet<Value*, 32>& currTemps, SmallPtrSet<Value*, 32>& currTemps,
std::set<BasicBlock*>& visited); std::set<BasicBlock*>& visited);
unsigned buildsets(Function& F); void buildsets(Function& F);
void insertion_pre(Value* e, BasicBlock* BB, void insertion_pre(Value* e, BasicBlock* BB,
std::map<BasicBlock*, Value*>& avail, std::map<BasicBlock*, Value*>& avail,
@@ -895,7 +895,7 @@ unsigned GVNPRE::buildsets_anticin(BasicBlock* BB,
/// buildsets - Phase 1 of the main algorithm. Construct the AVAIL_OUT /// buildsets - Phase 1 of the main algorithm. Construct the AVAIL_OUT
/// and the ANTIC_IN sets. /// and the ANTIC_IN sets.
unsigned GVNPRE::buildsets(Function& F) { void GVNPRE::buildsets(Function& F) {
std::map<BasicBlock*, SmallPtrSet<Value*, 32> > generatedExpressions; std::map<BasicBlock*, SmallPtrSet<Value*, 32> > generatedExpressions;
std::map<BasicBlock*, SmallPtrSet<PHINode*, 32> > generatedPhis; std::map<BasicBlock*, SmallPtrSet<PHINode*, 32> > generatedPhis;
std::map<BasicBlock*, SmallPtrSet<Value*, 32> > generatedTemporaries; std::map<BasicBlock*, SmallPtrSet<Value*, 32> > generatedTemporaries;
@@ -937,20 +937,23 @@ unsigned GVNPRE::buildsets(Function& F) {
// Phase 1, Part 2: calculate ANTIC_IN // Phase 1, Part 2: calculate ANTIC_IN
std::set<BasicBlock*> visited; std::set<BasicBlock*> visited;
SmallPtrSet<BasicBlock*, 4> block_changed;
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI)
block_changed.insert(FI);
bool changed = true; bool changed = true;
unsigned iterations = 0; unsigned iterations = 0;
while (changed) { while (changed) {
changed = false; changed = false;
SmallPtrSet<Value*, 32> anticOut; SmallPtrSet<Value*, 32> anticOut;
// Top-down walk of the postdominator tree // Postorder walk of the CFG
for (po_iterator<BasicBlock*> BBI = po_begin(&F.getEntryBlock()), for (po_iterator<BasicBlock*> BBI = po_begin(&F.getEntryBlock()),
BBE = po_end(&F.getEntryBlock()); BBI != BBE; ++BBI) { BBE = po_end(&F.getEntryBlock()); BBI != BBE; ++BBI) {
BasicBlock* BB = *BBI; BasicBlock* BB = *BBI;
if (BB == 0)
continue;
if (block_changed.count(BB) != 0) {
unsigned ret = buildsets_anticin(BB, anticOut,generatedExpressions[BB], unsigned ret = buildsets_anticin(BB, anticOut,generatedExpressions[BB],
generatedTemporaries[BB], visited); generatedTemporaries[BB], visited);
@@ -959,19 +962,24 @@ unsigned GVNPRE::buildsets(Function& F) {
continue; continue;
} else { } else {
visited.insert(BB); visited.insert(BB);
if (ret == 2) {
DOUT << "CHANGED: " << BB->getName() << "\n"; if (ret == 2)
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
PI != PE; ++PI) {
block_changed.insert(*PI);
} }
else
block_changed.erase(BB);
changed |= (ret == 2); changed |= (ret == 2);
} }
} }
}
iterations++; iterations++;
} }
DOUT << "ITERATIONS: " << iterations << "\n"; DOUT << "ITERATIONS: " << iterations << "\n";
return 0; // No bail, no changes
} }
/// insertion_pre - When a partial redundancy has been identified, eliminate it /// insertion_pre - When a partial redundancy has been identified, eliminate it
@@ -1173,10 +1181,7 @@ bool GVNPRE::runOnFunction(Function &F) {
// This phase calculates the AVAIL_OUT and ANTIC_IN sets // This phase calculates the AVAIL_OUT and ANTIC_IN sets
// NOTE: If full postdom information is no available, this will bail // NOTE: If full postdom information is no available, this will bail
// early, performing GVN but not PRE // early, performing GVN but not PRE
unsigned bail = buildsets(F); buildsets(F);
//If a bail occurred, terminate early
if (bail != 0)
return (bail == 2);
// Phase 2: Insert // Phase 2: Insert
// This phase inserts values to make partially redundant values // This phase inserts values to make partially redundant values