Line data Source code
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 567459 : 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 567459 : const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
17 1726539 : while (changed) {
18 : changed = false;
19 26467762 : for (int i = 0; i < blocks->length(); i++) {
20 26467761 : HBasicBlock* block = blocks->at(i);
21 12938070 : if (!block->IsReachable()) continue;
22 9920165 : bool is_reachable = blocks->at(0) == block;
23 11189348 : for (HPredecessorIterator it(block); !it.Done(); it.Advance()) {
24 8367046 : 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 17940291 : if (predecessor->IsReachable() && !predecessor->IsDeoptimizing()) {
30 : HBasicBlock* pred_succ;
31 : bool known_pred_succ =
32 8367046 : predecessor->end()->KnownSuccessorBlock(&pred_succ);
33 8367038 : if (!known_pred_succ || pred_succ == block) {
34 : is_reachable = true;
35 8258425 : break;
36 : }
37 : }
38 1269183 : if (block->is_osr_entry()) {
39 : is_reachable = true;
40 : }
41 : }
42 9920165 : if (!is_reachable) {
43 1063708 : block->MarkUnreachable();
44 : changed = true;
45 : }
46 : }
47 : }
48 567460 : }
49 :
50 :
51 567457 : void HMarkUnreachableBlocksPhase::Run() {
52 567457 : MarkUnreachableBlocks();
53 567460 : }
54 :
55 : } // namespace internal
56 : } // namespace v8
|