| 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/hash_map.h" | 10 #include "vm/hash_map.h" |
| (...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 // TODO(regis): Propagate NullType as well and revise the comment and code | 1246 // TODO(regis): Propagate NullType as well and revise the comment and code |
| 1247 // below to also eliminate the test for non-null and non-constant value. | 1247 // below to also eliminate the test for non-null and non-constant value. |
| 1248 | 1248 |
| 1249 // We can only eliminate an 'instance of' test when the checked value is | 1249 // We can only eliminate an 'instance of' test when the checked value is |
| 1250 // a constant time constant. Indeed, a variable of the proper compile time | 1250 // a constant time constant. Indeed, a variable of the proper compile time |
| 1251 // type may still hold null at run time and therefore fail the test. | 1251 // type may still hold null at run time and therefore fail the test. |
| 1252 // We do not bother checking for Object destination type, since the graph | 1252 // We do not bother checking for Object destination type, since the graph |
| 1253 // builder did already. | 1253 // builder did already. |
| 1254 if (FLAG_eliminate_type_checks && | 1254 if (FLAG_eliminate_type_checks && |
| 1255 instr->value()->BindsToConstant() && | 1255 instr->value()->BindsToConstant() && |
| 1256 !instr->value()->BindsToConstantNull() && | 1256 !instr->value()->BindsToConstantNull()) { |
| 1257 instr->value()->CompileTypeIsMoreSpecificThan(instr->type())) { | 1257 const Bool& bool_result = |
| 1258 Value* use = instr->value(); | 1258 instr->value()->CompileTypeIsMoreSpecificThan(instr->type()) ? |
| 1259 Definition* result = use->definition(); | 1259 Bool::ZoneHandle(Bool::True()) : Bool::ZoneHandle(Bool::False()); |
| 1260 ASSERT(result != NULL); | 1260 Definition* result = new ConstantInstr(bool_result); |
| 1261 result->set_ssa_temp_index(flow_graph_->alloc_ssa_temp_index()); |
| 1262 result->InsertBefore(instr); |
| 1261 // Replace uses and remove the current instruction via the iterator. | 1263 // Replace uses and remove the current instruction via the iterator. |
| 1262 instr->ReplaceUsesWith(result); | 1264 instr->ReplaceUsesWith(result); |
| 1263 ASSERT(current_iterator()->Current() == instr); | 1265 ASSERT(current_iterator()->Current() == instr); |
| 1264 current_iterator()->RemoveCurrentFromGraph(); | 1266 current_iterator()->RemoveCurrentFromGraph(); |
| 1265 if (FLAG_trace_optimization) { | 1267 if (FLAG_trace_optimization) { |
| 1266 OS::Print("Replacing v%"Pd" with v%"Pd"\n", | 1268 OS::Print("Replacing v%"Pd" with v%"Pd"\n", |
| 1267 instr->ssa_temp_index(), | 1269 instr->ssa_temp_index(), |
| 1268 result->ssa_temp_index()); | 1270 result->ssa_temp_index()); |
| 1269 } | 1271 } |
| 1270 | 1272 |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 DirectChainedHashMap<Definition*> child_map(*map); // Copy map. | 1569 DirectChainedHashMap<Definition*> child_map(*map); // Copy map. |
| 1568 OptimizeRecursive(child, &child_map); | 1570 OptimizeRecursive(child, &child_map); |
| 1569 } else { | 1571 } else { |
| 1570 OptimizeRecursive(child, map); // Reuse map for the last child. | 1572 OptimizeRecursive(child, map); // Reuse map for the last child. |
| 1571 } | 1573 } |
| 1572 } | 1574 } |
| 1573 } | 1575 } |
| 1574 | 1576 |
| 1575 | 1577 |
| 1576 } // namespace dart | 1578 } // namespace dart |
| OLD | NEW |