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

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

Issue 16430002: Ensure that all phis inserted by load optimizer have consistent representation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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 | « runtime/vm/flow_graph_optimizer.h ('k') | tests/language/language.status » ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/flow_graph_compiler.h" 10 #include "vm/flow_graph_compiler.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 } else if ((from == kUnboxedUint32x4) && (to == kTagged)) { 383 } else if ((from == kUnboxedUint32x4) && (to == kTagged)) {
384 converted = new BoxUint32x4Instr(use->CopyWithType()); 384 converted = new BoxUint32x4Instr(use->CopyWithType());
385 } 385 }
386 ASSERT(converted != NULL); 386 ASSERT(converted != NULL);
387 use->BindTo(converted); 387 use->BindTo(converted);
388 InsertBefore(insert_before, converted, use->instruction()->env(), 388 InsertBefore(insert_before, converted, use->instruction()->env(),
389 Definition::kValue); 389 Definition::kValue);
390 } 390 }
391 391
392 392
393 void FlowGraphOptimizer::ConvertUse(Value* use, Representation from_rep) {
394 const Representation to_rep =
395 use->instruction()->RequiredInputRepresentation(use->use_index());
396 if (from_rep == to_rep || to_rep == kNoRepresentation) {
397 return;
398 }
399
400 Instruction* insert_before;
401 Instruction* deopt_target;
402 PhiInstr* phi = use->instruction()->AsPhi();
403 if (phi != NULL) {
404 ASSERT(phi->is_alive());
405 // For phis conversions have to be inserted in the predecessor.
406 insert_before =
407 phi->block()->PredecessorAt(use->use_index())->last_instruction();
408 deopt_target = NULL;
409 } else {
410 deopt_target = insert_before = use->instruction();
411 }
412
413 InsertConversion(from_rep, to_rep, use, insert_before, deopt_target);
414 }
415
393 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { 416 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) {
394 const Representation from_rep = def->representation(); 417 const Representation from_rep = def->representation();
395 418
396 for (Value::Iterator it(def->input_use_list()); 419 for (Value::Iterator it(def->input_use_list());
397 !it.Done(); 420 !it.Done();
398 it.Advance()) { 421 it.Advance()) {
399 Value* use = it.Current(); 422 ConvertUse(it.Current(), from_rep);
400 const Representation to_rep = 423 }
401 use->instruction()->RequiredInputRepresentation(use->use_index()); 424 }
402 if (from_rep == to_rep || to_rep == kNoRepresentation) { 425
403 continue; 426
427 // Returns true if phi's representation was changed.
428 static bool UnboxPhi(PhiInstr* phi) {
429 Representation current = phi->representation();
430 Representation unboxed = current;
431
432 switch (phi->Type()->ToCid()) {
433 case kDoubleCid:
434 unboxed = kUnboxedDouble;
435 break;
436 case kFloat32x4Cid:
437 unboxed = kUnboxedFloat32x4;
438 break;
439 case kUint32x4Cid:
440 unboxed = kUnboxedUint32x4;
441 break;
442 }
443
444 if (unboxed != current) {
445 phi->set_representation(unboxed);
446 return true;
447 }
448
449 return false;
450 }
451
452
453 void FlowGraphOptimizer::UnboxPhis() {
454 GrowableArray<PhiInstr*> worklist(5);
455
456 // Convervatively unbox all phis that were proven to be of Double,
457 // Float32x4, or Uint32x4 type.
458 for (intptr_t i = 0; i < block_order_.length(); ++i) {
459 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry();
460 if (join_entry != NULL) {
461 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) {
462 PhiInstr* phi = it.Current();
463 if (UnboxPhi(phi)) {
464 worklist.Add(phi);
465 }
466 }
404 } 467 }
468 }
405 469
406 Instruction* insert_before; 470 while (!worklist.is_empty()) {
407 Instruction* deopt_target; 471 PhiInstr* phi = worklist.RemoveLast();
408 PhiInstr* phi = use->instruction()->AsPhi(); 472 InsertConversionsFor(phi);
409 if (phi != NULL) { 473
410 ASSERT(phi->is_alive()); 474 for (intptr_t i = 0; i < phi->InputCount(); i++) {
411 // For phis conversions have to be inserted in the predecessor. 475 ConvertUse(phi->InputAt(i),
412 insert_before = 476 phi->InputAt(i)->definition()->representation());
413 phi->block()->PredecessorAt(use->use_index())->last_instruction();
414 deopt_target = NULL;
415 } else {
416 deopt_target = insert_before = use->instruction();
417 } 477 }
418
419 InsertConversion(from_rep, to_rep, use, insert_before, deopt_target);
420 } 478 }
421 } 479 }
422 480
423 481
424 void FlowGraphOptimizer::SelectRepresentations() { 482 void FlowGraphOptimizer::SelectRepresentations() {
425 // Convervatively unbox all phis that were proven to be of Double, 483 // Convervatively unbox all phis that were proven to be of Double,
426 // Float32x4, or Uint32x4. 484 // Float32x4, or Uint32x4 type.
427 for (intptr_t i = 0; i < block_order_.length(); ++i) { 485 for (intptr_t i = 0; i < block_order_.length(); ++i) {
428 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry(); 486 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry();
429 if (join_entry != NULL) { 487 if (join_entry != NULL) {
430 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) { 488 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) {
431 PhiInstr* phi = it.Current(); 489 PhiInstr* phi = it.Current();
432 ASSERT(phi != NULL); 490 UnboxPhi(phi);
433 if (phi->Type()->ToCid() == kDoubleCid) {
434 phi->set_representation(kUnboxedDouble);
435 } else if (phi->Type()->ToCid() == kFloat32x4Cid) {
436 phi->set_representation(kUnboxedFloat32x4);
437 } else if (phi->Type()->ToCid() == kUint32x4Cid) {
438 phi->set_representation(kUnboxedUint32x4);
439 }
440 } 491 }
441 } 492 }
442 } 493 }
443 494
444 // Process all instructions and insert conversions where needed. 495 // Process all instructions and insert conversions where needed.
445 GraphEntryInstr* graph_entry = block_order_[0]->AsGraphEntry(); 496 GraphEntryInstr* graph_entry = block_order_[0]->AsGraphEntry();
446 497
447 // Visit incoming parameters and constants. 498 // Visit incoming parameters and constants.
448 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { 499 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) {
449 InsertConversionsFor((*graph_entry->initial_definitions())[i]); 500 InsertConversionsFor((*graph_entry->initial_definitions())[i]);
(...skipping 6097 matching lines...) Expand 10 before | Expand all | Expand 10 after
6547 6598
6548 // Insert materializations at environment uses. 6599 // Insert materializations at environment uses.
6549 const Class& cls = Class::Handle(alloc->constructor().Owner()); 6600 const Class& cls = Class::Handle(alloc->constructor().Owner());
6550 for (intptr_t i = 0; i < exits.length(); i++) { 6601 for (intptr_t i = 0; i < exits.length(); i++) {
6551 CreateMaterializationAt(exits[i], alloc, cls, *fields); 6602 CreateMaterializationAt(exits[i], alloc, cls, *fields);
6552 } 6603 }
6553 } 6604 }
6554 6605
6555 6606
6556 } // namespace dart 6607 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698