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