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

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: address Florian's comment 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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 void MarkPossiblySmiPhi(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
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 const intptr_t cid = phi->InputAt(i)->ResultCid();
1087 if ((input->definition() != phi) && 1089 if (cid != kSmiCid) {
1088 (input->ResultCid() != kSmiCid)) {
1089 return false; 1090 return false;
1090 } 1091 }
1091 } 1092 }
1092 return true; 1093 return true;
1093 } 1094 }
1094 1095
1095 1096
1097 static bool IsPossiblySmiPhi(PhiInstr* phi) {
1098 for (intptr_t i = 0; i < phi->InputCount(); i++) {
1099 const intptr_t cid = phi->InputAt(i)->ResultCid();
1100 if ((cid != kSmiCid) && (cid != kDynamicCid)) {
1101 return false;
1102 }
1103 }
1104 return true;
1105 }
1106
1107
1108 void SminessPropagator::MarkPossiblySmiPhi(PhiInstr* phi) {
1109 for (intptr_t i = 0; i < phi->InputCount(); i++) {
1110 Value* input = phi->InputAt(i);
1111 if ((input->ResultCid() != kSmiCid) &&
1112 !in_worklist_->Contains(input->definition()->ssa_temp_index())) {
1113 // Place all operands that are potentially smi phis to worklist.
Florian Schneider 2012/09/20 11:48:50 I don't see how input operands can be affected by
1114 PhiInstr* phi_input = input->definition()->AsPhi();
1115 if ((phi_input != NULL) && IsPossiblySmiPhi(phi_input)) {
1116 AddToWorklist(phi_input);
1117 continue;
1118 }
1119 return;
1120 }
1121 }
1122
1123 phi->SetPropagatedCid(kSmiCid);
1124
1125 // Place all phis that use this phi and can potentially be smi to worklist.
1126 for (Value* use = phi->input_use_list();
1127 use != NULL;
1128 use = use->next_use()) {
1129 PhiInstr* phi_use = use->definition()->AsPhi();
1130 if ((phi_use != NULL) &&
1131 (phi_use->GetPropagatedCid() == kDynamicCid) &&
1132 IsPossiblySmiPhi(phi_use)) {
1133 AddToWorklist(phi_use);
Florian Schneider 2012/09/20 11:48:50 Maybe rename this to AppendToWorkList since the al
1134 }
1135 }
1136 }
1137
1138
1096 void SminessPropagator::ProcessPhis() { 1139 void SminessPropagator::ProcessPhis() {
1140 // First optimistically mark all possible smi-phis: phi is possibly a smi if
1141 // its operands are either smis or phis in the worklist.
1142 for (intptr_t i = 0; i < worklist_.length(); i++) {
1143 PhiInstr* phi = worklist_[i];
1144 ASSERT(phi->GetPropagatedCid() == kDynamicCid);
1145 MarkPossiblySmiPhi(phi);
1146 }
1147
1148 // Now unmark phis that are not definitely smi: that is have only
1149 // smi operands.
1097 while (!worklist_.is_empty()) { 1150 while (!worklist_.is_empty()) {
1098 PhiInstr* phi = RemoveLastFromWorklist(); 1151 PhiInstr* phi = RemoveLastFromWorklist();
1099 if (IsSmiPhi(phi)) { 1152 if (!IsDefinitelySmiPhi(phi)) {
1100 ASSERT(phi->GetPropagatedCid() != kSmiCid); 1153 // Phi result is not a smi. Propagate this fact to phis that depend on it.
1101 phi->SetPropagatedCid(kSmiCid); 1154 phi->SetPropagatedCid(kDynamicCid);
1102 for (Value* use = phi->input_use_list(); 1155 for (Value* use = phi->input_use_list();
1103 use != NULL; 1156 use != NULL;
1104 use = use->next_use()) { 1157 use = use->next_use()) {
1105 if (use->definition()->IsPhi() && 1158 PhiInstr* phi_use = use->definition()->AsPhi();
1106 (use->definition()->GetPropagatedCid() != kSmiCid)) { 1159 if ((phi_use != NULL) && (phi_use->GetPropagatedCid() == kSmiCid)) {
1107 AddToWorklist(use->definition()->AsPhi()); 1160 AddToWorklist(phi_use);
1108 } 1161 }
1109 } 1162 }
1110 } 1163 }
1111 } 1164 }
1112 } 1165 }
1113 1166
1114 1167
1115 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) { 1168 void SminessPropagator::PropagateSminessRecursive(BlockEntryInstr* block) {
1116 const intptr_t rollback_point = rollback_checks_.length(); 1169 const intptr_t rollback_point = rollback_checks_.length();
1117 1170
(...skipping 1338 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 it.Advance()) { 2509 it.Advance()) {
2457 JoinEntryInstr* join = it.Current()->AsJoinEntry(); 2510 JoinEntryInstr* join = it.Current()->AsJoinEntry();
2458 if (join != NULL) join->EliminateUnreachablePhiInputs(); 2511 if (join != NULL) join->EliminateUnreachablePhiInputs();
2459 } 2512 }
2460 2513
2461 graph_->ComputeUseLists(); 2514 graph_->ComputeUseLists();
2462 } 2515 }
2463 2516
2464 2517
2465 } // namespace dart 2518 } // 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