OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/flow_graph.h" | 5 #include "vm/flow_graph.h" |
6 | 6 |
7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 for (PhiIterator it(join); !it.Done(); it.Advance()) { | 476 for (PhiIterator it(join); !it.Done(); it.Advance()) { |
477 PhiInstr* phi = it.Current(); | 477 PhiInstr* phi = it.Current(); |
478 ASSERT(phi != NULL); | 478 ASSERT(phi != NULL); |
479 VerifyUseListsInInstruction(phi); | 479 VerifyUseListsInInstruction(phi); |
480 } | 480 } |
481 } | 481 } |
482 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 482 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
483 VerifyUseListsInInstruction(it.Current()); | 483 VerifyUseListsInInstruction(it.Current()); |
484 } | 484 } |
485 } | 485 } |
| 486 |
486 return true; // Return true so we can ASSERT validation. | 487 return true; // Return true so we can ASSERT validation. |
487 } | 488 } |
488 | 489 |
489 | 490 |
| 491 // Verify that a redefinition dominates all uses of the redefined value. |
| 492 bool FlowGraph::VerifyRedefinitions() { |
| 493 for (BlockIterator block_it = reverse_postorder_iterator(); !block_it.Done(); |
| 494 block_it.Advance()) { |
| 495 for (ForwardInstructionIterator instr_it(block_it.Current()); |
| 496 !instr_it.Done(); instr_it.Advance()) { |
| 497 RedefinitionInstr* redefinition = instr_it.Current()->AsRedefinition(); |
| 498 if (redefinition != NULL) { |
| 499 Definition* original = redefinition->value()->definition(); |
| 500 for (Value::Iterator it(original->input_use_list()); !it.Done(); |
| 501 it.Advance()) { |
| 502 Value* original_use = it.Current(); |
| 503 if (original_use->instruction() == redefinition) { |
| 504 continue; |
| 505 } |
| 506 if (original_use->instruction()->IsDominatedBy(redefinition)) { |
| 507 FlowGraphPrinter::PrintGraph("VerifyRedefinitions", this); |
| 508 THR_Print("%s\n", redefinition->ToCString()); |
| 509 THR_Print("use=%s\n", original_use->instruction()->ToCString()); |
| 510 return false; |
| 511 } |
| 512 } |
| 513 } |
| 514 } |
| 515 } |
| 516 return true; |
| 517 } |
| 518 |
| 519 |
490 LivenessAnalysis::LivenessAnalysis( | 520 LivenessAnalysis::LivenessAnalysis( |
491 intptr_t variable_count, | 521 intptr_t variable_count, |
492 const GrowableArray<BlockEntryInstr*>& postorder) | 522 const GrowableArray<BlockEntryInstr*>& postorder) |
493 : zone_(Thread::Current()->zone()), | 523 : zone_(Thread::Current()->zone()), |
494 variable_count_(variable_count), | 524 variable_count_(variable_count), |
495 postorder_(postorder), | 525 postorder_(postorder), |
496 live_out_(postorder.length()), | 526 live_out_(postorder.length()), |
497 kill_(postorder.length()), | 527 kill_(postorder.length()), |
498 live_in_(postorder.length()) {} | 528 live_in_(postorder.length()) {} |
499 | 529 |
(...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 Definition* other) { | 2119 Definition* other) { |
2090 for (Value::Iterator it(def->input_use_list()); !it.Done(); it.Advance()) { | 2120 for (Value::Iterator it(def->input_use_list()); !it.Done(); it.Advance()) { |
2091 Value* use = it.Current(); | 2121 Value* use = it.Current(); |
2092 if (IsDominatedUse(dom, use)) { | 2122 if (IsDominatedUse(dom, use)) { |
2093 use->BindTo(other); | 2123 use->BindTo(other); |
2094 } | 2124 } |
2095 } | 2125 } |
2096 } | 2126 } |
2097 | 2127 |
2098 | 2128 |
| 2129 void FlowGraph::RenameUsesDominatedByRedefinitions() { |
| 2130 for (BlockIterator block_it = reverse_postorder_iterator(); !block_it.Done(); |
| 2131 block_it.Advance()) { |
| 2132 for (ForwardInstructionIterator instr_it(block_it.Current()); |
| 2133 !instr_it.Done(); instr_it.Advance()) { |
| 2134 RedefinitionInstr* redefinition = instr_it.Current()->AsRedefinition(); |
| 2135 if (redefinition != NULL) { |
| 2136 Definition* original = redefinition->value()->definition(); |
| 2137 RenameDominatedUses(original, redefinition, redefinition); |
| 2138 } |
| 2139 } |
| 2140 } |
| 2141 } |
| 2142 |
| 2143 |
2099 static bool IsPositiveOrZeroSmiConst(Definition* d) { | 2144 static bool IsPositiveOrZeroSmiConst(Definition* d) { |
2100 ConstantInstr* const_instr = d->AsConstant(); | 2145 ConstantInstr* const_instr = d->AsConstant(); |
2101 if ((const_instr != NULL) && (const_instr->value().IsSmi())) { | 2146 if ((const_instr != NULL) && (const_instr->value().IsSmi())) { |
2102 return Smi::Cast(const_instr->value()).Value() >= 0; | 2147 return Smi::Cast(const_instr->value()).Value() >= 0; |
2103 } | 2148 } |
2104 return false; | 2149 return false; |
2105 } | 2150 } |
2106 | 2151 |
2107 | 2152 |
2108 static BinarySmiOpInstr* AsSmiShiftLeftInstruction(Definition* d) { | 2153 static BinarySmiOpInstr* AsSmiShiftLeftInstruction(Definition* d) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 Representation rep, | 2274 Representation rep, |
2230 intptr_t cid) { | 2275 intptr_t cid) { |
2231 ExtractNthOutputInstr* extract = | 2276 ExtractNthOutputInstr* extract = |
2232 new (Z) ExtractNthOutputInstr(new (Z) Value(instr), index, rep, cid); | 2277 new (Z) ExtractNthOutputInstr(new (Z) Value(instr), index, rep, cid); |
2233 instr->ReplaceUsesWith(extract); | 2278 instr->ReplaceUsesWith(extract); |
2234 InsertAfter(instr, extract, NULL, FlowGraph::kValue); | 2279 InsertAfter(instr, extract, NULL, FlowGraph::kValue); |
2235 } | 2280 } |
2236 | 2281 |
2237 | 2282 |
2238 } // namespace dart | 2283 } // namespace dart |
OLD | NEW |