| 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/cha.h" | 7 #include "vm/cha.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 // below to also eliminate the test for non-null and non-constant value. | 791 // below to also eliminate the test for non-null and non-constant value. |
| 792 | 792 |
| 793 // We can only eliminate an 'assert boolean' test when the checked value is | 793 // We can only eliminate an 'assert boolean' test when the checked value is |
| 794 // a constant time constant. Indeed, a variable of the proper compile time | 794 // a constant time constant. Indeed, a variable of the proper compile time |
| 795 // type (bool) may still hold null at run time and therefore fail the test. | 795 // type (bool) may still hold null at run time and therefore fail the test. |
| 796 if (FLAG_eliminate_type_checks && | 796 if (FLAG_eliminate_type_checks && |
| 797 !comp->is_eliminated() && | 797 !comp->is_eliminated() && |
| 798 comp->value()->BindsToConstant() && | 798 comp->value()->BindsToConstant() && |
| 799 !comp->value()->BindsToConstantNull() && | 799 !comp->value()->BindsToConstantNull() && |
| 800 comp->value()->CompileTypeIsMoreSpecificThan( | 800 comp->value()->CompileTypeIsMoreSpecificThan( |
| 801 Type::Handle(Type::BoolInterface()))) { | 801 Type::Handle(Type::BoolType()))) { |
| 802 // TODO(regis): Remove is_eliminated_ field and support. | 802 // TODO(regis): Remove is_eliminated_ field and support. |
| 803 comp->eliminate(); | 803 comp->eliminate(); |
| 804 | 804 |
| 805 UseVal* use = comp->value()->AsUse(); | 805 UseVal* use = comp->value()->AsUse(); |
| 806 ASSERT(use != NULL); | 806 ASSERT(use != NULL); |
| 807 Definition* result = use->definition(); | 807 Definition* result = use->definition(); |
| 808 ASSERT(result != NULL); | 808 ASSERT(result != NULL); |
| 809 // Replace uses and remove the current instructions via the iterator. | 809 // Replace uses and remove the current instructions via the iterator. |
| 810 instr->ReplaceUsesWith(result); | 810 instr->ReplaceUsesWith(result); |
| 811 ASSERT(current_iterator()->Current() == instr); | 811 ASSERT(current_iterator()->Current() == instr); |
| 812 current_iterator()->RemoveCurrentFromGraph(); | 812 current_iterator()->RemoveCurrentFromGraph(); |
| 813 if (FLAG_trace_optimization) { | 813 if (FLAG_trace_optimization) { |
| 814 OS::Print("Replacing v%d with v%d\n", | 814 OS::Print("Replacing v%d with v%d\n", |
| 815 instr->ssa_temp_index(), | 815 instr->ssa_temp_index(), |
| 816 result->ssa_temp_index()); | 816 result->ssa_temp_index()); |
| 817 } | 817 } |
| 818 | 818 |
| 819 if (FLAG_trace_type_check_elimination) { | 819 if (FLAG_trace_type_check_elimination) { |
| 820 const String& name = String::Handle(Symbols::New("boolean expression")); | 820 const String& name = String::Handle(Symbols::New("boolean expression")); |
| 821 FlowGraphPrinter::PrintTypeCheck(parsed_function(), | 821 FlowGraphPrinter::PrintTypeCheck(parsed_function(), |
| 822 comp->token_pos(), | 822 comp->token_pos(), |
| 823 comp->value(), | 823 comp->value(), |
| 824 Type::Handle(Type::BoolInterface()), | 824 Type::Handle(Type::BoolType()), |
| 825 name, | 825 name, |
| 826 comp->is_eliminated()); | 826 comp->is_eliminated()); |
| 827 } | 827 } |
| 828 } | 828 } |
| 829 } | 829 } |
| 830 | 830 |
| 831 | 831 |
| 832 void FlowGraphTypePropagator::VisitInstanceOf(InstanceOfComp* comp, | 832 void FlowGraphTypePropagator::VisitInstanceOf(InstanceOfComp* comp, |
| 833 BindInstr* instr) { | 833 BindInstr* instr) { |
| 834 // TODO(regis): Propagate NullType as well and revise the comment and code | 834 // TODO(regis): Propagate NullType as well and revise the comment and code |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 DirectChainedHashMap<BindInstr*> child_map(*map); // Copy map. | 1063 DirectChainedHashMap<BindInstr*> child_map(*map); // Copy map. |
| 1064 OptimizeRecursive(child, &child_map); | 1064 OptimizeRecursive(child, &child_map); |
| 1065 } else { | 1065 } else { |
| 1066 OptimizeRecursive(child, map); // Reuse map for the last child. | 1066 OptimizeRecursive(child, map); // Reuse map for the last child. |
| 1067 } | 1067 } |
| 1068 } | 1068 } |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 | 1071 |
| 1072 } // namespace dart | 1072 } // namespace dart |
| OLD | NEW |