| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/flow_graph_allocator.h" | 9 #include "vm/flow_graph_allocator.h" |
| 10 #include "vm/flow_graph_builder.h" | 10 #include "vm/flow_graph_builder.h" |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 other->LinkTo(this); | 563 other->LinkTo(this); |
| 564 iterator->RemoveCurrentFromGraph(); | 564 iterator->RemoveCurrentFromGraph(); |
| 565 } else { | 565 } else { |
| 566 other->LinkTo(next()); | 566 other->LinkTo(next()); |
| 567 } | 567 } |
| 568 set_previous(NULL); | 568 set_previous(NULL); |
| 569 set_next(NULL); | 569 set_next(NULL); |
| 570 } | 570 } |
| 571 | 571 |
| 572 | 572 |
| 573 // A misleadingly named function for use in template functions that replace |
| 574 // both definitions with definitions and branch comparisons with |
| 575 // comparisons. In the branch case, leave the branch intact and replace its |
| 576 // comparison with another comparison. |
| 577 void BranchInstr::ReplaceWith(ComparisonInstr* other, |
| 578 ForwardInstructionIterator* ignored) { |
| 579 // Record the new comparison's input uses. |
| 580 for (intptr_t i = other->InputCount() - 1; i >= 0; --i) { |
| 581 Value* input = other->InputAt(i); |
| 582 input->definition()->AddInputUse(input); |
| 583 } |
| 584 SetComparison(other); |
| 585 } |
| 586 |
| 587 |
| 588 void BranchInstr::SetComparison(ComparisonInstr* comp) { |
| 589 // The new comparison's input uses are already recorded in their |
| 590 // definition's use lists. |
| 591 for (intptr_t i = comp->InputCount() - 1; i >= 0; --i) { |
| 592 Value* input = comp->InputAt(i); |
| 593 input->set_instruction(this); |
| 594 input->set_use_index(i); |
| 595 } |
| 596 // There should be no need to copy or unuse an environment. |
| 597 ASSERT(comparison()->env() == NULL); |
| 598 // Remove the current comparison's input uses. |
| 599 comparison()->UnuseAllInputs(); |
| 600 ASSERT(!comp->HasUses()); |
| 601 comparison_ = comp; |
| 602 } |
| 603 |
| 604 |
| 573 // ==== Postorder graph traversal. | 605 // ==== Postorder graph traversal. |
| 574 static bool IsMarked(BlockEntryInstr* block, | 606 static bool IsMarked(BlockEntryInstr* block, |
| 575 GrowableArray<BlockEntryInstr*>* preorder) { | 607 GrowableArray<BlockEntryInstr*>* preorder) { |
| 576 // Detect that a block has been visited as part of the current | 608 // Detect that a block has been visited as part of the current |
| 577 // DiscoverBlocks (we can call DiscoverBlocks multiple times). The block | 609 // DiscoverBlocks (we can call DiscoverBlocks multiple times). The block |
| 578 // will be 'marked' by (1) having a preorder number in the range of the | 610 // will be 'marked' by (1) having a preorder number in the range of the |
| 579 // preorder array and (2) being in the preorder array at that index. | 611 // preorder array and (2) being in the preorder array at that index. |
| 580 intptr_t i = block->preorder_number(); | 612 intptr_t i = block->preorder_number(); |
| 581 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); | 613 return (i >= 0) && (i < preorder->length()) && ((*preorder)[i] == block); |
| 582 } | 614 } |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 comp->InputAt(i)->definition()->representation()) { | 1184 comp->InputAt(i)->definition()->representation()) { |
| 1153 return this; | 1185 return this; |
| 1154 } | 1186 } |
| 1155 } | 1187 } |
| 1156 | 1188 |
| 1157 // Replace the comparison if the replacement is used at this branch, | 1189 // Replace the comparison if the replacement is used at this branch, |
| 1158 // and has exactly one use. | 1190 // and has exactly one use. |
| 1159 if ((comp->input_use_list()->instruction() == this) && | 1191 if ((comp->input_use_list()->instruction() == this) && |
| 1160 (comp->input_use_list()->next_use() == NULL) && | 1192 (comp->input_use_list()->next_use() == NULL) && |
| 1161 (comp->env_use_list() == NULL)) { | 1193 (comp->env_use_list() == NULL)) { |
| 1162 comparison()->UnuseAllInputs(); | |
| 1163 comp->RemoveFromGraph(); | 1194 comp->RemoveFromGraph(); |
| 1164 // It is safe to pass a NULL iterator because we're replacing the | 1195 // It is safe to pass a NULL iterator because we're replacing the |
| 1165 // comparison wrapped in a BranchInstr which does not modify the | 1196 // comparison wrapped in a BranchInstr which does not modify the |
| 1166 // linked list of instructions. | 1197 // linked list of instructions. |
| 1167 ReplaceWith(comp, NULL /* ignored */); | 1198 SetComparison(comp); |
| 1168 for (intptr_t i = 0; i < comp->InputCount(); ++i) { | |
| 1169 Value* operand = comp->InputAt(i); | |
| 1170 operand->set_instruction(this); | |
| 1171 } | |
| 1172 if (FLAG_trace_optimization) { | 1199 if (FLAG_trace_optimization) { |
| 1173 OS::Print("Merging comparison v%"Pd"\n", comp->ssa_temp_index()); | 1200 OS::Print("Merging comparison v%"Pd"\n", comp->ssa_temp_index()); |
| 1174 } | 1201 } |
| 1175 // Clear the comparison's temp index and ssa temp index since the | 1202 // Clear the comparison's temp index and ssa temp index since the |
| 1176 // value of the comparison is not used outside the branch anymore. | 1203 // value of the comparison is not used outside the branch anymore. |
| 1177 ASSERT(comp->input_use_list() == NULL); | 1204 ASSERT(comp->input_use_list() == NULL); |
| 1178 comp->ClearSSATempIndex(); | 1205 comp->ClearSSATempIndex(); |
| 1179 comp->ClearTempIndex(); | 1206 comp->ClearTempIndex(); |
| 1180 } | 1207 } |
| 1181 } | 1208 } |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 default: | 2228 default: |
| 2202 UNREACHABLE(); | 2229 UNREACHABLE(); |
| 2203 } | 2230 } |
| 2204 return kPowRuntimeEntry; | 2231 return kPowRuntimeEntry; |
| 2205 } | 2232 } |
| 2206 | 2233 |
| 2207 | 2234 |
| 2208 #undef __ | 2235 #undef __ |
| 2209 | 2236 |
| 2210 } // namespace dart | 2237 } // namespace dart |
| OLD | NEW |