| 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.h" | 5 #include "vm/flow_graph.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/intermediate_language.h" | 9 #include "vm/intermediate_language.h" |
| 10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 Value* use = new(isolate()) Value((*env)[i]); | 993 Value* use = new(isolate()) Value((*env)[i]); |
| 994 phi->SetInputAt(pred_index, use); | 994 phi->SetInputAt(pred_index, use); |
| 995 } | 995 } |
| 996 } | 996 } |
| 997 } | 997 } |
| 998 } | 998 } |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 | 1001 |
| 1002 void FlowGraph::RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis) { | 1002 void FlowGraph::RemoveDeadPhis(GrowableArray<PhiInstr*>* live_phis) { |
| 1003 // Augment live_phis with those that have implicit real used at |
| 1004 // potentially throwing instructions if there is a try-catch in this graph. |
| 1005 if (graph_entry()->SuccessorCount() > 1) { |
| 1006 for (BlockIterator it(postorder_iterator()); !it.Done(); it.Advance()) { |
| 1007 JoinEntryInstr* join = it.Current()->AsJoinEntry(); |
| 1008 if (join == NULL) continue; |
| 1009 for (PhiIterator phi_it(join); !phi_it.Done(); phi_it.Advance()) { |
| 1010 PhiInstr* phi = phi_it.Current(); |
| 1011 if (phi == NULL || |
| 1012 phi->is_alive() || |
| 1013 (phi->input_use_list() != NULL) || |
| 1014 (phi->env_use_list() == NULL)) { |
| 1015 continue; |
| 1016 } |
| 1017 for (Value::Iterator it(phi->env_use_list()); |
| 1018 !it.Done(); |
| 1019 it.Advance()) { |
| 1020 Value* use = it.Current(); |
| 1021 if (use->instruction()->MayThrow() && |
| 1022 use->instruction()->GetBlock()->InsideTryBlock()) { |
| 1023 live_phis->Add(phi); |
| 1024 phi->mark_alive(); |
| 1025 break; |
| 1026 } |
| 1027 } |
| 1028 } |
| 1029 } |
| 1030 } |
| 1031 |
| 1003 while (!live_phis->is_empty()) { | 1032 while (!live_phis->is_empty()) { |
| 1004 PhiInstr* phi = live_phis->RemoveLast(); | 1033 PhiInstr* phi = live_phis->RemoveLast(); |
| 1005 for (intptr_t i = 0; i < phi->InputCount(); i++) { | 1034 for (intptr_t i = 0; i < phi->InputCount(); i++) { |
| 1006 Value* val = phi->InputAt(i); | 1035 Value* val = phi->InputAt(i); |
| 1007 PhiInstr* used_phi = val->definition()->AsPhi(); | 1036 PhiInstr* used_phi = val->definition()->AsPhi(); |
| 1008 if ((used_phi != NULL) && !used_phi->is_alive()) { | 1037 if ((used_phi != NULL) && !used_phi->is_alive()) { |
| 1009 used_phi->mark_alive(); | 1038 used_phi->mark_alive(); |
| 1010 live_phis->Add(used_phi); | 1039 live_phis->Add(used_phi); |
| 1011 } | 1040 } |
| 1012 } | 1041 } |
| 1013 } | 1042 } |
| 1014 | 1043 |
| 1015 for (BlockIterator it(postorder_iterator()); !it.Done(); it.Advance()) { | 1044 for (BlockIterator it(postorder_iterator()); !it.Done(); it.Advance()) { |
| 1016 JoinEntryInstr* join = it.Current()->AsJoinEntry(); | 1045 JoinEntryInstr* join = it.Current()->AsJoinEntry(); |
| 1017 if (join != NULL) join->RemoveDeadPhis(constant_null()); | 1046 if (join != NULL) join->RemoveDeadPhis(constant_dead()); |
| 1018 } | 1047 } |
| 1019 } | 1048 } |
| 1020 | 1049 |
| 1021 | 1050 |
| 1022 void FlowGraph::RemoveRedefinitions() { | 1051 void FlowGraph::RemoveRedefinitions() { |
| 1023 // Remove redefinition instructions inserted to inhibit hoisting. | 1052 // Remove redefinition instructions inserted to inhibit hoisting. |
| 1024 for (BlockIterator block_it = reverse_postorder_iterator(); | 1053 for (BlockIterator block_it = reverse_postorder_iterator(); |
| 1025 !block_it.Done(); | 1054 !block_it.Done(); |
| 1026 block_it.Advance()) { | 1055 block_it.Advance()) { |
| 1027 for (ForwardInstructionIterator instr_it(block_it.Current()); | 1056 for (ForwardInstructionIterator instr_it(block_it.Current()); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 } | 1279 } |
| 1251 | 1280 |
| 1252 | 1281 |
| 1253 bool BlockEffects::IsSideEffectFreePath(BlockEntryInstr* from, | 1282 bool BlockEffects::IsSideEffectFreePath(BlockEntryInstr* from, |
| 1254 BlockEntryInstr* to) const { | 1283 BlockEntryInstr* to) const { |
| 1255 return available_at_[to->postorder_number()]->Contains( | 1284 return available_at_[to->postorder_number()]->Contains( |
| 1256 from->postorder_number()); | 1285 from->postorder_number()); |
| 1257 } | 1286 } |
| 1258 | 1287 |
| 1259 } // namespace dart | 1288 } // namespace dart |
| OLD | NEW |