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 13 matching lines...) Expand all Loading... |
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-escape-analysis.h" | 28 #include "hydrogen-escape-analysis.h" |
29 | 29 |
30 namespace v8 { | 30 namespace v8 { |
31 namespace internal { | 31 namespace internal { |
32 | 32 |
33 | 33 |
34 bool HEscapeAnalysisPhase::HasNoEscapingUses(HValue* value) { | 34 bool HEscapeAnalysisPhase::HasNoEscapingUses(HValue* value, int size) { |
35 for (HUseIterator it(value->uses()); !it.Done(); it.Advance()) { | 35 for (HUseIterator it(value->uses()); !it.Done(); it.Advance()) { |
36 HValue* use = it.value(); | 36 HValue* use = it.value(); |
37 if (use->HasEscapingOperandAt(it.index())) { | 37 if (use->HasEscapingOperandAt(it.index())) { |
38 if (FLAG_trace_escape_analysis) { | 38 if (FLAG_trace_escape_analysis) { |
39 PrintF("#%d (%s) escapes through #%d (%s) @%d\n", value->id(), | 39 PrintF("#%d (%s) escapes through #%d (%s) @%d\n", value->id(), |
40 value->Mnemonic(), use->id(), use->Mnemonic(), it.index()); | 40 value->Mnemonic(), use->id(), use->Mnemonic(), it.index()); |
41 } | 41 } |
42 return false; | 42 return false; |
43 } | 43 } |
44 if (use->RedefinedOperandIndex() == it.index() && !HasNoEscapingUses(use)) { | 44 if (use->HasOutOfBoundsAccess(size)) { |
| 45 if (FLAG_trace_escape_analysis) { |
| 46 PrintF("#%d (%s) out of bounds at #%d (%s) @%d\n", value->id(), |
| 47 value->Mnemonic(), use->id(), use->Mnemonic(), it.index()); |
| 48 } |
| 49 return false; |
| 50 } |
| 51 int redefined_index = use->RedefinedOperandIndex(); |
| 52 if (redefined_index == it.index() && !HasNoEscapingUses(use, size)) { |
45 if (FLAG_trace_escape_analysis) { | 53 if (FLAG_trace_escape_analysis) { |
46 PrintF("#%d (%s) escapes redefinition #%d (%s) @%d\n", value->id(), | 54 PrintF("#%d (%s) escapes redefinition #%d (%s) @%d\n", value->id(), |
47 value->Mnemonic(), use->id(), use->Mnemonic(), it.index()); | 55 value->Mnemonic(), use->id(), use->Mnemonic(), it.index()); |
48 } | 56 } |
49 return false; | 57 return false; |
50 } | 58 } |
51 } | 59 } |
52 return true; | 60 return true; |
53 } | 61 } |
54 | 62 |
55 | 63 |
56 void HEscapeAnalysisPhase::CollectCapturedValues() { | 64 void HEscapeAnalysisPhase::CollectCapturedValues() { |
57 int block_count = graph()->blocks()->length(); | 65 int block_count = graph()->blocks()->length(); |
58 for (int i = 0; i < block_count; ++i) { | 66 for (int i = 0; i < block_count; ++i) { |
59 HBasicBlock* block = graph()->blocks()->at(i); | 67 HBasicBlock* block = graph()->blocks()->at(i); |
60 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | 68 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { |
61 HInstruction* instr = it.Current(); | 69 HInstruction* instr = it.Current(); |
62 if (instr->IsAllocate() && HasNoEscapingUses(instr)) { | 70 if (!instr->IsAllocate()) continue; |
| 71 HAllocate* allocate = HAllocate::cast(instr); |
| 72 if (!allocate->size()->IsInteger32Constant()) continue; |
| 73 int size_in_bytes = allocate->size()->GetInteger32Constant(); |
| 74 if (HasNoEscapingUses(instr, size_in_bytes)) { |
63 if (FLAG_trace_escape_analysis) { | 75 if (FLAG_trace_escape_analysis) { |
64 PrintF("#%d (%s) is being captured\n", instr->id(), | 76 PrintF("#%d (%s) is being captured\n", instr->id(), |
65 instr->Mnemonic()); | 77 instr->Mnemonic()); |
66 } | 78 } |
67 captured_.Add(instr, zone()); | 79 captured_.Add(instr, zone()); |
68 } | 80 } |
69 } | 81 } |
70 } | 82 } |
71 } | 83 } |
72 | 84 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 ASSERT(allocate->HasNoUses()); | 295 ASSERT(allocate->HasNoUses()); |
284 allocate->DeleteAndReplaceWith(NULL); | 296 allocate->DeleteAndReplaceWith(NULL); |
285 } | 297 } |
286 | 298 |
287 | 299 |
288 void HEscapeAnalysisPhase::PerformScalarReplacement() { | 300 void HEscapeAnalysisPhase::PerformScalarReplacement() { |
289 for (int i = 0; i < captured_.length(); i++) { | 301 for (int i = 0; i < captured_.length(); i++) { |
290 HAllocate* allocate = HAllocate::cast(captured_.at(i)); | 302 HAllocate* allocate = HAllocate::cast(captured_.at(i)); |
291 | 303 |
292 // Compute number of scalar values and start with clean slate. | 304 // Compute number of scalar values and start with clean slate. |
293 if (!allocate->size()->IsInteger32Constant()) continue; | |
294 int size_in_bytes = allocate->size()->GetInteger32Constant(); | 305 int size_in_bytes = allocate->size()->GetInteger32Constant(); |
295 number_of_values_ = size_in_bytes / kPointerSize; | 306 number_of_values_ = size_in_bytes / kPointerSize; |
296 number_of_objects_++; | 307 number_of_objects_++; |
297 block_states_.Clear(); | 308 block_states_.Clear(); |
298 | 309 |
299 // Perform actual analysis steps. | 310 // Perform actual analysis steps. |
300 AnalyzeDataFlow(allocate); | 311 AnalyzeDataFlow(allocate); |
301 | 312 |
302 cumulative_values_ += number_of_values_; | 313 cumulative_values_ += number_of_values_; |
303 ASSERT(allocate->HasNoUses()); | 314 ASSERT(allocate->HasNoUses()); |
304 ASSERT(!allocate->IsLinked()); | 315 ASSERT(!allocate->IsLinked()); |
305 } | 316 } |
306 } | 317 } |
307 | 318 |
308 | 319 |
309 void HEscapeAnalysisPhase::Run() { | 320 void HEscapeAnalysisPhase::Run() { |
310 // TODO(mstarzinger): We disable escape analysis with OSR for now, because | 321 // TODO(mstarzinger): We disable escape analysis with OSR for now, because |
311 // spill slots might be uninitialized. Needs investigation. | 322 // spill slots might be uninitialized. Needs investigation. |
312 if (graph()->has_osr()) return; | 323 if (graph()->has_osr()) return; |
313 CollectCapturedValues(); | 324 CollectCapturedValues(); |
314 PerformScalarReplacement(); | 325 PerformScalarReplacement(); |
315 } | 326 } |
316 | 327 |
317 | 328 |
318 } } // namespace v8::internal | 329 } } // namespace v8::internal |
OLD | NEW |