Chromium Code Reviews| 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/flow_graph.h" | 8 #include "vm/flow_graph.h" |
| 9 #include "vm/flow_graph_compiler.h" | 9 #include "vm/flow_graph_compiler.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 624 } | 624 } |
| 625 | 625 |
| 626 void FlowGraphAllocator::SplitInitialDefinitionAt(LiveRange* range, | 626 void FlowGraphAllocator::SplitInitialDefinitionAt(LiveRange* range, |
| 627 intptr_t pos) { | 627 intptr_t pos) { |
| 628 if (range->End() > pos) { | 628 if (range->End() > pos) { |
| 629 LiveRange* tail = range->SplitAt(pos); | 629 LiveRange* tail = range->SplitAt(pos); |
| 630 CompleteRange(tail, Location::kRegister); | 630 CompleteRange(tail, Location::kRegister); |
| 631 } | 631 } |
| 632 } | 632 } |
| 633 | 633 |
| 634 #if defined(TARGET_ARCH_DBC) | |
|
Vyacheslav Egorov (Google)
2017/08/13 13:19:23
I think I liked original version of the function t
zra
2017/08/14 19:59:05
I'll defer to Slava here.
| |
| 634 void FlowGraphAllocator::ProcessInitialDefinition(Definition* defn, | 635 void FlowGraphAllocator::ProcessInitialDefinition(Definition* defn, |
| 635 LiveRange* range, | 636 LiveRange* range, |
| 636 BlockEntryInstr* block) { | 637 BlockEntryInstr* block) { |
| 637 #if defined(TARGET_ARCH_DBC) | |
| 638 if (block->IsCatchBlockEntry()) { | 638 if (block->IsCatchBlockEntry()) { |
| 639 if (defn->IsParameter()) { | 639 if (defn->IsParameter()) { |
| 640 // This must be in sync with FlowGraphCompiler::CatchEntryRegForVariable. | 640 // This must be in sync with FlowGraphCompiler::CatchEntryRegForVariable. |
| 641 ParameterInstr* param = defn->AsParameter(); | 641 ParameterInstr* param = defn->AsParameter(); |
| 642 intptr_t slot_index = param->index(); | 642 intptr_t slot_index = param->index(); |
| 643 AssignSafepoints(defn, range); | 643 AssignSafepoints(defn, range); |
| 644 range->finger()->Initialize(range); | 644 range->finger()->Initialize(range); |
| 645 slot_index = kNumberOfCpuRegisters - 1 - slot_index; | 645 slot_index = kNumberOfCpuRegisters - 1 - slot_index; |
| 646 range->set_assigned_location(Location::RegisterLocation(slot_index)); | 646 range->set_assigned_location(Location::RegisterLocation(slot_index)); |
| 647 SplitInitialDefinitionAt(range, block->lifetime_position() + 2); | 647 SplitInitialDefinitionAt(range, block->lifetime_position() + 2); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 659 if (use != NULL) { | 659 if (use != NULL) { |
| 660 LiveRange* tail = SplitBetween(range, block->start_pos(), use->pos()); | 660 LiveRange* tail = SplitBetween(range, block->start_pos(), use->pos()); |
| 661 // Parameters and constants are tagged, so allocated to CPU registers. | 661 // Parameters and constants are tagged, so allocated to CPU registers. |
| 662 ASSERT(constant->representation() == kTagged); | 662 ASSERT(constant->representation() == kTagged); |
| 663 CompleteRange(tail, Location::kRegister); | 663 CompleteRange(tail, Location::kRegister); |
| 664 } | 664 } |
| 665 ConvertAllUses(range); | 665 ConvertAllUses(range); |
| 666 } | 666 } |
| 667 return; | 667 return; |
| 668 } | 668 } |
| 669 #endif | |
| 670 | 669 |
| 671 // Save the range end because it may change below. | 670 // Save the range end because it may change below. |
| 672 intptr_t range_end = range->End(); | 671 intptr_t range_end = range->End(); |
| 673 if (defn->IsParameter()) { | 672 if (defn->IsParameter()) { |
| 674 ParameterInstr* param = defn->AsParameter(); | 673 ParameterInstr* param = defn->AsParameter(); |
| 675 // Assert that copied and non-copied parameters are mutually exclusive. | 674 // Assert that copied and non-copied parameters are mutually exclusive. |
| 676 // This might change in the future and, if so, the index will be wrong. | 675 // This might change in the future and, if so, the index will be wrong. |
| 677 ASSERT((flow_graph_.num_copied_params() == 0) || | 676 ASSERT((flow_graph_.num_copied_params() == 0) || |
| 678 (flow_graph_.num_non_copied_params() == 0)); | 677 (flow_graph_.num_non_copied_params() == 0)); |
| 679 intptr_t slot_index = param->index(); | 678 intptr_t slot_index = param->index(); |
| 680 ASSERT(slot_index >= 0); | 679 ASSERT(slot_index >= 0); |
| 681 ASSERT((param->base_reg() == FPREG) || (param->base_reg() == SPREG)); | 680 ASSERT((param->base_reg() == FPREG) || (param->base_reg() == SPREG)); |
| 682 if (param->base_reg() == FPREG) { | 681 if (param->base_reg() == FPREG) { |
| 683 // Slot index for the leftmost copied parameter is 0. | 682 // Slot index for the leftmost copied parameter is 0. |
| 684 // Slot index for the rightmost fixed parameter is -1. | 683 // Slot index for the rightmost fixed parameter is -1. |
| 685 slot_index -= flow_graph_.num_non_copied_params(); | 684 slot_index -= flow_graph_.num_non_copied_params(); |
| 686 } | 685 } |
| 687 | |
| 688 #if defined(TARGET_ARCH_DBC) | |
| 689 ASSERT(param->base_reg() == FPREG); | 686 ASSERT(param->base_reg() == FPREG); |
| 690 if (slot_index >= 0) { | 687 if (slot_index >= 0) { |
| 691 AssignSafepoints(defn, range); | 688 AssignSafepoints(defn, range); |
| 692 range->finger()->Initialize(range); | 689 range->finger()->Initialize(range); |
| 693 range->set_assigned_location(Location::RegisterLocation(slot_index)); | 690 range->set_assigned_location(Location::RegisterLocation(slot_index)); |
| 694 SplitInitialDefinitionAt(range, kNormalEntryPos); | 691 SplitInitialDefinitionAt(range, kNormalEntryPos); |
| 695 ConvertAllUses(range); | 692 ConvertAllUses(range); |
| 696 return; | 693 return; |
| 697 } | 694 } |
| 698 #endif // defined(TARGET_ARCH_DBC) | 695 range->set_assigned_location( |
| 696 Location::StackSlot(slot_index, param->base_reg())); | |
| 697 range->set_spill_slot(Location::StackSlot(slot_index, param->base_reg())); | |
| 698 } else if (defn->IsSpecialParameter()) { | |
| 699 SpecialParameterInstr* param = defn->AsSpecialParameter(); | |
| 700 if (param->kind() == SpecialParameterInstr::kContext) { | |
| 701 intptr_t context_reg = flow_graph_.num_copied_params(); | |
| 702 ASSERT(-flow_graph_.parsed_function().first_stack_local_index() - 1 == | |
| 703 context_reg); | |
| 704 if (flow_graph_.parsed_function().function_type_arguments() != NULL) { | |
| 705 // The first slot is used for function type arguments, either as their | |
| 706 // permanent location or as their temporary location when captured. | |
| 707 // So use the next one for the context. | |
| 708 context_reg++; | |
| 709 } | |
| 710 AssignSafepoints(defn, range); | |
|
Vyacheslav Egorov (Google)
2017/08/13 13:19:23
I think lines 710-717 and 724-729 should be almost
regis
2017/08/14 23:29:19
Done.
| |
| 711 range->finger()->Initialize(range); | |
| 712 range->set_assigned_location(Location::RegisterLocation(context_reg)); | |
| 713 if (range->End() > kNormalEntryPos) { | |
| 714 LiveRange* tail = range->SplitAt(kNormalEntryPos); | |
| 715 CompleteRange(tail, Location::kRegister); | |
| 716 } | |
| 717 ConvertAllUses(range); | |
| 718 return; | |
| 719 } | |
| 720 ASSERT(param->kind() == SpecialParameterInstr::kTypeArgs); | |
| 721 const intptr_t slot_index = flow_graph_.num_copied_params(); | |
| 722 ASSERT(-flow_graph_.parsed_function().first_stack_local_index() - 1 == | |
| 723 slot_index); | |
| 724 range->set_assigned_location(Location::RegisterLocation(slot_index)); | |
| 725 if (range->End() > kNormalEntryPos) { | |
| 726 LiveRange* tail = range->SplitAt(kNormalEntryPos); | |
| 727 CompleteRange(tail, Location::kRegister); | |
| 728 } | |
| 729 ConvertAllUses(range); | |
| 730 return; | |
| 731 } else { | |
| 732 ConstantInstr* constant = defn->AsConstant(); | |
| 733 ASSERT(constant != NULL); | |
| 734 range->set_assigned_location(Location::Constant(constant)); | |
| 735 range->set_spill_slot(Location::Constant(constant)); | |
| 736 } | |
| 737 AssignSafepoints(defn, range); | |
| 738 range->finger()->Initialize(range); | |
| 739 UsePosition* use = | |
| 740 range->finger()->FirstRegisterBeneficialUse(block->start_pos()); | |
| 741 if (use != NULL) { | |
| 742 LiveRange* tail = SplitBetween(range, block->start_pos(), use->pos()); | |
| 743 // Parameters and constants are tagged, so allocated to CPU registers. | |
| 744 CompleteRange(tail, Location::kRegister); | |
| 745 } | |
| 746 ConvertAllUses(range); | |
| 747 if (range->spill_slot().IsStackSlot() && | |
| 748 (range->spill_slot().stack_index() >= 0)) { | |
| 749 // On entry to the function, range is stored on the stack above the FP in | |
| 750 // the same space which is used for spill slots. Update spill slot state to | |
| 751 // reflect that and prevent register allocator from reusing this space as a | |
| 752 // spill slot. | |
| 753 spill_slots_.Add(range_end); | |
| 754 quad_spill_slots_.Add(false); | |
| 755 untagged_spill_slots_.Add(false); | |
| 756 // Note, all incoming parameters are assumed to be tagged. | |
| 757 MarkAsObjectAtSafepoints(range); | |
| 758 } else if (defn->IsConstant() && block->IsCatchBlockEntry()) { | |
| 759 // Constants at catch block entries consume spill slots. | |
| 760 spill_slots_.Add(range_end); | |
| 761 quad_spill_slots_.Add(false); | |
| 762 untagged_spill_slots_.Add(false); | |
| 763 } | |
| 764 } | |
| 765 #else | |
| 766 void FlowGraphAllocator::ProcessInitialDefinition(Definition* defn, | |
| 767 LiveRange* range, | |
| 768 BlockEntryInstr* block) { | |
| 769 // Save the range end because it may change below. | |
| 770 intptr_t range_end = range->End(); | |
| 771 if (defn->IsParameter()) { | |
| 772 ParameterInstr* param = defn->AsParameter(); | |
| 773 // Assert that copied and non-copied parameters are mutually exclusive. | |
| 774 // This might change in the future and, if so, the index will be wrong. | |
| 775 ASSERT((flow_graph_.num_copied_params() == 0) || | |
| 776 (flow_graph_.num_non_copied_params() == 0)); | |
| 777 intptr_t slot_index = param->index(); | |
| 778 ASSERT(slot_index >= 0); | |
| 779 ASSERT((param->base_reg() == FPREG) || (param->base_reg() == SPREG)); | |
| 780 if (param->base_reg() == FPREG) { | |
| 781 // Slot index for the leftmost copied parameter is 0. | |
| 782 // Slot index for the rightmost fixed parameter is -1. | |
| 783 slot_index -= flow_graph_.num_non_copied_params(); | |
| 784 } | |
| 699 range->set_assigned_location( | 785 range->set_assigned_location( |
| 700 Location::StackSlot(slot_index, param->base_reg())); | 786 Location::StackSlot(slot_index, param->base_reg())); |
| 701 range->set_spill_slot(Location::StackSlot(slot_index, param->base_reg())); | 787 range->set_spill_slot(Location::StackSlot(slot_index, param->base_reg())); |
| 702 | 788 |
| 703 } else if (defn->IsSpecialParameter()) { | 789 } else if (defn->IsSpecialParameter()) { |
| 704 SpecialParameterInstr* param = defn->AsSpecialParameter(); | 790 SpecialParameterInstr* param = defn->AsSpecialParameter(); |
| 705 if (param->kind() == SpecialParameterInstr::kContext) { | 791 if (param->kind() == SpecialParameterInstr::kContext) { |
| 706 #if !defined(TARGET_ARCH_DBC) | |
| 707 const Register context_reg = CTX; | 792 const Register context_reg = CTX; |
| 708 #else | |
| 709 const intptr_t context_reg = flow_graph_.num_copied_params(); | |
| 710 #endif | |
| 711 | |
| 712 AssignSafepoints(defn, range); | 793 AssignSafepoints(defn, range); |
| 713 range->finger()->Initialize(range); | 794 range->finger()->Initialize(range); |
| 714 range->set_assigned_location(Location::RegisterLocation(context_reg)); | 795 range->set_assigned_location(Location::RegisterLocation(context_reg)); |
| 715 if (range->End() > kNormalEntryPos) { | 796 if (range->End() > kNormalEntryPos) { |
| 716 LiveRange* tail = range->SplitAt(kNormalEntryPos); | 797 LiveRange* tail = range->SplitAt(kNormalEntryPos); |
| 717 CompleteRange(tail, Location::kRegister); | 798 CompleteRange(tail, Location::kRegister); |
| 718 } | 799 } |
| 719 ConvertAllUses(range); | 800 ConvertAllUses(range); |
| 720 return; | 801 return; |
| 721 } | 802 } |
| 722 ASSERT(param->kind() == SpecialParameterInstr::kTypeArgs); | 803 ASSERT(param->kind() == SpecialParameterInstr::kTypeArgs); |
| 723 #if defined(TARGET_ARCH_DBC) | |
| 724 UNIMPLEMENTED(); | |
| 725 #endif | |
| 726 const intptr_t slot_index = flow_graph_.num_copied_params(); | 804 const intptr_t slot_index = flow_graph_.num_copied_params(); |
| 727 range->set_assigned_location(Location::StackSlot(slot_index, FPREG)); | 805 range->set_assigned_location(Location::StackSlot(slot_index, FPREG)); |
| 728 range->set_spill_slot(Location::StackSlot(slot_index, FPREG)); | 806 range->set_spill_slot(Location::StackSlot(slot_index, FPREG)); |
| 729 } else { | 807 } else { |
| 730 ConstantInstr* constant = defn->AsConstant(); | 808 ConstantInstr* constant = defn->AsConstant(); |
| 731 ASSERT(constant != NULL); | 809 ASSERT(constant != NULL); |
| 732 range->set_assigned_location(Location::Constant(constant)); | 810 range->set_assigned_location(Location::Constant(constant)); |
| 733 range->set_spill_slot(Location::Constant(constant)); | 811 range->set_spill_slot(Location::Constant(constant)); |
| 734 } | 812 } |
| 735 AssignSafepoints(defn, range); | 813 AssignSafepoints(defn, range); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 753 untagged_spill_slots_.Add(false); | 831 untagged_spill_slots_.Add(false); |
| 754 // Note, all incoming parameters are assumed to be tagged. | 832 // Note, all incoming parameters are assumed to be tagged. |
| 755 MarkAsObjectAtSafepoints(range); | 833 MarkAsObjectAtSafepoints(range); |
| 756 } else if (defn->IsConstant() && block->IsCatchBlockEntry()) { | 834 } else if (defn->IsConstant() && block->IsCatchBlockEntry()) { |
| 757 // Constants at catch block entries consume spill slots. | 835 // Constants at catch block entries consume spill slots. |
| 758 spill_slots_.Add(range_end); | 836 spill_slots_.Add(range_end); |
| 759 quad_spill_slots_.Add(false); | 837 quad_spill_slots_.Add(false); |
| 760 untagged_spill_slots_.Add(false); | 838 untagged_spill_slots_.Add(false); |
| 761 } | 839 } |
| 762 } | 840 } |
| 841 #endif // defined(TARGET_ARCH_DBC) | |
| 763 | 842 |
| 764 static Location::Kind RegisterKindFromPolicy(Location loc) { | 843 static Location::Kind RegisterKindFromPolicy(Location loc) { |
| 765 if (loc.policy() == Location::kRequiresFpuRegister) { | 844 if (loc.policy() == Location::kRequiresFpuRegister) { |
| 766 return Location::kFpuRegister; | 845 return Location::kFpuRegister; |
| 767 } else { | 846 } else { |
| 768 return Location::kRegister; | 847 return Location::kRegister; |
| 769 } | 848 } |
| 770 } | 849 } |
| 771 | 850 |
| 772 static Location::Kind RegisterKindForResult(Instruction* instr) { | 851 static Location::Kind RegisterKindForResult(Instruction* instr) { |
| (...skipping 2236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3009 #ifndef PRODUCT | 3088 #ifndef PRODUCT |
| 3010 FlowGraphPrinter printer(flow_graph_, true); | 3089 FlowGraphPrinter printer(flow_graph_, true); |
| 3011 printer.PrintBlocks(); | 3090 printer.PrintBlocks(); |
| 3012 #endif | 3091 #endif |
| 3013 } | 3092 } |
| 3014 THR_Print("----------------------------------------------\n"); | 3093 THR_Print("----------------------------------------------\n"); |
| 3015 } | 3094 } |
| 3016 } | 3095 } |
| 3017 | 3096 |
| 3018 } // namespace dart | 3097 } // namespace dart |
| OLD | NEW |