OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/live-range-separator.h" | 5 #include "src/compiler/live-range-separator.h" |
6 #include "src/compiler/register-allocator.h" | 6 #include "src/compiler/register-allocator.h" |
7 | 7 |
8 namespace v8 { | 8 namespace v8 { |
9 namespace internal { | 9 namespace internal { |
10 namespace compiler { | 10 namespace compiler { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 range->SetSplinter(splinter); | 51 range->SetSplinter(splinter); |
52 } | 52 } |
53 Zone *zone = data->allocation_zone(); | 53 Zone *zone = data->allocation_zone(); |
54 TRACE("creating splinter for range %d between %d and %d\n", range->vreg(), | 54 TRACE("creating splinter for range %d between %d and %d\n", range->vreg(), |
55 start.ToInstructionIndex(), end.ToInstructionIndex()); | 55 start.ToInstructionIndex(), end.ToInstructionIndex()); |
56 range->Splinter(start, end, zone); | 56 range->Splinter(start, end, zone); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 int FirstInstruction(const UseInterval *interval) { | |
62 LifetimePosition start = interval->start(); | |
63 int ret = start.ToInstructionIndex(); | |
64 if (start.IsInstructionPosition() && start.IsEnd()) { | |
65 ++ret; | |
66 } | |
67 return ret; | |
68 } | |
69 | |
70 | |
71 int LastInstruction(const UseInterval *interval) { | |
72 LifetimePosition end = interval->end(); | |
73 int ret = end.ToInstructionIndex(); | |
74 if (end.IsGapPosition() || end.IsStart()) { | |
75 --ret; | |
76 } | |
77 return ret; | |
78 } | |
79 | |
80 | |
81 void SplinterLiveRange(TopLevelLiveRange *range, RegisterAllocationData *data) { | 61 void SplinterLiveRange(TopLevelLiveRange *range, RegisterAllocationData *data) { |
82 const InstructionSequence *code = data->code(); | 62 const InstructionSequence *code = data->code(); |
83 UseInterval *interval = range->first_interval(); | 63 UseInterval *interval = range->first_interval(); |
84 | 64 |
85 LifetimePosition first_cut = LifetimePosition::Invalid(); | 65 LifetimePosition first_cut = LifetimePosition::Invalid(); |
86 LifetimePosition last_cut = LifetimePosition::Invalid(); | 66 LifetimePosition last_cut = LifetimePosition::Invalid(); |
87 | 67 |
88 while (interval != nullptr) { | 68 while (interval != nullptr) { |
89 UseInterval *next_interval = interval->next(); | 69 UseInterval *next_interval = interval->next(); |
90 const InstructionBlock *first_block = | 70 const InstructionBlock *first_block = |
91 code->GetInstructionBlock(FirstInstruction(interval)); | 71 code->GetInstructionBlock(interval->FirstInstructionIndex()); |
92 const InstructionBlock *last_block = | 72 const InstructionBlock *last_block = |
93 code->GetInstructionBlock(LastInstruction(interval)); | 73 code->GetInstructionBlock(interval->LastInstructionIndex()); |
94 int first_block_nr = first_block->rpo_number().ToInt(); | 74 int first_block_nr = first_block->rpo_number().ToInt(); |
95 int last_block_nr = last_block->rpo_number().ToInt(); | 75 int last_block_nr = last_block->rpo_number().ToInt(); |
96 for (int block_id = first_block_nr; block_id <= last_block_nr; ++block_id) { | 76 for (int block_id = first_block_nr; block_id <= last_block_nr; ++block_id) { |
97 const InstructionBlock *current_block = | 77 const InstructionBlock *current_block = |
98 code->InstructionBlockAt(RpoNumber::FromInt(block_id)); | 78 code->InstructionBlockAt(RpoNumber::FromInt(block_id)); |
99 if (current_block->IsDeferred()) { | 79 if (current_block->IsDeferred()) { |
100 if (!first_cut.IsValid()) { | 80 if (!first_cut.IsValid()) { |
101 first_cut = LifetimePosition::GapFromInstructionIndex( | 81 first_cut = LifetimePosition::GapFromInstructionIndex( |
102 current_block->first_instruction_index()); | 82 current_block->first_instruction_index()); |
103 } | 83 } |
(...skipping 18 matching lines...) Expand all Loading... |
122 } // namespace | 102 } // namespace |
123 | 103 |
124 | 104 |
125 void LiveRangeSeparator::Splinter() { | 105 void LiveRangeSeparator::Splinter() { |
126 size_t virt_reg_count = data()->live_ranges().size(); | 106 size_t virt_reg_count = data()->live_ranges().size(); |
127 for (size_t vreg = 0; vreg < virt_reg_count; ++vreg) { | 107 for (size_t vreg = 0; vreg < virt_reg_count; ++vreg) { |
128 TopLevelLiveRange *range = data()->live_ranges()[vreg]; | 108 TopLevelLiveRange *range = data()->live_ranges()[vreg]; |
129 if (range == nullptr || range->IsEmpty() || range->IsSplinter()) { | 109 if (range == nullptr || range->IsEmpty() || range->IsSplinter()) { |
130 continue; | 110 continue; |
131 } | 111 } |
132 SplinterLiveRange(range, data()); | 112 int first_instr = range->first_interval()->FirstInstructionIndex(); |
| 113 if (!data()->code()->GetInstructionBlock(first_instr)->IsDeferred()) { |
| 114 SplinterLiveRange(range, data()); |
| 115 } |
| 116 } |
| 117 } |
| 118 |
| 119 |
| 120 void LiveRangeMerger::MarkRangesSpilledInDeferredBlocks() { |
| 121 for (TopLevelLiveRange *top : data()->live_ranges()) { |
| 122 if (top == nullptr || top->IsEmpty() || top->splinter() == nullptr) { |
| 123 continue; |
| 124 } |
| 125 |
| 126 LiveRange *child = top; |
| 127 for (; child != nullptr; child = child->next()) { |
| 128 if (child->spilled() || |
| 129 child->NextSlotPosition(child->Start()) != nullptr) { |
| 130 break; |
| 131 } |
| 132 } |
| 133 if (child == nullptr) top->MarkSpilledInDeferredBlock(); |
133 } | 134 } |
134 } | 135 } |
135 | 136 |
136 | 137 |
137 void LiveRangeMerger::Merge() { | 138 void LiveRangeMerger::Merge() { |
| 139 MarkRangesSpilledInDeferredBlocks(); |
| 140 |
138 int live_range_count = static_cast<int>(data()->live_ranges().size()); | 141 int live_range_count = static_cast<int>(data()->live_ranges().size()); |
139 for (int i = 0; i < live_range_count; ++i) { | 142 for (int i = 0; i < live_range_count; ++i) { |
140 TopLevelLiveRange *range = data()->live_ranges()[i]; | 143 TopLevelLiveRange *range = data()->live_ranges()[i]; |
141 if (range == nullptr || range->IsEmpty() || !range->IsSplinter()) { | 144 if (range == nullptr || range->IsEmpty() || !range->IsSplinter()) { |
142 continue; | 145 continue; |
143 } | 146 } |
144 TopLevelLiveRange *splinter_parent = range->splintered_from(); | 147 TopLevelLiveRange *splinter_parent = range->splintered_from(); |
145 | 148 |
146 int to_remove = range->vreg(); | 149 int to_remove = range->vreg(); |
147 splinter_parent->Merge(range, data()->allocation_zone()); | 150 splinter_parent->Merge(range, data()->allocation_zone()); |
148 data()->live_ranges()[to_remove] = nullptr; | 151 data()->live_ranges()[to_remove] = nullptr; |
149 } | 152 } |
150 } | 153 } |
151 | 154 |
152 | 155 |
153 } // namespace compiler | 156 } // namespace compiler |
154 } // namespace internal | 157 } // namespace internal |
155 } // namespace v8 | 158 } // namespace v8 |
OLD | NEW |