OLD | NEW |
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_allocator.h" | 5 #include "vm/flow_graph_allocator.h" |
6 | 6 |
7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 #include "vm/il_printer.h" | 9 #include "vm/il_printer.h" |
10 #include "vm/flow_graph.h" | 10 #include "vm/flow_graph.h" |
11 #include "vm/flow_graph_compiler.h" | 11 #include "vm/flow_graph_compiler.h" |
12 #include "vm/log.h" | 12 #include "vm/log.h" |
13 #include "vm/parser.h" | 13 #include "vm/parser.h" |
| 14 #include "vm/stack_frame.h" |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 | 17 |
17 #if defined(DEBUG) | 18 #if defined(DEBUG) |
18 #define TRACE_ALLOC(statement) \ | 19 #define TRACE_ALLOC(statement) \ |
19 do { \ | 20 do { \ |
20 if (FLAG_trace_ssa_allocator) statement; \ | 21 if (FLAG_trace_ssa_allocator) statement; \ |
21 } while (0) | 22 } while (0) |
22 #else | 23 #else |
23 #define TRACE_ALLOC(statement) | 24 #define TRACE_ALLOC(statement) |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 range->MarkHasOnlyUnconstrainedUsesInLoop(block_info->loop_id()); | 606 range->MarkHasOnlyUnconstrainedUsesInLoop(block_info->loop_id()); |
606 } | 607 } |
607 } | 608 } |
608 } | 609 } |
609 | 610 |
610 if (block->IsJoinEntry()) { | 611 if (block->IsJoinEntry()) { |
611 ConnectIncomingPhiMoves(block->AsJoinEntry()); | 612 ConnectIncomingPhiMoves(block->AsJoinEntry()); |
612 } else if (block->IsCatchBlockEntry()) { | 613 } else if (block->IsCatchBlockEntry()) { |
613 // Process initial definitions. | 614 // Process initial definitions. |
614 CatchBlockEntryInstr* catch_entry = block->AsCatchBlockEntry(); | 615 CatchBlockEntryInstr* catch_entry = block->AsCatchBlockEntry(); |
615 #if defined(TARGET_ARCH_DBC) | |
616 // TODO(vegorov) support try-catch/finally for DBC. | |
617 flow_graph_.parsed_function().Bailout("FlowGraphAllocator", "Catch"); | |
618 #endif | |
619 | 616 |
620 ProcessEnvironmentUses(catch_entry, catch_entry); // For lazy deopt | 617 ProcessEnvironmentUses(catch_entry, catch_entry); // For lazy deopt |
621 | 618 |
622 for (intptr_t i = 0; | 619 for (intptr_t i = 0; |
623 i < catch_entry->initial_definitions()->length(); | 620 i < catch_entry->initial_definitions()->length(); |
624 i++) { | 621 i++) { |
625 Definition* defn = (*catch_entry->initial_definitions())[i]; | 622 Definition* defn = (*catch_entry->initial_definitions())[i]; |
626 LiveRange* range = GetLiveRange(defn->ssa_temp_index()); | 623 LiveRange* range = GetLiveRange(defn->ssa_temp_index()); |
627 range->DefineAt(catch_entry->start_pos()); // Defined at block entry. | 624 range->DefineAt(catch_entry->start_pos()); // Defined at block entry. |
628 ProcessInitialDefinition(defn, range, catch_entry); | 625 ProcessInitialDefinition(defn, range, catch_entry); |
629 } | 626 } |
630 // Block the two fixed registers used by CatchBlockEntryInstr from the | 627 // Block the two fixed registers used by CatchBlockEntryInstr from the |
631 // block start to until the end of the instruction so that they are | 628 // block start to until the end of the instruction so that they are |
632 // preserved. | 629 // preserved. |
633 intptr_t start = catch_entry->start_pos(); | 630 intptr_t start = catch_entry->start_pos(); |
634 BlockLocation(Location::RegisterLocation(kExceptionObjectReg), | 631 #if !defined(TARGET_ARCH_DBC) |
| 632 const Register exception_reg = kExceptionObjectReg; |
| 633 const Register stacktrace_reg = kStackTraceObjectReg; |
| 634 #else |
| 635 const intptr_t exception_reg = |
| 636 LocalVarIndex(0, catch_entry->exception_var().index()); |
| 637 const intptr_t stacktrace_reg = |
| 638 LocalVarIndex(0, catch_entry->stacktrace_var().index()); |
| 639 #endif |
| 640 BlockLocation(Location::RegisterLocation(exception_reg), |
635 start, | 641 start, |
636 ToInstructionEnd(start)); | 642 ToInstructionEnd(start)); |
637 BlockLocation(Location::RegisterLocation(kStackTraceObjectReg), | 643 BlockLocation(Location::RegisterLocation(stacktrace_reg), |
638 start, | 644 start, |
639 ToInstructionEnd(start)); | 645 ToInstructionEnd(start)); |
640 } | 646 } |
641 } | 647 } |
642 | 648 |
643 // Process incoming parameters and constants. Do this after all other | 649 // Process incoming parameters and constants. Do this after all other |
644 // instructions so that safepoints for all calls have already been found. | 650 // instructions so that safepoints for all calls have already been found. |
645 GraphEntryInstr* graph_entry = flow_graph_.graph_entry(); | 651 GraphEntryInstr* graph_entry = flow_graph_.graph_entry(); |
646 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { | 652 for (intptr_t i = 0; i < graph_entry->initial_definitions()->length(); i++) { |
647 Definition* defn = (*graph_entry->initial_definitions())[i]; | 653 Definition* defn = (*graph_entry->initial_definitions())[i]; |
648 ASSERT(!defn->HasPairRepresentation()); | 654 ASSERT(!defn->HasPairRepresentation()); |
649 LiveRange* range = GetLiveRange(defn->ssa_temp_index()); | 655 LiveRange* range = GetLiveRange(defn->ssa_temp_index()); |
650 range->AddUseInterval(graph_entry->start_pos(), graph_entry->end_pos()); | 656 range->AddUseInterval(graph_entry->start_pos(), graph_entry->end_pos()); |
651 range->DefineAt(graph_entry->start_pos()); | 657 range->DefineAt(graph_entry->start_pos()); |
652 ProcessInitialDefinition(defn, range, graph_entry); | 658 ProcessInitialDefinition(defn, range, graph_entry); |
653 } | 659 } |
654 } | 660 } |
655 | 661 |
656 | 662 |
| 663 void FlowGraphAllocator::SplitInitialDefinitionAt(LiveRange* range, |
| 664 intptr_t pos) { |
| 665 if (range->End() > pos) { |
| 666 LiveRange* tail = range->SplitAt(pos); |
| 667 CompleteRange(tail, Location::kRegister); |
| 668 } |
| 669 } |
| 670 |
| 671 |
657 void FlowGraphAllocator::ProcessInitialDefinition(Definition* defn, | 672 void FlowGraphAllocator::ProcessInitialDefinition(Definition* defn, |
658 LiveRange* range, | 673 LiveRange* range, |
659 BlockEntryInstr* block) { | 674 BlockEntryInstr* block) { |
| 675 #if defined(TARGET_ARCH_DBC) |
| 676 if (block->IsCatchBlockEntry()) { |
| 677 if (defn->IsParameter()) { |
| 678 ParameterInstr* param = defn->AsParameter(); |
| 679 intptr_t slot_index = param->index(); |
| 680 AssignSafepoints(defn, range); |
| 681 range->finger()->Initialize(range); |
| 682 slot_index = kNumberOfCpuRegisters - 1 - slot_index; |
| 683 range->set_assigned_location(Location::RegisterLocation(slot_index)); |
| 684 SplitInitialDefinitionAt(range, block->lifetime_position() + 2); |
| 685 ConvertAllUses(range); |
| 686 BlockLocation(Location::RegisterLocation(slot_index), 0, kMaxPosition); |
| 687 } else { |
| 688 ConstantInstr* constant = defn->AsConstant(); |
| 689 ASSERT(constant != NULL); |
| 690 range->set_assigned_location(Location::Constant(constant)); |
| 691 range->set_spill_slot(Location::Constant(constant)); |
| 692 AssignSafepoints(defn, range); |
| 693 range->finger()->Initialize(range); |
| 694 UsePosition* use = |
| 695 range->finger()->FirstRegisterBeneficialUse(block->start_pos()); |
| 696 if (use != NULL) { |
| 697 LiveRange* tail = |
| 698 SplitBetween(range, block->start_pos(), use->pos()); |
| 699 // Parameters and constants are tagged, so allocated to CPU registers. |
| 700 ASSERT(constant->representation() == kTagged); |
| 701 CompleteRange(tail, Location::kRegister); |
| 702 } |
| 703 ConvertAllUses(range); |
| 704 } |
| 705 return; |
| 706 } |
| 707 #endif |
| 708 |
660 // Save the range end because it may change below. | 709 // Save the range end because it may change below. |
661 intptr_t range_end = range->End(); | 710 intptr_t range_end = range->End(); |
662 if (defn->IsParameter()) { | 711 if (defn->IsParameter()) { |
663 ParameterInstr* param = defn->AsParameter(); | 712 ParameterInstr* param = defn->AsParameter(); |
664 // Assert that copied and non-copied parameters are mutually exclusive. | 713 // Assert that copied and non-copied parameters are mutually exclusive. |
665 // This might change in the future and, if so, the index will be wrong. | 714 // This might change in the future and, if so, the index will be wrong. |
666 ASSERT((flow_graph_.num_copied_params() == 0) || | 715 ASSERT((flow_graph_.num_copied_params() == 0) || |
667 (flow_graph_.num_non_copied_params() == 0)); | 716 (flow_graph_.num_non_copied_params() == 0)); |
668 intptr_t slot_index = param->index(); | 717 intptr_t slot_index = param->index(); |
669 ASSERT((param->base_reg() == FPREG) || (param->base_reg() == SPREG)); | 718 ASSERT((param->base_reg() == FPREG) || (param->base_reg() == SPREG)); |
670 if (param->base_reg() == FPREG) { | 719 if (param->base_reg() == FPREG) { |
671 // Slot index for the leftmost copied parameter is 0. | 720 // Slot index for the leftmost copied parameter is 0. |
672 // Slot index for the rightmost fixed parameter is -1. | 721 // Slot index for the rightmost fixed parameter is -1. |
673 slot_index -= flow_graph_.num_non_copied_params(); | 722 slot_index -= flow_graph_.num_non_copied_params(); |
674 } | 723 } |
675 | 724 |
676 #if defined(TARGET_ARCH_DBC) | 725 #if defined(TARGET_ARCH_DBC) |
677 ASSERT(param->base_reg() == FPREG); | 726 ASSERT(param->base_reg() == FPREG); |
678 if (slot_index >= 0) { | 727 if (slot_index >= 0) { |
679 AssignSafepoints(defn, range); | 728 AssignSafepoints(defn, range); |
680 range->finger()->Initialize(range); | 729 range->finger()->Initialize(range); |
681 range->set_assigned_location(Location::RegisterLocation(slot_index)); | 730 range->set_assigned_location(Location::RegisterLocation(slot_index)); |
682 if (range->End() > kNormalEntryPos) { | 731 SplitInitialDefinitionAt(range, kNormalEntryPos); |
683 LiveRange* tail = range->SplitAt(kNormalEntryPos); | |
684 CompleteRange(tail, Location::kRegister); | |
685 } | |
686 ConvertAllUses(range); | 732 ConvertAllUses(range); |
687 return; | 733 return; |
688 } | 734 } |
689 #endif // defined(TARGET_ARCH_DBC) | 735 #endif // defined(TARGET_ARCH_DBC) |
690 range->set_assigned_location(Location::StackSlot(slot_index, | 736 range->set_assigned_location(Location::StackSlot(slot_index, |
691 param->base_reg())); | 737 param->base_reg())); |
692 range->set_spill_slot(Location::StackSlot(slot_index, | 738 range->set_spill_slot(Location::StackSlot(slot_index, |
693 param->base_reg())); | 739 param->base_reg())); |
694 | 740 |
695 } else if (defn->IsCurrentContext()) { | 741 } else if (defn->IsCurrentContext()) { |
(...skipping 2417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3113 FlowGraphPrinter printer(flow_graph_, true); | 3159 FlowGraphPrinter printer(flow_graph_, true); |
3114 printer.PrintBlocks(); | 3160 printer.PrintBlocks(); |
3115 #endif | 3161 #endif |
3116 } | 3162 } |
3117 THR_Print("----------------------------------------------\n"); | 3163 THR_Print("----------------------------------------------\n"); |
3118 } | 3164 } |
3119 } | 3165 } |
3120 | 3166 |
3121 | 3167 |
3122 } // namespace dart | 3168 } // namespace dart |
OLD | NEW |