title: Fast calculation of dominators
body: <p>It is said that when converting intermediate code to static single assignment form,</p>
  
  <ol>
  <li><p>It is necessary to calculate the dominators of basic blocks</p></li>
  <li><p>The somewhat obvious way to do this as a fixed point of equations is slow</p></li>
  <li><p>To do it fast, you need to use the fairly complicated Lengauer-Tarjan algorithm</p></li>
  </ol>
  
  <p>I can see the first two points, but I'm not clear about the reasoning behind the third. In particular, is there any reason why you can't do it just in the process of calculating the preorder dominator tree? I've implemented a version of that in JavaScript and it seems to work:</p>
  
  <pre><code>var domPreorder = [];
  
  function doms(b) {
      b.children = [];
      for (var c of b[b.length - 1].targets)
          if (c.i == null) {
              c.i = domPreorder.length
              domPreorder.push(c)
              b.children.push(c)
              c.parent = b
              doms(c)
          }
  }
  
  f[0].i = 0
  domPreorder.push(f[0])
  doms(f[0])
  </code></pre>
  
  <p>Is there some disadvantage to this method that I'm not seeing?</p>