OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 |
| 28 #include "hydrogen-removable-simulates.h" |
| 29 |
| 30 namespace v8 { |
| 31 namespace internal { |
| 32 |
| 33 void HMergeRemovableSimulatesPhase::Run() { |
| 34 ZoneList<HSimulate*> mergelist(2, zone()); |
| 35 for (int i = 0; i < graph()->blocks()->length(); ++i) { |
| 36 HBasicBlock* block = graph()->blocks()->at(i); |
| 37 // Make sure the merge list is empty at the start of a block. |
| 38 ASSERT(mergelist.is_empty()); |
| 39 // Nasty heuristic: Never remove the first simulate in a block. This |
| 40 // just so happens to have a beneficial effect on register allocation. |
| 41 bool first = true; |
| 42 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 43 HInstruction* current = it.Current(); |
| 44 if (current->IsLeaveInlined()) { |
| 45 // Never fold simulates from inlined environments into simulates |
| 46 // in the outer environment. |
| 47 // (Before each HEnterInlined, there is a non-foldable HSimulate |
| 48 // anyway, so we get the barrier in the other direction for free.) |
| 49 // Simply remove all accumulated simulates without merging. This |
| 50 // is safe because simulates after instructions with side effects |
| 51 // are never added to the merge list. |
| 52 while (!mergelist.is_empty()) { |
| 53 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); |
| 54 } |
| 55 continue; |
| 56 } |
| 57 if (current->IsReturn()) { |
| 58 // Drop mergeable simulates in the list. This is safe because |
| 59 // simulates after instructions with side effects are never added |
| 60 // to the merge list. |
| 61 while (!mergelist.is_empty()) { |
| 62 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); |
| 63 } |
| 64 continue; |
| 65 } |
| 66 // Skip the non-simulates and the first simulate. |
| 67 if (!current->IsSimulate()) continue; |
| 68 if (first) { |
| 69 first = false; |
| 70 continue; |
| 71 } |
| 72 HSimulate* current_simulate = HSimulate::cast(current); |
| 73 if ((current_simulate->previous()->HasObservableSideEffects() && |
| 74 !current_simulate->next()->IsSimulate()) || |
| 75 !current_simulate->is_candidate_for_removal()) { |
| 76 // This simulate is not suitable for folding. |
| 77 // Fold the ones accumulated so far. |
| 78 current_simulate->MergeWith(&mergelist); |
| 79 continue; |
| 80 } else { |
| 81 // Accumulate this simulate for folding later on. |
| 82 mergelist.Add(current_simulate, zone()); |
| 83 } |
| 84 } |
| 85 |
| 86 if (!mergelist.is_empty()) { |
| 87 // Merge the accumulated simulates at the end of the block. |
| 88 HSimulate* last = mergelist.RemoveLast(); |
| 89 last->MergeWith(&mergelist); |
| 90 } |
| 91 } |
| 92 } |
| 93 |
| 94 } } // namespace v8::internal |
OLD | NEW |