OLD | NEW |
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-sce.h" | 28 #include "hydrogen-mark-unreachable.h" |
29 #include "v8.h" | |
30 | 29 |
31 namespace v8 { | 30 namespace v8 { |
32 namespace internal { | 31 namespace internal { |
33 | 32 |
34 void HStackCheckEliminationPhase::Run() { | 33 |
35 // For each loop block walk the dominator tree from the backwards branch to | 34 void HMarkUnreachableBlocksPhase::MarkUnreachableBlocks() { |
36 // the loop header. If a call instruction is encountered the backwards branch | 35 // If there is unreachable code in the graph, propagate the unreachable marks |
37 // is dominated by a call and the stack check in the backwards branch can be | 36 // using a fixed-point iteration. |
38 // removed. | 37 bool changed = true; |
39 for (int i = 0; i < graph()->blocks()->length(); i++) { | 38 const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
40 HBasicBlock* block = graph()->blocks()->at(i); | 39 while (changed) { |
41 if (block->IsLoopHeader()) { | 40 changed = false; |
42 HBasicBlock* back_edge = block->loop_information()->GetLastBackEdge(); | 41 for (int i = 0; i < blocks->length(); i++) { |
43 HBasicBlock* dominator = back_edge; | 42 HBasicBlock* block = blocks->at(i); |
44 while (true) { | 43 if (!block->IsReachable()) continue; |
45 for (HInstructionIterator it(dominator); !it.Done(); it.Advance()) { | 44 bool is_reachable = blocks->at(0) == block; |
46 if (it.Current()->IsCall()) { | 45 for (HPredecessorIterator it(block); !it.Done(); it.Advance()) { |
47 block->loop_information()->stack_check()->Eliminate(); | 46 HBasicBlock* predecessor = it.Current(); |
| 47 // A block is reachable if one of its predecessors is reachable, |
| 48 // doesn't deoptimize and either is known to transfer control to the |
| 49 // block or has a control flow instruction for which the next block |
| 50 // cannot be determined. |
| 51 if (predecessor->IsReachable() && !predecessor->IsDeoptimizing()) { |
| 52 HBasicBlock* pred_succ; |
| 53 bool known_pred_succ = |
| 54 predecessor->end()->KnownSuccessorBlock(&pred_succ); |
| 55 if (!known_pred_succ || pred_succ == block) { |
| 56 is_reachable = true; |
48 break; | 57 break; |
49 } | 58 } |
50 } | 59 } |
51 | 60 if (block->is_osr_entry()) { |
52 // Done when the loop header is processed. | 61 is_reachable = true; |
53 if (dominator == block) break; | 62 } |
54 | 63 } |
55 // Move up the dominator tree. | 64 if (!is_reachable) { |
56 dominator = dominator->dominator(); | 65 block->MarkUnreachable(); |
| 66 changed = true; |
57 } | 67 } |
58 } | 68 } |
59 } | 69 } |
60 } | 70 } |
61 | 71 |
| 72 |
| 73 void HMarkUnreachableBlocksPhase::Run() { |
| 74 MarkUnreachableBlocks(); |
| 75 } |
| 76 |
62 } } // namespace v8::internal | 77 } } // namespace v8::internal |
OLD | NEW |