Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: src/hydrogen-mark-unreachable.cc

Issue 22876009: Improve and simplify removal of unreachable code (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add missing file Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "hydrogen-infer-types.h" 28 #include "hydrogen-mark-unreachable.h"
29 29
30 namespace v8 { 30 namespace v8 {
31 namespace internal { 31 namespace internal {
32 32
33 void HInferTypesPhase::InferTypes(int from_inclusive, int to_inclusive) {
34 for (int i = from_inclusive; i <= to_inclusive; ++i) {
35 HBasicBlock* block = graph()->blocks()->at(i);
36 33
37 const ZoneList<HPhi*>* phis = block->phis(); 34 void HMarkUnreachableBlocksPhase::MarkUnreachableBlocks() {
38 for (int j = 0; j < phis->length(); j++) { 35 // If there is unreachable code in the graph, propagate the unreachable marks
39 phis->at(j)->UpdateInferredType(); 36 // using a fixed-point iteration.
40 } 37 bool changed = true;
41 38 const ZoneList<HBasicBlock*>* blocks = graph()->blocks();
42 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { 39 while (changed) {
43 it.Current()->UpdateInferredType(); 40 changed = false;
44 } 41 for (int i = 0; i < blocks->length(); i++) {
45 42 HBasicBlock* block = blocks->at(i);
46 if (block->IsLoopHeader()) { 43 if (block->IsReachable()) {
Jakob Kummerow 2013/10/01 11:59:20 nit: you can avoid one level of indentation by tur
danno 2013/10/23 11:46:51 Done.
47 HBasicBlock* last_back_edge = 44 bool is_reachable = blocks->at(0) == block;
48 block->loop_information()->GetLastBackEdge(); 45 for (HPredecessorIterator it(block); !it.Done(); it.Advance()) {
49 InferTypes(i + 1, last_back_edge->block_id()); 46 HBasicBlock* predecessor = it.Current();
50 // Skip all blocks already processed by the recursive call. 47 // A block is reachable if one of it's predecessor is reachable,
Jakob Kummerow 2013/10/01 17:47:13 nit: s/it's predecessor/its predecessors/
danno 2013/10/23 11:46:51 Done.
51 i = last_back_edge->block_id(); 48 // doesn't deoptimize and either is known to transfer control to the
52 // Update phis of the loop header now after the whole loop body is 49 // block or has a control flow instruction for which the next block
53 // guaranteed to be processed. 50 // cannot be determined.
54 for (int j = 0; j < block->phis()->length(); ++j) { 51 if (predecessor->IsReachable() && !predecessor->IsDeoptimizing()) {
55 HPhi* phi = block->phis()->at(j); 52 HBasicBlock* pred_succ;
56 worklist_.Add(phi, zone()); 53 bool known_pred_succ =
57 in_worklist_.Add(phi->id()); 54 predecessor->end()->KnownSuccessorBlock(&pred_succ);
58 } 55 if (!known_pred_succ || pred_succ == block) {
59 while (!worklist_.is_empty()) { 56 is_reachable = true;
60 HValue* current = worklist_.RemoveLast(); 57 break;
61 in_worklist_.Remove(current->id());
62 if (current->UpdateInferredType()) {
63 for (HUseIterator it(current->uses()); !it.Done(); it.Advance()) {
64 HValue* use = it.value();
65 if (!in_worklist_.Contains(use->id())) {
66 in_worklist_.Add(use->id());
67 worklist_.Add(use, zone());
68 } 58 }
69 } 59 }
60 if (block->is_osr_entry()) {
61 is_reachable = true;
62 }
63 }
64 if (!is_reachable) {
65 block->MarkUnreachable();
66 changed = true;
70 } 67 }
71 } 68 }
72 ASSERT(in_worklist_.IsEmpty());
73 } 69 }
74 } 70 }
75 } 71 }
76 72
73
74 void HMarkUnreachableBlocksPhase::Run() {
75 MarkUnreachableBlocks();
76 }
77
77 } } // namespace v8::internal 78 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698