DFG dominators: document and rename stuff.

https://bugs.webkit.org/show_bug.cgi?id=123056

Patch by Nadav Rotem <nrotem@apple.com> on 2013-10-19
Reviewed by Filip Pizlo.

Documented the code and renamed some variables.

* dfg/DFGDominators.cpp:
(JSC::DFG::Dominators::compute):
(JSC::DFG::Dominators::pruneDominators):
* dfg/DFGDominators.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157675 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 17140916
2013-10-19 Nadav Rotem <nrotem@apple.com>
DFG dominators: document and rename stuff.
https://bugs.webkit.org/show_bug.cgi?id=123056
Reviewed by Filip Pizlo.
Documented the code and renamed some variables.
* dfg/DFGDominators.cpp:
(JSC::DFG::Dominators::compute):
(JSC::DFG::Dominators::pruneDominators):
* dfg/DFGDominators.h:
2013-10-19 Julien Brianceau <jbriance@cisco.com>
Fix build failure for architectures with 4 argument registers.
......
......@@ -48,16 +48,19 @@ void Dominators::compute(Graph& graph)
unsigned numBlocks = graph.numBlocks();
// Allocate storage for the dense dominance matrix.
if (numBlocks > m_results.size()) {
m_results.grow(numBlocks);
for (unsigned i = numBlocks; i--;)
m_results[i].resize(numBlocks);
m_scratch.resize(numBlocks);
}
// We know that the entry block is only dominated by itself.
m_results[0].clearAll();
m_results[0].set(0);
// Find all of the valid blocks.
m_scratch.clearAll();
for (unsigned i = numBlocks; i--;) {
if (!graph.block(i))
......@@ -65,39 +68,48 @@ void Dominators::compute(Graph& graph)
m_scratch.set(i);
}
// Mark all nodes as dominated by everything.
for (unsigned i = numBlocks; i-- > 1;) {
if (!graph.block(i) || graph.block(i)->predecessors.isEmpty())
m_results[i].clearAll();
else
m_results[i].set(m_scratch);
}
// Iteratively eliminate nodes that are not dominator.
bool changed;
do {
changed = false;
// Prune dominators in all non entry blocks: forward scan.
for (unsigned i = 1; i < numBlocks; ++i)
changed |= iterateForBlock(graph, i);
changed |= pruneDominators(graph, i);
if (!changed)
break;
// Prune dominators in all non entry blocks: backward scan.
changed = false;
for (unsigned i = numBlocks; i-- > 1;)
changed |= iterateForBlock(graph, i);
changed |= pruneDominators(graph, i);
} while (changed);
}
bool Dominators::iterateForBlock(Graph& graph, BlockIndex i)
bool Dominators::pruneDominators(Graph& graph, BlockIndex idx)
{
BasicBlock* block = graph.block(i);
if (!block)
return false;
if (block->predecessors.isEmpty())
BasicBlock* block = graph.block(idx);
if (!block || block->predecessors.isEmpty())
return false;
// Find the intersection of dom(preds).
m_scratch.set(m_results[block->predecessors[0]->index]);
for (unsigned j = block->predecessors.size(); j-- > 1;)
m_scratch.filter(m_results[block->predecessors[j]->index]);
m_scratch.set(i);
return m_results[i].setAndCheck(m_scratch);
// The block is also dominated by itself.
m_scratch.set(idx);
return m_results[idx].setAndCheck(m_scratch);
}
void Dominators::dump(Graph& graph, PrintStream& out) const
......
......@@ -60,10 +60,10 @@ public:
void dump(Graph& graph, PrintStream&) const;
private:
bool iterateForBlock(Graph& graph, BlockIndex);
bool pruneDominators(Graph&, BlockIndex);
Vector<FastBitVector> m_results; // For each block, the bitvector of blocks that dominate it.
FastBitVector m_scratch;
FastBitVector m_scratch; // A temporary bitvector with bit for each block. We recycle this to save new/deletes.
};
} } // namespace JSC::DFG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment