Home | History | Annotate | Download | only in src
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "src/hydrogen-mark-unreachable.h"
      6 
      7 namespace v8 {
      8 namespace internal {
      9 
     10 
     11 void HMarkUnreachableBlocksPhase::MarkUnreachableBlocks() {
     12   // If there is unreachable code in the graph, propagate the unreachable marks
     13   // using a fixed-point iteration.
     14   bool changed = true;
     15   const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
     16   while (changed) {
     17     changed = false;
     18     for (int i = 0; i < blocks->length(); i++) {
     19       HBasicBlock* block = blocks->at(i);
     20       if (!block->IsReachable()) continue;
     21       bool is_reachable = blocks->at(0) == block;
     22       for (HPredecessorIterator it(block); !it.Done(); it.Advance()) {
     23         HBasicBlock* predecessor = it.Current();
     24         // A block is reachable if one of its predecessors is reachable,
     25         // doesn't deoptimize and either is known to transfer control to the
     26         // block or has a control flow instruction for which the next block
     27         // cannot be determined.
     28         if (predecessor->IsReachable() && !predecessor->IsDeoptimizing()) {
     29           HBasicBlock* pred_succ;
     30           bool known_pred_succ =
     31               predecessor->end()->KnownSuccessorBlock(&pred_succ);
     32           if (!known_pred_succ || pred_succ == block) {
     33             is_reachable = true;
     34             break;
     35           }
     36         }
     37         if (block->is_osr_entry()) {
     38           is_reachable = true;
     39         }
     40       }
     41       if (!is_reachable) {
     42         block->MarkUnreachable();
     43         changed = true;
     44       }
     45     }
     46   }
     47 }
     48 
     49 
     50 void HMarkUnreachableBlocksPhase::Run() {
     51   MarkUnreachableBlocks();
     52 }
     53 
     54 } }  // namespace v8::internal
     55