| 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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ZoneList<HSimulate*> mergelist(2, zone()); | 34 ZoneList<HSimulate*> mergelist(2, zone()); |
| 35 for (int i = 0; i < graph()->blocks()->length(); ++i) { | 35 for (int i = 0; i < graph()->blocks()->length(); ++i) { |
| 36 HBasicBlock* block = graph()->blocks()->at(i); | 36 HBasicBlock* block = graph()->blocks()->at(i); |
| 37 // Make sure the merge list is empty at the start of a block. | 37 // Make sure the merge list is empty at the start of a block. |
| 38 ASSERT(mergelist.is_empty()); | 38 ASSERT(mergelist.is_empty()); |
| 39 // Nasty heuristic: Never remove the first simulate in a block. This | 39 // Nasty heuristic: Never remove the first simulate in a block. This |
| 40 // just so happens to have a beneficial effect on register allocation. | 40 // just so happens to have a beneficial effect on register allocation. |
| 41 bool first = true; | 41 bool first = true; |
| 42 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | 42 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
| 43 HInstruction* current = it.Current(); | 43 HInstruction* current = it.Current(); |
| 44 if (current->IsEnterInlined()) { |
| 45 // Ensure there's a non-foldable HSimulate before an HEnterInlined to |
| 46 // avoid folding across HEnterInlined. |
| 47 ASSERT(!HSimulate::cast(current->previous())-> |
| 48 is_candidate_for_removal()); |
| 49 } |
| 44 if (current->IsLeaveInlined()) { | 50 if (current->IsLeaveInlined()) { |
| 45 // Never fold simulates from inlined environments into simulates | 51 // Never fold simulates from inlined environments into simulates in the |
| 46 // in the outer environment. | 52 // outer environment. Simply remove all accumulated simulates without |
| 47 // (Before each HEnterInlined, there is a non-foldable HSimulate | 53 // merging. This is safe because simulates after instructions with side |
| 48 // anyway, so we get the barrier in the other direction for free.) | 54 // effects are never added to the merge list. |
| 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()) { | 55 while (!mergelist.is_empty()) { |
| 53 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); | 56 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); |
| 54 } | 57 } |
| 55 continue; | 58 continue; |
| 56 } | 59 } |
| 57 if (current->IsReturn()) { | 60 if (current->IsReturn()) { |
| 58 // Drop mergeable simulates in the list. This is safe because | 61 // Drop mergeable simulates in the list. This is safe because |
| 59 // simulates after instructions with side effects are never added | 62 // simulates after instructions with side effects are never added |
| 60 // to the merge list. | 63 // to the merge list. |
| 61 while (!mergelist.is_empty()) { | 64 while (!mergelist.is_empty()) { |
| 62 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); | 65 mergelist.RemoveLast()->DeleteAndReplaceWith(NULL); |
| 63 } | 66 } |
| 64 continue; | 67 continue; |
| 65 } | 68 } |
| 66 // Skip the non-simulates and the first simulate. | 69 // Skip the non-simulates and the first simulate. |
| 67 if (!current->IsSimulate()) continue; | 70 if (!current->IsSimulate()) continue; |
| 68 if (first) { | 71 if (first) { |
| 69 first = false; | 72 first = false; |
| 70 continue; | 73 continue; |
| 71 } | 74 } |
| 72 HSimulate* current_simulate = HSimulate::cast(current); | 75 HSimulate* current_simulate = HSimulate::cast(current); |
| 73 if ((current_simulate->previous()->HasObservableSideEffects() && | 76 if (!current_simulate->is_candidate_for_removal()) { |
| 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); | 77 current_simulate->MergeWith(&mergelist); |
| 79 continue; | 78 } else if (current_simulate->ast_id().IsNone()) { |
| 79 ASSERT(current_simulate->next()->IsEnterInlined()); |
| 80 if (!mergelist.is_empty()) { |
| 81 HSimulate* last = mergelist.RemoveLast(); |
| 82 last->MergeWith(&mergelist); |
| 83 } |
| 84 } else if (current_simulate->previous()->HasObservableSideEffects()) { |
| 85 while (current_simulate->next()->IsSimulate()) { |
| 86 it.Advance(); |
| 87 HSimulate* next_simulate = HSimulate::cast(it.Current()); |
| 88 if (next_simulate->ast_id().IsNone()) break; |
| 89 mergelist.Add(current_simulate, zone()); |
| 90 current_simulate = next_simulate; |
| 91 if (!current_simulate->is_candidate_for_removal()) break; |
| 92 } |
| 93 current_simulate->MergeWith(&mergelist); |
| 80 } else { | 94 } else { |
| 81 // Accumulate this simulate for folding later on. | 95 // Accumulate this simulate for folding later on. |
| 82 mergelist.Add(current_simulate, zone()); | 96 mergelist.Add(current_simulate, zone()); |
| 83 } | 97 } |
| 84 } | 98 } |
| 85 | 99 |
| 86 if (!mergelist.is_empty()) { | 100 if (!mergelist.is_empty()) { |
| 87 // Merge the accumulated simulates at the end of the block. | 101 // Merge the accumulated simulates at the end of the block. |
| 88 HSimulate* last = mergelist.RemoveLast(); | 102 HSimulate* last = mergelist.RemoveLast(); |
| 89 last->MergeWith(&mergelist); | 103 last->MergeWith(&mergelist); |
| 90 } | 104 } |
| 91 } | 105 } |
| 92 } | 106 } |
| 93 | 107 |
| 94 } } // namespace v8::internal | 108 } } // namespace v8::internal |
| OLD | NEW |