Chromium Code Reviews| 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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 worklist_(0) { } | 1044 worklist_(0) { } |
| 1045 | 1045 |
| 1046 void Propagate(); | 1046 void Propagate(); |
| 1047 | 1047 |
| 1048 private: | 1048 private: |
| 1049 void PropagateSminessRecursive(BlockEntryInstr* block); | 1049 void PropagateSminessRecursive(BlockEntryInstr* block); |
| 1050 void AddToWorklist(PhiInstr* phi); | 1050 void AddToWorklist(PhiInstr* phi); |
| 1051 PhiInstr* RemoveLastFromWorklist(); | 1051 PhiInstr* RemoveLastFromWorklist(); |
| 1052 void ProcessPhis(); | 1052 void ProcessPhis(); |
| 1053 | 1053 |
| 1054 bool IsPossiblySmiPhi(PhiInstr* phi); | |
| 1055 | |
| 1054 FlowGraph* flow_graph_; | 1056 FlowGraph* flow_graph_; |
| 1055 | 1057 |
| 1056 BitVector* known_smis_; | 1058 BitVector* known_smis_; |
| 1057 GrowableArray<intptr_t> rollback_checks_; | 1059 GrowableArray<intptr_t> rollback_checks_; |
| 1058 | 1060 |
| 1059 BitVector* in_worklist_; | 1061 BitVector* in_worklist_; |
| 1060 GrowableArray<PhiInstr*> worklist_; | 1062 GrowableArray<PhiInstr*> worklist_; |
| 1061 }; | 1063 }; |
| 1062 | 1064 |
| 1063 | 1065 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1074 | 1076 |
| 1075 PhiInstr* SminessPropagator::RemoveLastFromWorklist() { | 1077 PhiInstr* SminessPropagator::RemoveLastFromWorklist() { |
| 1076 PhiInstr* phi = worklist_.Last(); | 1078 PhiInstr* phi = worklist_.Last(); |
| 1077 ASSERT(in_worklist_->Contains(phi->ssa_temp_index())); | 1079 ASSERT(in_worklist_->Contains(phi->ssa_temp_index())); |
| 1078 worklist_.RemoveLast(); | 1080 worklist_.RemoveLast(); |
| 1079 in_worklist_->Remove(phi->ssa_temp_index()); | 1081 in_worklist_->Remove(phi->ssa_temp_index()); |
| 1080 return phi; | 1082 return phi; |
| 1081 } | 1083 } |
| 1082 | 1084 |
| 1083 | 1085 |
| 1084 static bool IsSmiPhi(PhiInstr* phi) { | 1086 static bool IsDefinitelySmiPhi(PhiInstr* phi) { |
| 1085 for (intptr_t i = 0; i < phi->InputCount(); i++) { | 1087 for (intptr_t i = 0; i < phi->InputCount(); i++) { |
| 1086 Value* input = phi->InputAt(i); | 1088 Value* input = phi->InputAt(i); |
| 1087 if ((input->definition() != phi) && | 1089 if (input->ResultCid() != kSmiCid) { |
| 1088 (input->ResultCid() != kSmiCid)) { | |
| 1089 return false; | 1090 return false; |
| 1090 } | 1091 } |
| 1091 } | 1092 } |
| 1093 return true; | |
| 1094 } | |
| 1095 | |
| 1096 | |
| 1097 bool SminessPropagator::IsPossiblySmiPhi(PhiInstr* phi) { | |
| 1098 for (intptr_t i = 0; i < phi->InputCount(); i++) { | |
| 1099 Value* input = phi->InputAt(i); | |
| 1100 if ((input->ResultCid() != kSmiCid) && | |
| 1101 !in_worklist_->Contains(input->definition()->ssa_temp_index())) { | |
|
Florian Schneider
2012/09/20 08:54:02
What about operands defined by phis that depend (p
| |
| 1102 return false; | |
| 1103 } | |
| 1104 } | |
| 1092 return true; | 1105 return true; |
| 1093 } | 1106 } |
| 1094 | 1107 |
| 1095 | 1108 |
| 1096 void SminessPropagator::ProcessPhis() { | 1109 void SminessPropagator::ProcessPhis() { |
| 1110 // First optimistically mark all possible smi-phis: phi is possibly a smi if | |
| 1111 // its operands are either smis or phis in the worklist. | |
| 1112 for (intptr_t i = 0; i < worklist_.length(); i++) { | |
| 1113 PhiInstr* phi = worklist_[i]; | |
| 1114 ASSERT(phi->GetPropagatedCid() == kDynamicCid); | |
| 1115 if (IsPossiblySmiPhi(phi)) phi->SetPropagatedCid(kSmiCid); | |
| 1116 } | |
| 1117 | |
| 1118 // Now unmark phis that are not definitely smi: that is have only | |
| 1119 // smi operands. | |
| 1097 while (!worklist_.is_empty()) { | 1120 while (!worklist_.is_empty()) { |
| 1098 PhiInstr* phi = RemoveLastFromWorklist(); | 1121 PhiInstr* phi = RemoveLastFromWorklist(); |
| 1099 if (IsSmiPhi(phi)) { | 1122 if (!IsDefinitelySmiPhi(phi)) { |
| 1100 ASSERT(phi->GetPropagatedCid() != kSmiCid); | 1123 // Phi result is not a smi. Propagate this fact to phis that depend on it. |
| 1101 phi->SetPropagatedCid(kSmiCid); | 1124 phi->SetPropagatedCid(kDynamicCid); |
| 1102 for (Value* use = phi->input_use_list(); | 1125 for (Value* use = phi->input_use_list(); |
| 1103 use != NULL; | 1126 use != NULL; |
| 1104 use = use->next_use()) { | 1127 use = use->next_use()) { |
| 1105 if (use->definition()->IsPhi() && | 1128 if (use->definition()->IsPhi() && |
| 1106 (use->definition()->GetPropagatedCid() != kSmiCid)) { | 1129 (use->definition()->GetPropagatedCid() == kSmiCid)) { |
| 1107 AddToWorklist(use->definition()->AsPhi()); | 1130 AddToWorklist(use->definition()->AsPhi()); |
| 1108 } | 1131 } |
| 1109 } | 1132 } |
| 1110 } | 1133 } |
| 1111 } | 1134 } |
| 1112 } | 1135 } |
| 1113 | 1136 |
| 1114 | 1137 |
| 1115 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) { | 1138 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) { |
| 1116 const intptr_t rollback_point = rollback_checks_.length(); | 1139 const intptr_t rollback_point = rollback_checks_.length(); |
| (...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2456 it.Advance()) { | 2479 it.Advance()) { |
| 2457 JoinEntryInstr* join = it.Current()->AsJoinEntry(); | 2480 JoinEntryInstr* join = it.Current()->AsJoinEntry(); |
| 2458 if (join != NULL) join->EliminateUnreachablePhiInputs(); | 2481 if (join != NULL) join->EliminateUnreachablePhiInputs(); |
| 2459 } | 2482 } |
| 2460 | 2483 |
| 2461 graph_->ComputeUseLists(); | 2484 graph_->ComputeUseLists(); |
| 2462 } | 2485 } |
| 2463 | 2486 |
| 2464 | 2487 |
| 2465 } // namespace dart | 2488 } // namespace dart |
| OLD | NEW |