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

Side by Side Diff: vm/flow_graph_optimizer.cc

Issue 10836239: Change indexed load and store IL instructions to fit with SSA backend. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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 | « vm/flow_graph_optimizer.h ('k') | vm/intermediate_language.h » ('j') | 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/flow_graph_builder.h" 7 #include "vm/flow_graph_builder.h"
8 #include "vm/il_printer.h" 8 #include "vm/il_printer.h"
9 #include "vm/object_store.h" 9 #include "vm/object_store.h"
10 #include "vm/parser.h" 10 #include "vm/parser.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 144
145 145
146 static void RemovePushArguments(InstanceCallComp* comp) { 146 static void RemovePushArguments(InstanceCallComp* comp) {
147 // Remove original push arguments. 147 // Remove original push arguments.
148 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) { 148 for (intptr_t i = 0; i < comp->ArgumentCount(); ++i) {
149 comp->ArgumentAt(i)->RemoveFromGraph(); 149 comp->ArgumentAt(i)->RemoveFromGraph();
150 } 150 }
151 } 151 }
152 152
153 153
154 // Returns true if all targets are the same.
155 // TODO(srdjan): if targets are native use their C_function to compare.
156 static bool HasOneTarget(const ICData& ic_data) {
157 ASSERT(ic_data.NumberOfChecks() > 0);
158 const Function& first_target = Function::Handle(ic_data.GetTargetAt(0));
159 Function& test_target = Function::Handle();
160 for (intptr_t i = 1; i < ic_data.NumberOfChecks(); i++) {
161 test_target = ic_data.GetTargetAt(i);
162 if (first_target.raw() != test_target.raw()) {
163 return false;
164 }
165 }
166 return true;
167 }
168
169
170 static intptr_t ReceiverClassId(Computation* comp) {
171 if (!comp->HasICData()) return kIllegalCid;
172
173 const ICData& ic_data = *comp->ic_data();
174
175 if (ic_data.NumberOfChecks() == 0) return kIllegalCid;
176 // TODO(vegorov): Add multiple receiver type support.
177 if (ic_data.NumberOfChecks() != 1) return kIllegalCid;
178 ASSERT(HasOneTarget(ic_data));
179
180 Function& target = Function::Handle();
181 intptr_t class_id;
182 ic_data.GetOneClassCheckAt(0, &class_id, &target);
183 return class_id;
184 }
185
186
187 bool FlowGraphOptimizer::TryReplaceWithArrayOp(BindInstr* instr,
188 InstanceCallComp* comp,
189 Token::Kind op_kind) {
190 // TODO(fschneider): Optimize []= operator in checked mode as well.
191 if (op_kind == Token::kASSIGN_INDEX && FLAG_enable_type_checks) return false;
192
193 const intptr_t class_id = ReceiverClassId(comp);
194 switch (class_id) {
195 case kImmutableArrayCid:
196 // Stores are only specialized for Array and GrowableObjectArray,
197 // not for ImmutableArray.
198 if (op_kind == Token::kASSIGN_INDEX) return false;
199 // Fall through.
200 case kArrayCid:
201 case kGrowableObjectArrayCid: {
202 Computation* array_op = NULL;
203 if (op_kind == Token::kINDEX) {
srdjan 2012/08/15 22:13:34 Assert somewhere that you have only Token::INDEX o
204 array_op = new LoadIndexedComp(comp->ArgumentAt(0)->value(),
205 comp->ArgumentAt(1)->value(),
206 class_id,
207 comp);
208 } else {
209 array_op = new StoreIndexedComp(comp->ArgumentAt(0)->value(),
210 comp->ArgumentAt(1)->value(),
211 comp->ArgumentAt(2)->value(),
212 class_id,
213 comp);
214 }
215 array_op->set_ic_data(comp->ic_data());
216 instr->set_computation(array_op);
217 RemovePushArguments(comp);
218 return true;
219 }
220 default:
221 return false;
222 }
223 }
224
225
154 bool FlowGraphOptimizer::TryReplaceWithBinaryOp(BindInstr* instr, 226 bool FlowGraphOptimizer::TryReplaceWithBinaryOp(BindInstr* instr,
155 InstanceCallComp* comp, 227 InstanceCallComp* comp,
156 Token::Kind op_kind) { 228 Token::Kind op_kind) {
157 BinaryOpComp::OperandsType operands_type = BinaryOpComp::kDynamicOperands; 229 BinaryOpComp::OperandsType operands_type = BinaryOpComp::kDynamicOperands;
158 ASSERT(comp->HasICData()); 230 ASSERT(comp->HasICData());
159 const ICData& ic_data = *comp->ic_data(); 231 const ICData& ic_data = *comp->ic_data();
160 switch (op_kind) { 232 switch (op_kind) {
161 case Token::kADD: 233 case Token::kADD:
162 case Token::kSUB: 234 case Token::kSUB:
163 case Token::kMUL: 235 case Token::kMUL:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 310 }
239 if (unary_op == NULL) return false; 311 if (unary_op == NULL) return false;
240 312
241 unary_op->set_ic_data(comp->ic_data()); 313 unary_op->set_ic_data(comp->ic_data());
242 instr->set_computation(unary_op); 314 instr->set_computation(unary_op);
243 RemovePushArguments(comp); 315 RemovePushArguments(comp);
244 return true; 316 return true;
245 } 317 }
246 318
247 319
248 // Returns true if all targets are the same.
249 // TODO(srdjan): if targets are native use their C_function to compare.
250 static bool HasOneTarget(const ICData& ic_data) {
251 ASSERT(ic_data.NumberOfChecks() > 0);
252 const Function& first_target = Function::Handle(ic_data.GetTargetAt(0));
253 Function& test_target = Function::Handle();
254 for (intptr_t i = 1; i < ic_data.NumberOfChecks(); i++) {
255 test_target = ic_data.GetTargetAt(i);
256 if (first_target.raw() != test_target.raw()) {
257 return false;
258 }
259 }
260 return true;
261 }
262
263
264 // Using field class 320 // Using field class
265 static RawField* GetField(intptr_t class_id, const String& field_name) { 321 static RawField* GetField(intptr_t class_id, const String& field_name) {
266 Class& cls = Class::Handle(Isolate::Current()->class_table()->At(class_id)); 322 Class& cls = Class::Handle(Isolate::Current()->class_table()->At(class_id));
267 Field& field = Field::Handle(); 323 Field& field = Field::Handle();
268 while (!cls.IsNull()) { 324 while (!cls.IsNull()) {
269 field = cls.LookupInstanceField(field_name); 325 field = cls.LookupInstanceField(field_name);
270 if (!field.IsNull()) { 326 if (!field.IsNull()) {
271 return field.raw(); 327 return field.raw();
272 } 328 }
273 cls = cls.SuperClass(); 329 cls = cls.SuperClass();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 return true; 451 return true;
396 } 452 }
397 return false; 453 return false;
398 } 454 }
399 455
400 456
401 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp, 457 void FlowGraphOptimizer::VisitInstanceCall(InstanceCallComp* comp,
402 BindInstr* instr) { 458 BindInstr* instr) {
403 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() > 0)) { 459 if (comp->HasICData() && (comp->ic_data()->NumberOfChecks() > 0)) {
404 const Token::Kind op_kind = comp->token_kind(); 460 const Token::Kind op_kind = comp->token_kind();
461 if (Token::IsIndexOperator(op_kind) &&
462 TryReplaceWithArrayOp(instr, comp, op_kind)) {
463 return;
464 }
405 if (Token::IsBinaryToken(op_kind) && 465 if (Token::IsBinaryToken(op_kind) &&
406 TryReplaceWithBinaryOp(instr, comp, op_kind)) { 466 TryReplaceWithBinaryOp(instr, comp, op_kind)) {
407 return; 467 return;
408 } 468 }
409 if (Token::IsUnaryToken(op_kind) && 469 if (Token::IsUnaryToken(op_kind) &&
410 TryReplaceWithUnaryOp(instr, comp, op_kind)) { 470 TryReplaceWithUnaryOp(instr, comp, op_kind)) {
411 return; 471 return;
412 } 472 }
413 if ((op_kind == Token::kGET) && TryInlineInstanceGetter(instr, comp)) { 473 if ((op_kind == Token::kGET) && TryInlineInstanceGetter(instr, comp)) {
414 return; 474 return;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 comp->ArgumentAt(0)->value(), 538 comp->ArgumentAt(0)->value(),
479 comp->ArgumentAt(1)->value(), 539 comp->ArgumentAt(1)->value(),
480 comp); 540 comp);
481 store->set_ic_data(comp->ic_data()); 541 store->set_ic_data(comp->ic_data());
482 instr->set_computation(store); 542 instr->set_computation(store);
483 RemovePushArguments(comp); 543 RemovePushArguments(comp);
484 return true; 544 return true;
485 } 545 }
486 546
487 547
488 enum IndexedAccessType {
489 kIndexedLoad,
490 kIndexedStore
491 };
492
493
494 static intptr_t ReceiverClassId(Computation* comp) {
495 if (!comp->HasICData()) return kIllegalCid;
496
497 const ICData& ic_data = *comp->ic_data();
498
499 if (ic_data.NumberOfChecks() == 0) return kIllegalCid;
500 // TODO(vegorov): Add multiple receiver type support.
501 if (ic_data.NumberOfChecks() != 1) return kIllegalCid;
502 ASSERT(HasOneTarget(ic_data));
503
504 Function& target = Function::Handle();
505 intptr_t class_id;
506 ic_data.GetOneClassCheckAt(0, &class_id, &target);
507 return class_id;
508 }
509
510
511 void FlowGraphOptimizer::VisitLoadIndexed(LoadIndexedComp* comp,
512 BindInstr* instr) {
513 const intptr_t class_id = ReceiverClassId(comp);
514 switch (class_id) {
515 case kArrayCid:
516 case kImmutableArrayCid:
517 case kGrowableObjectArrayCid:
518 comp->set_receiver_type(class_id);
519 }
520 }
521
522
523 void FlowGraphOptimizer::VisitStoreIndexed(StoreIndexedComp* comp,
524 BindInstr* instr) {
525 if (FLAG_enable_type_checks) return;
526
527 const intptr_t class_id = ReceiverClassId(comp);
528 switch (class_id) {
529 case kArrayCid:
530 case kGrowableObjectArrayCid:
531 comp->set_receiver_type(class_id);
532 }
533 }
534
535
536 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp, 548 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpComp* comp,
537 BindInstr* instr) { 549 BindInstr* instr) {
538 if (!comp->HasICData()) return; 550 if (!comp->HasICData()) return;
539 551
540 const ICData& ic_data = *comp->ic_data(); 552 const ICData& ic_data = *comp->ic_data();
541 if (ic_data.NumberOfChecks() == 0) return; 553 if (ic_data.NumberOfChecks() == 0) return;
542 // TODO(srdjan): Add multiple receiver type support. 554 // TODO(srdjan): Add multiple receiver type support.
543 if (ic_data.NumberOfChecks() != 1) return; 555 if (ic_data.NumberOfChecks() != 1) return;
544 ASSERT(HasOneTarget(ic_data)); 556 ASSERT(HasOneTarget(ic_data));
545 557
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 LocationSummary* locs = it.Current()->locs(); 730 LocationSummary* locs = it.Current()->locs();
719 if ((locs != NULL) && locs->contains_call()) { 731 if ((locs != NULL) && locs->contains_call()) {
720 is_leaf_ = false; 732 is_leaf_ = false;
721 return; 733 return;
722 } 734 }
723 } 735 }
724 } 736 }
725 } 737 }
726 738
727 } // namespace dart 739 } // namespace dart
OLDNEW
« no previous file with comments | « vm/flow_graph_optimizer.h ('k') | vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698