| 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_optimizer.h" | 5 #include "vm/flow_graph_optimizer.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 OS::Print("Removing v%"Pd".\n", | 151 OS::Print("Removing v%"Pd".\n", |
| 152 current->AsDefinition()->ssa_temp_index()); | 152 current->AsDefinition()->ssa_temp_index()); |
| 153 } else { | 153 } else { |
| 154 OS::Print("Removing %s\n", current->DebugName()); | 154 OS::Print("Removing %s\n", current->DebugName()); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 it->RemoveCurrentFromGraph(); | 157 it->RemoveCurrentFromGraph(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 | 160 |
| 161 void FlowGraphOptimizer::OptimizeComputations() { | 161 void FlowGraphOptimizer::Canonicalize() { |
| 162 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 162 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 163 BlockEntryInstr* entry = block_order_[i]; | 163 BlockEntryInstr* entry = block_order_[i]; |
| 164 entry->Accept(this); | 164 entry->Accept(this); |
| 165 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { | 165 for (ForwardInstructionIterator it(entry); !it.Done(); it.Advance()) { |
| 166 Instruction* current = it.Current(); | 166 Instruction* current = it.Current(); |
| 167 Instruction* replacement = current->Canonicalize(this); | 167 Instruction* replacement = current->Canonicalize(this); |
| 168 if (replacement != current) { | 168 if (replacement != current) { |
| 169 // For non-definitions Canonicalize should return either NULL or | 169 // For non-definitions Canonicalize should return either NULL or |
| 170 // this. | 170 // this. |
| 171 ASSERT((replacement == NULL) || current->IsDefinition()); | 171 ASSERT((replacement == NULL) || current->IsDefinition()); |
| (...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 field, | 1453 field, |
| 1454 instr->ArgumentAt(0)->value(), | 1454 instr->ArgumentAt(0)->value(), |
| 1455 instr->ArgumentAt(1)->value(), | 1455 instr->ArgumentAt(1)->value(), |
| 1456 needs_store_barrier); | 1456 needs_store_barrier); |
| 1457 instr->ReplaceWith(store, current_iterator()); | 1457 instr->ReplaceWith(store, current_iterator()); |
| 1458 RemovePushArguments(instr); | 1458 RemovePushArguments(instr); |
| 1459 return true; | 1459 return true; |
| 1460 } | 1460 } |
| 1461 | 1461 |
| 1462 | 1462 |
| 1463 // TODO(fschneider): Once we get rid of the distinction between Instruction | |
| 1464 // and computation, this helper can go away. | |
| 1465 static void HandleRelationalOp(FlowGraphOptimizer* optimizer, | 1463 static void HandleRelationalOp(FlowGraphOptimizer* optimizer, |
| 1466 RelationalOpInstr* comp, | 1464 RelationalOpInstr* comp, |
| 1467 Instruction* instr) { | 1465 Instruction* instr) { |
| 1468 if (!comp->HasICData() || (comp->ic_data()->NumberOfChecks() == 0)) { | 1466 if (!comp->HasICData() || (comp->ic_data()->NumberOfChecks() == 0)) { |
| 1469 return; | 1467 return; |
| 1470 } | 1468 } |
| 1471 const ICData& ic_data = *comp->ic_data(); | 1469 const ICData& ic_data = *comp->ic_data(); |
| 1472 if (ic_data.NumberOfChecks() == 1) { | 1470 if (ic_data.NumberOfChecks() == 1) { |
| 1473 ASSERT(ic_data.HasOneTarget()); | 1471 ASSERT(ic_data.HasOneTarget()); |
| 1474 if (HasOnlyTwoSmis(ic_data)) { | 1472 if (HasOnlyTwoSmis(ic_data)) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1496 comp->set_operands_class_id(kMintCid); | 1494 comp->set_operands_class_id(kMintCid); |
| 1497 } | 1495 } |
| 1498 } | 1496 } |
| 1499 | 1497 |
| 1500 | 1498 |
| 1501 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpInstr* instr) { | 1499 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpInstr* instr) { |
| 1502 HandleRelationalOp(this, instr, instr); | 1500 HandleRelationalOp(this, instr, instr); |
| 1503 } | 1501 } |
| 1504 | 1502 |
| 1505 | 1503 |
| 1506 // TODO(fschneider): Once we get rid of the distinction between Instruction | |
| 1507 // and computation, this helper can go away. | |
| 1508 template <typename T> | 1504 template <typename T> |
| 1509 static void HandleEqualityCompare(FlowGraphOptimizer* optimizer, | 1505 static void HandleEqualityCompare(FlowGraphOptimizer* optimizer, |
| 1510 EqualityCompareInstr* comp, | 1506 EqualityCompareInstr* comp, |
| 1511 T instr, | 1507 T instr, |
| 1512 ForwardInstructionIterator* iterator) { | 1508 ForwardInstructionIterator* iterator) { |
| 1513 // If one of the inputs is null, no ICdata will be collected. | 1509 // If one of the inputs is null, no ICdata will be collected. |
| 1514 if (comp->left()->BindsToConstantNull() || | 1510 if (comp->left()->BindsToConstantNull() || |
| 1515 comp->right()->BindsToConstantNull()) { | 1511 comp->right()->BindsToConstantNull()) { |
| 1516 Token::Kind strict_kind = (comp->kind() == Token::kEQ) ? | 1512 Token::Kind strict_kind = (comp->kind() == Token::kEQ) ? |
| 1517 Token::kEQ_STRICT : Token::kNE_STRICT; | 1513 Token::kEQ_STRICT : Token::kNE_STRICT; |
| (...skipping 2900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4418 | 4414 |
| 4419 if (FLAG_trace_constant_propagation) { | 4415 if (FLAG_trace_constant_propagation) { |
| 4420 OS::Print("\n==== After constant propagation ====\n"); | 4416 OS::Print("\n==== After constant propagation ====\n"); |
| 4421 FlowGraphPrinter printer(*graph_); | 4417 FlowGraphPrinter printer(*graph_); |
| 4422 printer.PrintBlocks(); | 4418 printer.PrintBlocks(); |
| 4423 } | 4419 } |
| 4424 } | 4420 } |
| 4425 | 4421 |
| 4426 | 4422 |
| 4427 } // namespace dart | 4423 } // namespace dart |
| OLD | NEW |