Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: runtime/vm/flow_graph_optimizer.cc

Issue 10950035: Improve SminessPropagator to propagate sminess across cycles of phis. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: done Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 1074
1075 PhiInstr* SminessPropagator::RemoveLastFromWorklist() { 1075 PhiInstr* SminessPropagator::RemoveLastFromWorklist() {
1076 PhiInstr* phi = worklist_.Last(); 1076 PhiInstr* phi = worklist_.Last();
1077 ASSERT(in_worklist_->Contains(phi->ssa_temp_index())); 1077 ASSERT(in_worklist_->Contains(phi->ssa_temp_index()));
1078 worklist_.RemoveLast(); 1078 worklist_.RemoveLast();
1079 in_worklist_->Remove(phi->ssa_temp_index()); 1079 in_worklist_->Remove(phi->ssa_temp_index());
1080 return phi; 1080 return phi;
1081 } 1081 }
1082 1082
1083 1083
1084 static bool IsSmiPhi(PhiInstr* phi) { 1084 static bool IsDefinitelySmiPhi(PhiInstr* phi) {
1085 for (intptr_t i = 0; i < phi->InputCount(); i++) { 1085 for (intptr_t i = 0; i < phi->InputCount(); i++) {
1086 Value* input = phi->InputAt(i); 1086 const intptr_t cid = phi->InputAt(i)->ResultCid();
1087 if ((input->definition() != phi) && 1087 if (cid != kSmiCid) {
1088 (input->ResultCid() != kSmiCid)) {
1089 return false; 1088 return false;
1090 } 1089 }
1091 } 1090 }
1091 return true;
1092 }
1093
1094
1095 static bool IsPossiblySmiPhi(PhiInstr* phi) {
1096 for (intptr_t i = 0; i < phi->InputCount(); i++) {
1097 const intptr_t cid = phi->InputAt(i)->ResultCid();
1098 if ((cid != kSmiCid) && (cid != kDynamicCid)) {
1099 return false;
1100 }
1101 }
1092 return true; 1102 return true;
1093 } 1103 }
1094 1104
1095 1105
1096 void SminessPropagator::ProcessPhis() { 1106 void SminessPropagator::ProcessPhis() {
1107 // First optimistically mark all possible smi-phis: phi is possibly a smi if
1108 // its operands are either smis or phis in the worklist.
1109 for (intptr_t i = 0; i < worklist_.length(); i++) {
1110 PhiInstr* phi = worklist_[i];
1111 ASSERT(phi->GetPropagatedCid() == kDynamicCid);
1112 phi->SetPropagatedCid(kSmiCid);
1113
1114 // Append all phis that use this phi and can potentially be smi to the
1115 // end of worklist.
1116 for (Value* use = phi->input_use_list();
1117 use != NULL;
1118 use = use->next_use()) {
1119 PhiInstr* phi_use = use->definition()->AsPhi();
1120 if ((phi_use != NULL) &&
1121 (phi_use->GetPropagatedCid() == kDynamicCid) &&
1122 IsPossiblySmiPhi(phi_use)) {
1123 AddToWorklist(phi_use);
1124 }
1125 }
1126 }
1127
1128 // Now unmark phis that are not definitely smi: that is have only
1129 // smi operands.
1097 while (!worklist_.is_empty()) { 1130 while (!worklist_.is_empty()) {
1098 PhiInstr* phi = RemoveLastFromWorklist(); 1131 PhiInstr* phi = RemoveLastFromWorklist();
1099 if (IsSmiPhi(phi)) { 1132 if (!IsDefinitelySmiPhi(phi)) {
1100 ASSERT(phi->GetPropagatedCid() != kSmiCid); 1133 // Phi result is not a smi. Propagate this fact to phis that depend on it.
1101 phi->SetPropagatedCid(kSmiCid); 1134 phi->SetPropagatedCid(kDynamicCid);
1102 for (Value* use = phi->input_use_list(); 1135 for (Value* use = phi->input_use_list();
1103 use != NULL; 1136 use != NULL;
1104 use = use->next_use()) { 1137 use = use->next_use()) {
1105 if (use->definition()->IsPhi() && 1138 PhiInstr* phi_use = use->definition()->AsPhi();
1106 (use->definition()->GetPropagatedCid() != kSmiCid)) { 1139 if ((phi_use != NULL) && (phi_use->GetPropagatedCid() == kSmiCid)) {
1107 AddToWorklist(use->definition()->AsPhi()); 1140 AddToWorklist(phi_use);
1108 } 1141 }
1109 } 1142 }
1110 } 1143 }
1111 } 1144 }
1112 } 1145 }
1113 1146
1114 1147
1115 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) { 1148 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) {
1116 const intptr_t rollback_point = rollback_checks_.length(); 1149 const intptr_t rollback_point = rollback_checks_.length();
1117 1150
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 it.Advance()) { 2489 it.Advance()) {
2457 JoinEntryInstr* join = it.Current()->AsJoinEntry(); 2490 JoinEntryInstr* join = it.Current()->AsJoinEntry();
2458 if (join != NULL) join->EliminateUnreachablePhiInputs(); 2491 if (join != NULL) join->EliminateUnreachablePhiInputs();
2459 } 2492 }
2460 2493
2461 graph_->ComputeUseLists(); 2494 graph_->ComputeUseLists();
2462 } 2495 }
2463 2496
2464 2497
2465 } // namespace dart 2498 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698