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/preprocess-live-ranges.h" | 5 #include "src/compiler/preprocess-live-ranges.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 { |
11 | 11 |
12 | 12 |
13 #define TRACE(...) \ | 13 #define TRACE(...) \ |
14 do { \ | 14 do { \ |
15 if (FLAG_trace_alloc) PrintF(__VA_ARGS__); \ | 15 if (FLAG_trace_alloc) PrintF(__VA_ARGS__); \ |
16 } while (false) | 16 } while (false) |
17 | 17 |
18 | 18 |
19 namespace { | |
20 | |
21 LiveRange* Split(LiveRange* range, RegisterAllocationData* data, | |
22 LifetimePosition pos) { | |
23 DCHECK(range->Start() < pos && pos < range->End()); | |
24 DCHECK(pos.IsStart() || pos.IsGapPosition() || | |
25 (data->code() | |
26 ->GetInstructionBlock(pos.ToInstructionIndex()) | |
27 ->last_instruction_index() != pos.ToInstructionIndex())); | |
28 LiveRange* result = data->NewChildRangeFor(range); | |
29 range->SplitAt(pos, result, data->allocation_zone()); | |
30 TRACE("Split range %d(v%d) @%d => %d.\n", range->id(), | |
31 range->TopLevel()->id(), pos.ToInstructionIndex(), result->id()); | |
32 return result; | |
33 } | |
34 | |
35 | |
36 LifetimePosition GetSplitPositionForInstruction(const LiveRange* range, | |
37 int instruction_index) { | |
38 LifetimePosition ret = LifetimePosition::Invalid(); | |
39 | |
40 ret = LifetimePosition::GapFromInstructionIndex(instruction_index); | |
41 if (range->Start() >= ret || ret >= range->End()) { | |
42 return LifetimePosition::Invalid(); | |
43 } | |
44 return ret; | |
45 } | |
46 | |
47 | |
48 LiveRange* SplitRangeAfterBlock(LiveRange* range, RegisterAllocationData* data, | |
49 const InstructionBlock* block) { | |
50 const InstructionSequence* code = data->code(); | |
51 int last_index = block->last_instruction_index(); | |
52 int outside_index = static_cast<int>(code->instructions().size()); | |
53 bool has_handler = false; | |
54 for (auto successor_id : block->successors()) { | |
55 const InstructionBlock* successor = code->InstructionBlockAt(successor_id); | |
56 if (successor->IsHandler()) { | |
57 has_handler = true; | |
58 } | |
59 outside_index = Min(outside_index, successor->first_instruction_index()); | |
60 } | |
61 int split_at = has_handler ? outside_index : last_index; | |
62 LifetimePosition after_block = | |
63 GetSplitPositionForInstruction(range, split_at); | |
64 | |
65 if (after_block.IsValid()) { | |
66 return Split(range, data, after_block); | |
67 } | |
68 | |
69 return range; | |
70 } | |
71 | |
72 | |
73 int GetFirstInstructionIndex(const UseInterval* interval) { | |
74 int ret = interval->start().ToInstructionIndex(); | |
75 if (!interval->start().IsGapPosition() && !interval->start().IsStart()) { | |
76 ++ret; | |
77 } | |
78 return ret; | |
79 } | |
80 | |
81 | |
82 bool DoesSubsequenceClobber(const InstructionSequence* code, int start, | |
83 int stop) { | |
Jarin
2015/08/04 19:39:43
stop -> end
Mircea Trofin
2015/08/04 20:34:46
Done.
| |
84 for (int i = start; i <= stop; ++i) { | |
85 if (code->InstructionAt(i)->IsCall()) return true; | |
86 } | |
87 return false; | |
88 } | |
89 | |
90 | |
91 void SplitRangeByClobberingDeferredBlocks(LiveRange* range, | |
Jarin
2015/08/04 19:39:43
The name is a bit confusing (it sounds like it clo
Mircea Trofin
2015/08/04 20:34:46
Done.
| |
92 RegisterAllocationData* data) { | |
93 DCHECK(!range->IsFixed()); | |
94 DCHECK(!range->spilled()); | |
95 if (range->TopLevel()->HasSpillOperand()) { | |
96 TRACE( | |
97 "Skipping deferred block analysis for live range %d because it has a " | |
98 "spill operand.\n", | |
99 range->TopLevel()->id()); | |
100 return; | |
101 } | |
102 | |
103 const InstructionSequence* code = data->code(); | |
104 LiveRange* current_subrange = range; | |
105 | |
106 UseInterval* interval = current_subrange->first_interval(); | |
107 | |
108 while (interval != nullptr) { | |
109 int first_index = GetFirstInstructionIndex(interval); | |
110 int last_index = interval->end().ToInstructionIndex(); | |
111 | |
112 if (last_index >= code->InstructionCount()) { | |
Jarin
2015/08/04 19:39:43
It could be more readable if you said "if (last_in
Mircea Trofin
2015/08/04 20:34:46
Done.
| |
113 last_index = code->LastInstructionIndex(); | |
114 } | |
115 interval = interval->next(); | |
116 | |
117 for (int index = first_index; index <= last_index;) { | |
118 const InstructionBlock* block = code->GetInstructionBlock(index); | |
119 int last_block_index = static_cast<int>(block->last_instruction_index()); | |
120 int last_covered_index = Min(last_index, last_block_index); | |
121 int working_index = index; | |
122 index = block->last_instruction_index() + 1; | |
123 | |
124 if (!block->IsDeferred() || | |
125 !DoesSubsequenceClobber(code, working_index, last_covered_index)) { | |
126 continue; | |
127 } | |
128 | |
129 TRACE("Deferred block B%d clobbers range %d(v%d).\n", | |
130 block->rpo_number().ToInt(), current_subrange->id(), | |
131 current_subrange->TopLevel()->id()); | |
132 LifetimePosition block_start = | |
133 GetSplitPositionForInstruction(current_subrange, working_index); | |
134 LiveRange* block_and_after = nullptr; | |
135 if (block_start.IsValid()) { | |
136 block_and_after = Split(current_subrange, data, block_start); | |
137 } else { | |
138 block_and_after = current_subrange; | |
139 } | |
140 LiveRange* next = SplitRangeAfterBlock(block_and_after, data, block); | |
141 if (next != current_subrange) interval = next->first_interval(); | |
142 current_subrange = next; | |
143 break; | |
144 } | |
145 } | |
146 } | |
147 } | |
148 | |
149 | |
19 void PreprocessLiveRanges::PreprocessRanges() { | 150 void PreprocessLiveRanges::PreprocessRanges() { |
20 SplitRangesAroundDeferredBlocks(); | 151 SplitRangesAroundDeferredBlocks(); |
21 } | 152 } |
22 | 153 |
23 | 154 |
24 void PreprocessLiveRanges::SplitRangesAroundDeferredBlocks() {} | 155 void PreprocessLiveRanges::SplitRangesAroundDeferredBlocks() { |
25 | 156 size_t live_range_count = data()->live_ranges().size(); |
157 for (size_t i = 0; i < live_range_count; i++) { | |
158 LiveRange* range = data()->live_ranges()[i]; | |
159 if (range != nullptr && !range->IsEmpty() && !range->spilled() && | |
160 !range->IsFixed() && !range->IsChild()) { | |
161 SplitRangeByClobberingDeferredBlocks(range, data()); | |
162 } | |
163 } | |
164 } | |
26 | 165 |
27 } // namespace compiler | 166 } // namespace compiler |
28 } // namespace internal | 167 } // namespace internal |
29 } // namespace v8 | 168 } // namespace v8 |
OLD | NEW |