OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n", | 528 TRACE_GVN_1("Using optimistic loop invariant code motion: %s\n", |
529 graph()->use_optimistic_licm() ? "yes" : "no"); | 529 graph()->use_optimistic_licm() ? "yes" : "no"); |
530 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { | 530 for (int i = graph()->blocks()->length() - 1; i >= 0; --i) { |
531 HBasicBlock* block = graph()->blocks()->at(i); | 531 HBasicBlock* block = graph()->blocks()->at(i); |
532 if (block->IsLoopHeader()) { | 532 if (block->IsLoopHeader()) { |
533 GVNFlagSet side_effects = loop_side_effects_[block->block_id()]; | 533 GVNFlagSet side_effects = loop_side_effects_[block->block_id()]; |
534 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n", | 534 TRACE_GVN_2("Try loop invariant motion for block B%d %s\n", |
535 block->block_id(), | 535 block->block_id(), |
536 GetGVNFlagsString(side_effects).get()); | 536 GetGVNFlagsString(side_effects).get()); |
537 | 537 |
538 GVNFlagSet accumulated_first_time_depends; | |
539 GVNFlagSet accumulated_first_time_changes; | |
540 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); | 538 HBasicBlock* last = block->loop_information()->GetLastBackEdge(); |
541 for (int j = block->block_id(); j <= last->block_id(); ++j) { | 539 for (int j = block->block_id(); j <= last->block_id(); ++j) { |
542 ProcessLoopBlock(graph()->blocks()->at(j), block, side_effects, | 540 ProcessLoopBlock(graph()->blocks()->at(j), block, side_effects); |
543 &accumulated_first_time_depends, | |
544 &accumulated_first_time_changes); | |
545 } | 541 } |
546 } | 542 } |
547 } | 543 } |
548 } | 544 } |
549 | 545 |
550 | 546 |
551 void HGlobalValueNumberingPhase::ProcessLoopBlock( | 547 void HGlobalValueNumberingPhase::ProcessLoopBlock( |
552 HBasicBlock* block, | 548 HBasicBlock* block, |
553 HBasicBlock* loop_header, | 549 HBasicBlock* loop_header, |
554 GVNFlagSet loop_kills, | 550 GVNFlagSet loop_kills) { |
555 GVNFlagSet* first_time_depends, | |
556 GVNFlagSet* first_time_changes) { | |
557 HBasicBlock* pre_header = loop_header->predecessors()->at(0); | 551 HBasicBlock* pre_header = loop_header->predecessors()->at(0); |
558 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); | 552 GVNFlagSet depends_flags = HValue::ConvertChangesToDependsFlags(loop_kills); |
559 TRACE_GVN_2("Loop invariant motion for B%d %s\n", | 553 TRACE_GVN_2("Loop invariant motion for B%d %s\n", |
560 block->block_id(), | 554 block->block_id(), |
561 GetGVNFlagsString(depends_flags).get()); | 555 GetGVNFlagsString(depends_flags).get()); |
562 HInstruction* instr = block->first(); | 556 HInstruction* instr = block->first(); |
563 while (instr != NULL) { | 557 while (instr != NULL) { |
564 HInstruction* next = instr->next(); | 558 HInstruction* next = instr->next(); |
565 bool hoisted = false; | |
566 if (instr->CheckFlag(HValue::kUseGVN)) { | 559 if (instr->CheckFlag(HValue::kUseGVN)) { |
567 TRACE_GVN_4("Checking instruction %d (%s) %s. Loop %s\n", | 560 TRACE_GVN_4("Checking instruction %d (%s) %s. Loop %s\n", |
568 instr->id(), | 561 instr->id(), |
569 instr->Mnemonic(), | 562 instr->Mnemonic(), |
570 GetGVNFlagsString(instr->gvn_flags()).get(), | 563 GetGVNFlagsString(instr->gvn_flags()).get(), |
571 GetGVNFlagsString(loop_kills).get()); | 564 GetGVNFlagsString(loop_kills).get()); |
572 bool can_hoist = !instr->gvn_flags().ContainsAnyOf(depends_flags); | 565 bool can_hoist = !instr->gvn_flags().ContainsAnyOf(depends_flags); |
573 if (can_hoist && !graph()->use_optimistic_licm()) { | 566 if (can_hoist && !graph()->use_optimistic_licm()) { |
574 can_hoist = block->IsLoopSuccessorDominator(); | 567 can_hoist = block->IsLoopSuccessorDominator(); |
575 } | 568 } |
576 | 569 |
577 if (can_hoist) { | 570 if (can_hoist) { |
578 bool inputs_loop_invariant = true; | 571 bool inputs_loop_invariant = true; |
579 for (int i = 0; i < instr->OperandCount(); ++i) { | 572 for (int i = 0; i < instr->OperandCount(); ++i) { |
580 if (instr->OperandAt(i)->IsDefinedAfter(pre_header)) { | 573 if (instr->OperandAt(i)->IsDefinedAfter(pre_header)) { |
581 inputs_loop_invariant = false; | 574 inputs_loop_invariant = false; |
582 } | 575 } |
583 } | 576 } |
584 | 577 |
585 if (inputs_loop_invariant && ShouldMove(instr, loop_header)) { | 578 if (inputs_loop_invariant && ShouldMove(instr, loop_header)) { |
586 TRACE_GVN_2("Hoisting loop invariant instruction i%d to block B%d\n", | 579 TRACE_GVN_2("Hoisting loop invariant instruction i%d to block B%d\n", |
587 instr->id(), pre_header->block_id()); | 580 instr->id(), pre_header->block_id()); |
588 // Move the instruction out of the loop. | 581 // Move the instruction out of the loop. |
589 instr->Unlink(); | 582 instr->Unlink(); |
590 instr->InsertBefore(pre_header->end()); | 583 instr->InsertBefore(pre_header->end()); |
591 if (instr->HasSideEffects()) removed_side_effects_ = true; | 584 if (instr->HasSideEffects()) removed_side_effects_ = true; |
592 hoisted = true; | |
593 } | 585 } |
594 } | 586 } |
595 } | 587 } |
596 if (!hoisted) { | |
597 // If an instruction is not hoisted, we have to account for its side | |
598 // effects when hoisting later HTransitionElementsKind instructions. | |
599 GVNFlagSet previous_depends = *first_time_depends; | |
600 GVNFlagSet previous_changes = *first_time_changes; | |
601 first_time_depends->Add(instr->DependsOnFlags()); | |
602 first_time_changes->Add(instr->ChangesFlags()); | |
603 if (!(previous_depends == *first_time_depends)) { | |
604 TRACE_GVN_1("Updated first-time accumulated %s\n", | |
605 GetGVNFlagsString(*first_time_depends).get()); | |
606 } | |
607 if (!(previous_changes == *first_time_changes)) { | |
608 TRACE_GVN_1("Updated first-time accumulated %s\n", | |
609 GetGVNFlagsString(*first_time_changes).get()); | |
610 } | |
611 } | |
612 instr = next; | 588 instr = next; |
613 } | 589 } |
614 } | 590 } |
615 | 591 |
616 | 592 |
617 bool HGlobalValueNumberingPhase::AllowCodeMotion() { | 593 bool HGlobalValueNumberingPhase::AllowCodeMotion() { |
618 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; | 594 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; |
619 } | 595 } |
620 | 596 |
621 | 597 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 dominated); | 839 dominated); |
864 successor_map->Kill(side_effects_on_all_paths); | 840 successor_map->Kill(side_effects_on_all_paths); |
865 successor_dominators->Kill(side_effects_on_all_paths); | 841 successor_dominators->Kill(side_effects_on_all_paths); |
866 } | 842 } |
867 } | 843 } |
868 current = next; | 844 current = next; |
869 } | 845 } |
870 } | 846 } |
871 | 847 |
872 } } // namespace v8::internal | 848 } } // namespace v8::internal |
OLD | NEW |