Improve dominator computation to avoid worst-case quadratic time.

In case of a degenerated CFG like in the example below processing
predecessors in the wrong order yields n^2 runtime.

  do {
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    if (x) break;
    // etc.
  } while (false);

Reversing iteration order avoids this.
Review URL: http://codereview.chromium.org/8502012

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9905 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3628c934
......@@ -756,7 +756,7 @@ void HGraph::AssignDominators() {
// All others are back edges, and thus cannot dominate the loop header.
blocks_[i]->AssignCommonDominator(blocks_[i]->predecessors()->first());
} else {
for (int j = 0; j < blocks_[i]->predecessors()->length(); ++j) {
for (int j = blocks_[i]->predecessors()->length() - 1; j >= 0; --j) {
blocks_[i]->AssignCommonDominator(blocks_[i]->predecessors()->at(j));
}
}
......
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