Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: src/arm/lithium-gap-resolver-arm.cc

Issue 6311010: ARM: Port new version of ParallelMove's GapResolver to ARM. Add MemOperand s... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "arm/lithium-gap-resolver-arm.h"
29 #include "arm/lithium-codegen-arm.h"
30
31 namespace v8 {
32 namespace internal {
33
34 static const Register kSavedValueRegister = r9;
Søren Thygesen Gjesse 2011/01/25 08:33:20 Use LCodeGen::scratch0 instead.
William Hesse 2011/01/25 17:25:13 Used { 9 } instead, with an assert that it equals
35 static const DoubleRegister kSavedDoubleValueRegister = d0;
Søren Thygesen Gjesse 2011/01/25 08:33:20 Use LCodeGen::double_scratch0() instead.
William Hesse 2011/01/25 17:25:13 Used { 0 } instead.
36
37 LGapResolver::LGapResolver(LCodeGen* owner)
38 : cgen_(owner), moves_(32), root_index_(0), in_cycle_(false),
39 cycle_breaker_spilled_(false), saved_destination_(NULL) {}
40
41
42 void LGapResolver::Resolve(LParallelMove* parallel_move) {
43 ASSERT(moves_.is_empty());
44 // Build up a worklist of moves.
45 BuildInitialMoveList(parallel_move);
46
47 for (int i = 0; i < moves_.length(); ++i) {
48 LMoveOperands move = moves_[i];
49 // Skip constants to perform them last. They don't block other moves
50 // and skipping such moves with register destinations keeps those
51 // registers free for the whole algorithm.
52 if (!move.IsEliminated() && !move.source()->IsConstantOperand()) {
53 root_index_ = i;
54 PerformMove(i);
55 if (in_cycle_) {
56 RestoreValue();
57 }
58 }
59 }
60
61 // Perform the moves with constant sources.
62 for (int i = 0; i < moves_.length(); ++i) {
63 if (!moves_[i].IsEliminated()) {
64 ASSERT(moves_[i].source()->IsConstantOperand());
65 EmitMove(i);
66 }
67 }
68
69 moves_.Rewind(0);
70 }
71
72
73 void LGapResolver::BuildInitialMoveList(LParallelMove* parallel_move) {
74 // Perform a linear sweep of the moves to add them to the initial list of
75 // moves to perform, ignoring any move that is redundant (the source is
76 // the same as the destination, the destination is ignored and
77 // unallocated, or the move was already eliminated).
78 const ZoneList<LMoveOperands>* moves = parallel_move->move_operands();
79 for (int i = 0; i < moves->length(); ++i) {
80 LMoveOperands move = moves->at(i);
81 if (!move.IsRedundant()) moves_.Add(move);
82 }
83 Verify();
84 }
85
86
87 void LGapResolver::PerformMove(int index) {
88 // Each call to this function performs a move and deletes it from the move
89 // graph. We first recursively perform any move blocking this one. We
90 // mark a move as "pending" on entry to PerformMove in order to detect
91 // cycles in the move graph.
92
93 // We can only find a cycle, when doing a depth-first traversal of moves,
94 // be encountering the starting move again. So by spilling the source of
95 // the starting move, we break the cycle. All moves are then unblocked,
96 // and the starting move is completed by writing the spilled value to
97 // its destination. All other moves from the spilled source have been
98 // completed prior to breaking the cycle.
99 // An additional complication is that moves to MemOperands with large
100 // offsets (more than 1K or 4K) require us to spill this spilled value to
101 // the stack, to free up the register.
102 ASSERT(!moves_[index].IsPending());
103 ASSERT(!moves_[index].IsRedundant());
104
105 // Clear this move's destination to indicate a pending move. The actual
106 // destination is saved in a stack allocated local. Multiple moves can
107 // be pending because this function is recursive.
108 ASSERT(moves_[index].source() != NULL); // Or else it will look eliminated.
109 LOperand* destination = moves_[index].destination();
110 moves_[index].set_destination(NULL);
111
112 // Perform a depth-first traversal of the move graph to resolve
113 // dependencies. Any unperformed, unpending move with a source the same
114 // as this one's destination blocks this one so recursively perform all
115 // such moves.
116 for (int i = 0; i < moves_.length(); ++i) {
117 LMoveOperands other_move = moves_[i];
118 if (other_move.Blocks(destination) && !other_move.IsPending()) {
119 PerformMove(i);
120 // If there is a blocking, pending move it must be moves_[root_index_]
121 // and all other moves with the same source as moves_[root_index_] are
122 // sucessfully executed (because they are cycle-free) by this loop.
123 }
124 }
125
126 // We are about to resolve this move and don't need it marked as
127 // pending, so restore its destination.
128 moves_[index].set_destination(destination);
129
130 // This move's source may have changed due to swaps to resolve cycles and
131 // so it may now be the last move in the cycle. If so remove it.
132 if (moves_[index].source()->Equals(destination)) {
133 moves_[index].Eliminate();
134 return;
135 }
136
137 // The move may be blocked on a (at most one) pending move, in which case
138 // we have a cycle. The only possible blocking move is the starting move.
139 LMoveOperands other_move = moves_[root_index_];
140 if (other_move.Blocks(destination)) {
141 ASSERT(other_move.IsPending());
142 BreakCycle(index);
143 return;
144 }
145
146 // This move is no longer blocked.
147 EmitMove(index);
148 }
149
150
151 void LGapResolver::Verify() {
152 #ifdef ENABLE_SLOW_ASSERTS
153 // No operand should be the destination for more than one move.
154 for (int i = 0; i < moves_.length(); ++i) {
155 LOperand* destination = moves_[i].destination();
156 for (int j = i + 1; j < moves_.length(); ++j) {
157 SLOW_ASSERT(!destination->Equals(moves_[j].destination()));
158 }
159 }
160 #endif
161 }
162
163 #define __ ACCESS_MASM(cgen_->masm())
164
165 void LGapResolver::BreakCycle(int index) {
166 // We save in a register the value that should end up in the source of
167 // moves_[root_index]. After performing all moves in the tree rooted
168 // in that move, we save the value to that source.
169 ASSERT(moves_[index].destination()->Equals(moves_[root_index_].source()));
170 ASSERT(!in_cycle_);
171 ASSERT(!cycle_breaker_spilled_);
172 in_cycle_ = true;
173 LOperand* source = moves_[index].source();
174 saved_destination_ = moves_[index].destination();
175 if (source->IsRegister()) {
176 __ mov(kSavedValueRegister, cgen_->ToRegister(source));
177 } else if (source->IsStackSlot()) {
178 __ ldr(kSavedValueRegister, cgen_->ToMemOperand(source));
179 } else if (source->IsDoubleRegister()) {
180 __ vmov(kSavedDoubleValueRegister, cgen_->ToDoubleRegister(source));
181 } else if (source->IsDoubleStackSlot()) {
182 MemOperand source_operand = cgen_->ToMemOperand(source);
183 __ vldr(kSavedDoubleValueRegister, source_operand.rn(),
184 source_operand.offset());
185 } else {
186 UNREACHABLE();
187 }
188 // This move will be done by restoring the saved value to the destination.
189 moves_[index].Eliminate();
190 }
191
192
193 void LGapResolver::RestoreValue() {
194 ASSERT(in_cycle_);
195 ASSERT(saved_destination_ != NULL);
196
197 if (cycle_breaker_spilled_) {
198 // Restore from stack
Søren Thygesen Gjesse 2011/01/25 08:33:20 End comment with full stop.
William Hesse 2011/01/25 17:25:13 Done.
199 if (saved_destination_->IsRegister()) {
200 __ pop(cgen_->ToRegister(saved_destination_));
201 } else if (saved_destination_->IsStackSlot()) {
202 __ pop(kSavedValueRegister);
203 __ str(kSavedValueRegister, cgen_->ToMemOperand(saved_destination_));
204 } else if (saved_destination_->IsDoubleRegister()) {
205 __ vldr(cgen_->ToDoubleRegister(saved_destination_), MemOperand(sp, 0));
206 __ add(sp, sp, Operand(8));
207 } else if (saved_destination_->IsDoubleStackSlot()) {
208 __ vldr(kSavedDoubleValueRegister, MemOperand(sp, 0));
209 __ add(sp, sp, Operand(8));
210 __ vstr(kSavedDoubleValueRegister,
211 cgen_->ToMemOperand(saved_destination_));
212 } else {
213 UNREACHABLE();
214 }
215 } else {
216 // Spilled value is in kSavedValueRegister or kSavedDoubleValueRegister.
217 if (saved_destination_->IsRegister()) {
218 __ mov(cgen_->ToRegister(saved_destination_), kSavedValueRegister);
219 } else if (saved_destination_->IsStackSlot()) {
220 __ str(kSavedValueRegister, cgen_->ToMemOperand(saved_destination_));
221 } else if (saved_destination_->IsDoubleRegister()) {
222 __ vmov(cgen_->ToDoubleRegister(saved_destination_),
223 kSavedDoubleValueRegister);
224 } else if (saved_destination_->IsDoubleStackSlot()) {
225 __ vldr(kSavedDoubleValueRegister,
226 cgen_->ToMemOperand(saved_destination_));
227 } else {
228 UNREACHABLE();
Søren Thygesen Gjesse 2011/01/25 08:33:20 Missing indent.
William Hesse 2011/01/25 17:25:13 Done.
229 }
230 }
231
232 in_cycle_ = false;
233 cycle_breaker_spilled_ = false;
234 saved_destination_ = NULL;
235 }
236
237
238 void LGapResolver::EmitMove(int index) {
239 LOperand* source = moves_[index].source();
240 LOperand* destination = moves_[index].destination();
241
242 // Dispatch on the source and destination operand kinds. Not all
243 // combinations are possible.
244
245 if (source->IsRegister()) {
246 Register source_register = cgen_->ToRegister(source);
247 if (destination->IsRegister()) {
248 __ mov(cgen_->ToRegister(destination), source_register);
249 } else {
250 ASSERT(destination->IsStackSlot());
251 __ str(source_register, cgen_->ToMemOperand(destination));
252 }
253
254 } else if (source->IsStackSlot()) {
255 MemOperand source_operand = cgen_->ToMemOperand(source);
256 if (destination->IsRegister()) {
257 __ ldr(cgen_->ToRegister(destination), source_operand);
258 } else {
259 ASSERT(destination->IsStackSlot());
260 MemOperand destination_operand = cgen_->ToMemOperand(destination);
261 if (in_cycle_ && !cycle_breaker_spilled_) {
262 if (!destination_operand.OffsetIsEncodable()) {
Søren Thygesen Gjesse 2011/01/25 08:33:20 Please explain this check for OffsetIsEncodable. T
William Hesse 2011/01/25 17:25:13 Done.
263 cycle_breaker_spilled_ = true;
264 __ push(kSavedValueRegister);
265 __ ldr(kSavedValueRegister, source_operand);
266 __ str(kSavedValueRegister, destination_operand);
267 } else {
268 __ ldr(ip, source_operand);
269 __ str(ip, destination_operand);
270 }
271 } else {
272 __ ldr(kSavedValueRegister, source_operand);
273 __ str(kSavedValueRegister, destination_operand);
274 }
275 }
276
277 } else if (source->IsConstantOperand()) {
278 Operand source_operand = cgen_->ToOperand(source);
279 if (destination->IsRegister()) {
280 __ mov(cgen_->ToRegister(destination), source_operand);
281 } else {
282 ASSERT(destination->IsStackSlot());
283 MemOperand destination_operand = cgen_->ToMemOperand(destination);
284 if (in_cycle_ && !cycle_breaker_spilled_) {
285 if (!destination_operand.OffsetIsEncodable()) {
Søren Thygesen Gjesse 2011/01/25 08:33:20 Ditto.
William Hesse 2011/01/25 17:25:13 Done.
William Hesse 2011/01/25 17:25:13 Done.
286 cycle_breaker_spilled_ = true;
287 __ push(kSavedValueRegister);
288 __ mov(kSavedValueRegister, source_operand);
289 __ str(kSavedValueRegister, destination_operand);
290 } else {
291 __ mov(ip, source_operand);
292 __ str(ip, destination_operand);
293 }
294 } else {
295 __ mov(kSavedValueRegister, source_operand);
296 __ str(kSavedValueRegister, destination_operand);
297 }
298 }
299
300 } else if (source->IsDoubleRegister()) {
301 DoubleRegister source_register = cgen_->ToDoubleRegister(source);
302 if (destination->IsDoubleRegister()) {
303 __ vmov(cgen_->ToDoubleRegister(destination), source_register);
304 } else {
305 ASSERT(destination->IsDoubleStackSlot());
306 MemOperand destination_operand = cgen_->ToMemOperand(destination);
307 __ vstr(source_register, destination_operand);
308 }
309
310 } else if (source->IsDoubleStackSlot()) {
311 MemOperand source_operand = cgen_->ToMemOperand(source);
312 if (destination->IsDoubleRegister()) {
313 __ vldr(cgen_->ToDoubleRegister(destination), source_operand);
314 } else {
315 ASSERT(destination->IsDoubleStackSlot());
316 MemOperand destination_operand = cgen_->ToMemOperand(destination);
317 if (in_cycle_ && !cycle_breaker_spilled_) {
318 MemOperand source_high_operand =
319 cgen_->ToHighMemOperand(source);
320 MemOperand destination_high_operand =
321 cgen_->ToHighMemOperand(destination);
322 if (destination_operand.OffsetIsVFPEncodable() &&
Søren Thygesen Gjesse 2011/01/25 08:33:20 Isn't this condition wrong? It should use vfp inst
William Hesse 2011/01/25 17:25:13 No, we can use vfp instructions in either case. Fo
323 destination_high_operand.OffsetIsVFPEncodable()) {
Søren Thygesen Gjesse 2011/01/25 08:33:20 Don't we need to check operands for OffsetIsEncoda
William Hesse 2011/01/25 17:25:13 You are right. All this is now rewritten to elimi
324 __ ldr(ip, source_operand);
325 __ str(ip, destination_operand);
326 __ ldr(ip, source_high_operand);
327 __ str(ip, destination_high_operand);
328 } else {
329 cycle_breaker_spilled_ = true;
Søren Thygesen Gjesse 2011/01/25 08:33:20 I don't know whether these three VFP load/stores t
William Hesse 2011/01/25 17:25:13 These are done if we can't use ip. But I see we c
330 __ sub(sp, sp, Operand(8));
331 __ vstr(kSavedDoubleValueRegister, MemOperand(sp, 0));
332 __ vldr(kSavedDoubleValueRegister, source_operand);
333 __ vstr(kSavedDoubleValueRegister, destination_operand);
334 }
335 } else {
336 __ vldr(kSavedDoubleValueRegister, source_operand);
337 __ vstr(kSavedDoubleValueRegister, destination_operand);
338 }
339 }
340 } else {
341 UNREACHABLE();
342 }
343
344 moves_[index].Eliminate();
345 }
346
347
348 #undef __
349
350 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698