hydrogen-sce.cc 1.26 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5
#include "src/crankshaft/hydrogen-sce.h"
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

namespace v8 {
namespace internal {

void HStackCheckEliminationPhase::Run() {
  // For each loop block walk the dominator tree from the backwards branch to
  // the loop header. If a call instruction is encountered the backwards branch
  // is dominated by a call and the stack check in the backwards branch can be
  // removed.
  for (int i = 0; i < graph()->blocks()->length(); i++) {
    HBasicBlock* block = graph()->blocks()->at(i);
    if (block->IsLoopHeader()) {
      HBasicBlock* back_edge = block->loop_information()->GetLastBackEdge();
      HBasicBlock* dominator = back_edge;
      while (true) {
        for (HInstructionIterator it(dominator); !it.Done(); it.Advance()) {
vegorov@chromium.org's avatar
vegorov@chromium.org committed
22
          if (it.Current()->HasStackCheck()) {
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
            block->loop_information()->stack_check()->Eliminate();
            break;
          }
        }

        // Done when the loop header is processed.
        if (dominator == block) break;

        // Move up the dominator tree.
        dominator = dominator->dominator();
      }
    }
  }
}

38 39
}  // namespace internal
}  // namespace v8