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

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 =
401 use->instruction()->RequiredInputRepresentation(use->use_index());
402 if (from_rep == to_rep || to_rep == kNoRepresentation) {
403 continue;
404 }
405
406 Instruction* insert_before;
407 Instruction* deopt_target;
408 PhiInstr* phi = use->instruction()->AsPhi();
409 if (phi != NULL) {
410 ASSERT(phi->is_alive());
411 // For phis conversions have to be inserted in the predecessor.
412 insert_before =
413 phi->block()->PredecessorAt(use->use_index())->last_instruction();
414 deopt_target = NULL;
415 } else {
416 deopt_target = insert_before = use->instruction();
417 }
418
419 InsertConversion(from_rep, to_rep, use, insert_before, deopt_target);
420 } 423 }
421 } 424 }
422 425
426
427 static bool UnboxPhi(PhiInstr* phi) {
srdjan 2013/06/05 15:25:21 Add comment: return true if phi representation cha
Vyacheslav Egorov (Google) 2013/06/05 15:33:07 Done.
428 Representation current = phi->representation();
429 Representation unboxed = current;
430
431 switch (phi->Type()->ToCid()) {
432 case kDoubleCid:
433 unboxed = kUnboxedDouble;
434 break;
435 case kFloat32x4Cid:
436 unboxed = kUnboxedFloat32x4;
437 break;
438 case kUint32x4Cid:
439 unboxed = kUnboxedUint32x4;
440 break;
srdjan 2013/06/05 15:25:21 Do we need to handle also unboxed Mints?
Vyacheslav Egorov (Google) 2013/06/05 15:33:07 Simple type based unboxing unfortunately does not
441 }
442
443 if (unboxed != current) {
444 phi->set_representation(unboxed);
445 return true;
446 }
447
448 return false;
449 }
450
451
452 void FlowGraphOptimizer::UnboxPhis() {
453 GrowableArray<PhiInstr*> worklist(5);
454
455 // Convervatively unbox all phis that were proven to be of type Double.
srdjan 2013/06/05 15:25:21 Why not Mint as well? Maybe mention that Double me
Vyacheslav Egorov (Google) 2013/06/05 15:33:07 Mint issue explained above. Comment fixed.
456 for (intptr_t i = 0; i < block_order_.length(); ++i) {
457 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry();
458 if (join_entry != NULL) {
459 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) {
460 PhiInstr* phi = it.Current();
461 if (UnboxPhi(phi)) {
462 worklist.Add(phi);
463 }
464 }
465 }
466 }
467
468 while (!worklist.is_empty()) {
469 PhiInstr* phi = worklist.RemoveLast();
470 InsertConversionsFor(phi);
471
472 for (intptr_t i = 0; i < phi->InputCount(); i++) {
473 ConvertUse(phi->InputAt(i),
474 phi->InputAt(i)->definition()->representation());
475 }
476 }
477 }
478
423 479
424 void FlowGraphOptimizer::SelectRepresentations() { 480 void FlowGraphOptimizer::SelectRepresentations() {
425 // Convervatively unbox all phis that were proven to be of Double, 481 // Convervatively unbox all phis that were proven to be of Double,
426 // Float32x4, or Uint32x4. 482 // Float32x4, or Uint32x4.
427 for (intptr_t i = 0; i < block_order_.length(); ++i) { 483 for (intptr_t i = 0; i < block_order_.length(); ++i) {
428 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry(); 484 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry();
429 if (join_entry != NULL) { 485 if (join_entry != NULL) {
430 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) { 486 for (PhiIterator it(join_entry); !it.Done(); it.Advance()) {
431 PhiInstr* phi = it.Current(); 487 PhiInstr* phi = it.Current();
432 ASSERT(phi != NULL); 488 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 } 489 }
441 } 490 }
442 } 491 }
443 492
444 // Process all instructions and insert conversions where needed. 493 // Process all instructions and insert conversions where needed.
445 GraphEntryInstr* graph_entry = block_order_[0]->AsGraphEntry(); 494 GraphEntryInstr* graph_entry = block_order_[0]->AsGraphEntry();
446 495
447 // Visit incoming parameters and constants. 496 // Visit incoming parameters and constants.
448 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { 497 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) {
449 InsertConversionsFor((*graph_entry->initial_definitions())[i]); 498 InsertConversionsFor((*graph_entry->initial_definitions())[i]);
(...skipping 6097 matching lines...) Expand 10 before | Expand all | Expand 10 after
6547 6596
6548 // Insert materializations at environment uses. 6597 // Insert materializations at environment uses.
6549 const Class& cls = Class::Handle(alloc->constructor().Owner()); 6598 const Class& cls = Class::Handle(alloc->constructor().Owner());
6550 for (intptr_t i = 0; i < exits.length(); i++) { 6599 for (intptr_t i = 0; i < exits.length(); i++) {
6551 CreateMaterializationAt(exits[i], alloc, cls, *fields); 6600 CreateMaterializationAt(exits[i], alloc, cls, *fields);
6552 } 6601 }
6553 } 6602 }
6554 6603
6555 6604
6556 } // namespace dart 6605 } // 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