| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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" |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 Value* value = values[i]; | 755 Value* value = values[i]; |
| 756 locations[i] = Location::Any(); | 756 locations[i] = Location::Any(); |
| 757 Definition* def = value->definition(); | 757 Definition* def = value->definition(); |
| 758 | 758 |
| 759 if (def->IsPushArgument()) { | 759 if (def->IsPushArgument()) { |
| 760 // Frame size is unknown until after allocation. | 760 // Frame size is unknown until after allocation. |
| 761 locations[i] = Location::NoLocation(); | 761 locations[i] = Location::NoLocation(); |
| 762 continue; | 762 continue; |
| 763 } | 763 } |
| 764 | 764 |
| 765 ConstantComp* constant = def->AsConstant(); |
| 766 if (constant != NULL) { |
| 767 locations[i] = Location::Constant(constant->value()); |
| 768 continue; |
| 769 } |
| 770 |
| 765 const intptr_t vreg = def->ssa_temp_index(); | 771 const intptr_t vreg = def->ssa_temp_index(); |
| 766 LiveRange* range = GetLiveRange(vreg); | 772 LiveRange* range = GetLiveRange(vreg); |
| 767 range->AddUseInterval(block_start_pos, use_pos); | 773 range->AddUseInterval(block_start_pos, use_pos); |
| 768 range->AddUse(use_pos, &locations[i]); | 774 range->AddUse(use_pos, &locations[i]); |
| 769 } | 775 } |
| 770 | 776 |
| 771 env->set_locations(locations); | 777 env->set_locations(locations); |
| 772 } | 778 } |
| 773 | 779 |
| 774 | 780 |
| 775 // Create and update live ranges corresponding to instruction's inputs, | 781 // Create and update live ranges corresponding to instruction's inputs, |
| 776 // temporaries and output. | 782 // temporaries and output. |
| 777 void FlowGraphAllocator::ProcessOneInstruction(BlockEntryInstr* block, | 783 void FlowGraphAllocator::ProcessOneInstruction(BlockEntryInstr* block, |
| 778 Instruction* current) { | 784 Instruction* current) { |
| 785 LocationSummary* locs = current->locs(); |
| 786 |
| 787 Definition* def = current->AsDefinition(); |
| 788 if ((def != NULL) && |
| 789 (def->AsConstant() != NULL) && |
| 790 (GetLiveRange(def->ssa_temp_index())->first_use() == NULL)) { |
| 791 // Drop definitions of constants that have no uses. |
| 792 locs->set_out(Location::NoLocation()); |
| 793 return; |
| 794 } |
| 795 |
| 779 const intptr_t pos = current->lifetime_position(); | 796 const intptr_t pos = current->lifetime_position(); |
| 780 ASSERT(IsInstructionStartPosition(pos)); | 797 ASSERT(IsInstructionStartPosition(pos)); |
| 781 | 798 |
| 782 LocationSummary* locs = current->locs(); | |
| 783 | |
| 784 // Number of input locations and number of input operands have to agree. | 799 // Number of input locations and number of input operands have to agree. |
| 785 ASSERT(locs->input_count() == current->InputCount()); | 800 ASSERT(locs->input_count() == current->InputCount()); |
| 786 | 801 |
| 787 // Normalize same-as-first-input output if input is specified as | 802 // Normalize same-as-first-input output if input is specified as |
| 788 // fixed register. | 803 // fixed register. |
| 789 if (locs->out().IsUnallocated() && | 804 if (locs->out().IsUnallocated() && |
| 790 (locs->out().policy() == Location::kSameAsFirstInput) && | 805 (locs->out().policy() == Location::kSameAsFirstInput) && |
| 791 (locs->in(0).IsMachineRegister())) { | 806 (locs->in(0).IsMachineRegister())) { |
| 792 locs->set_out(locs->in(0)); | 807 locs->set_out(locs->in(0)); |
| 793 } | 808 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 817 // | 832 // |
| 818 // j' i i' | 833 // j' i i' |
| 819 // value --* | 834 // value --* |
| 820 // register [-----) | 835 // register [-----) |
| 821 // | 836 // |
| 822 MoveOperands* move = | 837 MoveOperands* move = |
| 823 AddMoveAt(pos - 1, *in_ref, Location::Any()); | 838 AddMoveAt(pos - 1, *in_ref, Location::Any()); |
| 824 BlockLocation(*in_ref, pos - 1, pos + 1); | 839 BlockLocation(*in_ref, pos - 1, pos + 1); |
| 825 range->AddUseInterval(block->start_pos(), pos - 1); | 840 range->AddUseInterval(block->start_pos(), pos - 1); |
| 826 range->AddHintedUse(pos - 1, move->src_slot(), in_ref); | 841 range->AddHintedUse(pos - 1, move->src_slot(), in_ref); |
| 827 } else { | 842 } else if (in_ref->IsUnallocated()) { |
| 828 // Normal unallocated input. Expected shape of | 843 // Normal unallocated input. Expected shape of |
| 829 // live ranges: | 844 // live ranges: |
| 830 // | 845 // |
| 831 // i i' | 846 // i i' |
| 832 // value -----* | 847 // value -----* |
| 833 // | 848 // |
| 834 ASSERT(in_ref->IsUnallocated()); | 849 ASSERT(in_ref->IsUnallocated()); |
| 835 range->AddUseInterval(block->start_pos(), pos + 1); | 850 range->AddUseInterval(block->start_pos(), pos + 1); |
| 836 range->AddUse(pos + 1, in_ref); | 851 range->AddUse(pos + 1, in_ref); |
| 852 } else { |
| 853 ASSERT(in_ref->IsConstant()); |
| 837 } | 854 } |
| 838 } | 855 } |
| 839 | 856 |
| 840 // Process temps. | 857 // Process temps. |
| 841 for (intptr_t j = 0; j < locs->temp_count(); j++) { | 858 for (intptr_t j = 0; j < locs->temp_count(); j++) { |
| 842 // Expected shape of live range: | 859 // Expected shape of live range: |
| 843 // | 860 // |
| 844 // i i' | 861 // i i' |
| 845 // [--) | 862 // [--) |
| 846 // | 863 // |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 910 } |
| 894 | 911 |
| 895 ASSERT(!locs->out().IsUnallocated()); | 912 ASSERT(!locs->out().IsUnallocated()); |
| 896 #endif | 913 #endif |
| 897 } | 914 } |
| 898 | 915 |
| 899 if (locs->can_call()) { | 916 if (locs->can_call()) { |
| 900 safepoints_.Add(current); | 917 safepoints_.Add(current); |
| 901 } | 918 } |
| 902 | 919 |
| 903 Definition* def = current->AsDefinition(); | |
| 904 if (def == NULL) { | 920 if (def == NULL) { |
| 905 ASSERT(locs->out().IsInvalid()); | 921 ASSERT(locs->out().IsInvalid()); |
| 906 return; | 922 return; |
| 907 } | 923 } |
| 908 | 924 |
| 909 if (locs->out().IsInvalid()) { | 925 if (locs->out().IsInvalid()) { |
| 910 ASSERT(def->ssa_temp_index() < 0); | 926 ASSERT(def->ssa_temp_index() < 0); |
| 911 return; | 927 return; |
| 912 } | 928 } |
| 913 | 929 |
| (...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", | 2174 OS::Print("-- [after ssa allocator] ir [%s] -------------\n", |
| 2159 function.ToFullyQualifiedCString()); | 2175 function.ToFullyQualifiedCString()); |
| 2160 FlowGraphPrinter printer(flow_graph_, true); | 2176 FlowGraphPrinter printer(flow_graph_, true); |
| 2161 printer.PrintBlocks(); | 2177 printer.PrintBlocks(); |
| 2162 OS::Print("----------------------------------------------\n"); | 2178 OS::Print("----------------------------------------------\n"); |
| 2163 } | 2179 } |
| 2164 } | 2180 } |
| 2165 | 2181 |
| 2166 | 2182 |
| 2167 } // namespace dart | 2183 } // namespace dart |
| OLD | NEW |