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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 default: | 605 default: |
606 // TODO(fschneider): Add support for other array types. | 606 // TODO(fschneider): Add support for other array types. |
607 UNREACHABLE(); | 607 UNREACHABLE(); |
608 } | 608 } |
609 AssertAssignableInstr* assert_value = | 609 AssertAssignableInstr* assert_value = |
610 new AssertAssignableInstr(call->token_pos(), | 610 new AssertAssignableInstr(call->token_pos(), |
611 value->Copy(), | 611 value->Copy(), |
612 instantiator, | 612 instantiator, |
613 type_args, | 613 type_args, |
614 value_type, | 614 value_type, |
615 String::ZoneHandle(Symbols::New("value"))); | 615 Symbols::Value()); |
616 InsertBefore(call, assert_value, NULL, Definition::kValue); | 616 InsertBefore(call, assert_value, NULL, Definition::kValue); |
617 } | 617 } |
618 | 618 |
619 Value* array = NULL; | 619 Value* array = NULL; |
620 Value* index = NULL; | 620 Value* index = NULL; |
621 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); | 621 intptr_t array_cid = PrepareIndexedOp(call, class_id, &array, &index); |
622 Value* value = call->ArgumentAt(2)->value(); | 622 Value* value = call->ArgumentAt(2)->value(); |
623 // Check if store barrier is needed. | 623 // Check if store barrier is needed. |
624 bool needs_store_barrier = true; | 624 bool needs_store_barrier = true; |
625 if ((class_id == kFloat32ArrayCid) || (class_id == kFloat64ArrayCid)) { | 625 if ((class_id == kFloat32ArrayCid) || (class_id == kFloat64ArrayCid)) { |
(...skipping 1887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2513 instr->ReplaceUsesWith(result); | 2513 instr->ReplaceUsesWith(result); |
2514 ASSERT(current_iterator()->Current() == instr); | 2514 ASSERT(current_iterator()->Current() == instr); |
2515 current_iterator()->RemoveCurrentFromGraph(); | 2515 current_iterator()->RemoveCurrentFromGraph(); |
2516 if (FLAG_trace_optimization) { | 2516 if (FLAG_trace_optimization) { |
2517 OS::Print("Replacing v%"Pd" with v%"Pd"\n", | 2517 OS::Print("Replacing v%"Pd" with v%"Pd"\n", |
2518 instr->ssa_temp_index(), | 2518 instr->ssa_temp_index(), |
2519 result->ssa_temp_index()); | 2519 result->ssa_temp_index()); |
2520 } | 2520 } |
2521 | 2521 |
2522 if (FLAG_trace_type_check_elimination) { | 2522 if (FLAG_trace_type_check_elimination) { |
2523 const String& name = String::Handle(Symbols::New("boolean expression")); | |
2524 FlowGraphPrinter::PrintTypeCheck(parsed_function(), | 2523 FlowGraphPrinter::PrintTypeCheck(parsed_function(), |
2525 instr->token_pos(), | 2524 instr->token_pos(), |
2526 instr->value(), | 2525 instr->value(), |
2527 Type::Handle(Type::BoolType()), | 2526 Type::Handle(Type::BoolType()), |
2528 name, | 2527 Symbols::BooleanExpression(), |
2529 instr->is_eliminated()); | 2528 instr->is_eliminated()); |
2530 } | 2529 } |
2531 } | 2530 } |
2532 } | 2531 } |
2533 | 2532 |
2534 | 2533 |
2535 void FlowGraphTypePropagator::VisitInstanceOf(InstanceOfInstr* instr) { | 2534 void FlowGraphTypePropagator::VisitInstanceOf(InstanceOfInstr* instr) { |
2536 bool is_null; | 2535 bool is_null; |
2537 bool is_instance = false; | 2536 bool is_instance = false; |
2538 if (FLAG_eliminate_type_checks && | 2537 if (FLAG_eliminate_type_checks && |
2539 instr->value()->CanComputeIsNull(&is_null) && | 2538 instr->value()->CanComputeIsNull(&is_null) && |
2540 (is_null || | 2539 (is_null || |
2541 instr->value()->CanComputeIsInstanceOf(instr->type(), &is_instance))) { | 2540 instr->value()->CanComputeIsInstanceOf(instr->type(), &is_instance))) { |
2542 Definition* result = new ConstantInstr(Bool::ZoneHandle(Bool::Get( | 2541 Definition* result = new ConstantInstr(Bool::ZoneHandle(Bool::Get( |
2543 instr->negate_result() ? !is_instance : is_instance))); | 2542 instr->negate_result() ? !is_instance : is_instance))); |
2544 result->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); | 2543 result->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
2545 result->InsertBefore(instr); | 2544 result->InsertBefore(instr); |
2546 // Replace uses and remove the current instruction via the iterator. | 2545 // Replace uses and remove the current instruction via the iterator. |
2547 instr->ReplaceUsesWith(result); | 2546 instr->ReplaceUsesWith(result); |
2548 ASSERT(current_iterator()->Current() == instr); | 2547 ASSERT(current_iterator()->Current() == instr); |
2549 current_iterator()->RemoveCurrentFromGraph(); | 2548 current_iterator()->RemoveCurrentFromGraph(); |
2550 if (FLAG_trace_optimization) { | 2549 if (FLAG_trace_optimization) { |
2551 OS::Print("Replacing v%"Pd" with v%"Pd"\n", | 2550 OS::Print("Replacing v%"Pd" with v%"Pd"\n", |
2552 instr->ssa_temp_index(), | 2551 instr->ssa_temp_index(), |
2553 result->ssa_temp_index()); | 2552 result->ssa_temp_index()); |
2554 } | 2553 } |
2555 | 2554 |
2556 if (FLAG_trace_type_check_elimination) { | 2555 if (FLAG_trace_type_check_elimination) { |
2557 const String& name = String::Handle(Symbols::New("InstanceOf")); | |
2558 FlowGraphPrinter::PrintTypeCheck(parsed_function(), | 2556 FlowGraphPrinter::PrintTypeCheck(parsed_function(), |
2559 instr->token_pos(), | 2557 instr->token_pos(), |
2560 instr->value(), | 2558 instr->value(), |
2561 instr->type(), | 2559 instr->type(), |
2562 name, | 2560 Symbols::InstanceOf(), |
2563 /* eliminated = */ true); | 2561 /* eliminated = */ true); |
2564 } | 2562 } |
2565 } | 2563 } |
2566 } | 2564 } |
2567 | 2565 |
2568 | 2566 |
2569 void FlowGraphTypePropagator::VisitGraphEntry(GraphEntryInstr* graph_entry) { | 2567 void FlowGraphTypePropagator::VisitGraphEntry(GraphEntryInstr* graph_entry) { |
2570 // Visit incoming parameters. | 2568 // Visit incoming parameters. |
2571 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { | 2569 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { |
2572 ParameterInstr* param = | 2570 ParameterInstr* param = |
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4351 | 4349 |
4352 if (FLAG_trace_constant_propagation) { | 4350 if (FLAG_trace_constant_propagation) { |
4353 OS::Print("\n==== After constant propagation ====\n"); | 4351 OS::Print("\n==== After constant propagation ====\n"); |
4354 FlowGraphPrinter printer(*graph_); | 4352 FlowGraphPrinter printer(*graph_); |
4355 printer.PrintBlocks(); | 4353 printer.PrintBlocks(); |
4356 } | 4354 } |
4357 } | 4355 } |
4358 | 4356 |
4359 | 4357 |
4360 } // namespace dart | 4358 } // namespace dart |
OLD | NEW |