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

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

Issue 1405363003: Move Hydrogen and Lithium to src/crankshaft/ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 5 years, 2 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
« no previous file with comments | « src/mips/lithium-gap-resolver-mips.h ('k') | src/mips/lithium-mips.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/mips/lithium-codegen-mips.h"
6 #include "src/mips/lithium-gap-resolver-mips.h"
7
8 namespace v8 {
9 namespace internal {
10
11 LGapResolver::LGapResolver(LCodeGen* owner)
12 : cgen_(owner),
13 moves_(32, owner->zone()),
14 root_index_(0),
15 in_cycle_(false),
16 saved_destination_(NULL) {}
17
18
19 void LGapResolver::Resolve(LParallelMove* parallel_move) {
20 DCHECK(moves_.is_empty());
21 // Build up a worklist of moves.
22 BuildInitialMoveList(parallel_move);
23
24 for (int i = 0; i < moves_.length(); ++i) {
25 LMoveOperands move = moves_[i];
26 // Skip constants to perform them last. They don't block other moves
27 // and skipping such moves with register destinations keeps those
28 // registers free for the whole algorithm.
29 if (!move.IsEliminated() && !move.source()->IsConstantOperand()) {
30 root_index_ = i; // Any cycle is found when by reaching this move again.
31 PerformMove(i);
32 if (in_cycle_) {
33 RestoreValue();
34 }
35 }
36 }
37
38 // Perform the moves with constant sources.
39 for (int i = 0; i < moves_.length(); ++i) {
40 if (!moves_[i].IsEliminated()) {
41 DCHECK(moves_[i].source()->IsConstantOperand());
42 EmitMove(i);
43 }
44 }
45
46 moves_.Rewind(0);
47 }
48
49
50 void LGapResolver::BuildInitialMoveList(LParallelMove* parallel_move) {
51 // Perform a linear sweep of the moves to add them to the initial list of
52 // moves to perform, ignoring any move that is redundant (the source is
53 // the same as the destination, the destination is ignored and
54 // unallocated, or the move was already eliminated).
55 const ZoneList<LMoveOperands>* moves = parallel_move->move_operands();
56 for (int i = 0; i < moves->length(); ++i) {
57 LMoveOperands move = moves->at(i);
58 if (!move.IsRedundant()) moves_.Add(move, cgen_->zone());
59 }
60 Verify();
61 }
62
63
64 void LGapResolver::PerformMove(int index) {
65 // Each call to this function performs a move and deletes it from the move
66 // graph. We first recursively perform any move blocking this one. We
67 // mark a move as "pending" on entry to PerformMove in order to detect
68 // cycles in the move graph.
69
70 // We can only find a cycle, when doing a depth-first traversal of moves,
71 // be encountering the starting move again. So by spilling the source of
72 // the starting move, we break the cycle. All moves are then unblocked,
73 // and the starting move is completed by writing the spilled value to
74 // its destination. All other moves from the spilled source have been
75 // completed prior to breaking the cycle.
76 // An additional complication is that moves to MemOperands with large
77 // offsets (more than 1K or 4K) require us to spill this spilled value to
78 // the stack, to free up the register.
79 DCHECK(!moves_[index].IsPending());
80 DCHECK(!moves_[index].IsRedundant());
81
82 // Clear this move's destination to indicate a pending move. The actual
83 // destination is saved in a stack allocated local. Multiple moves can
84 // be pending because this function is recursive.
85 DCHECK(moves_[index].source() != NULL); // Or else it will look eliminated.
86 LOperand* destination = moves_[index].destination();
87 moves_[index].set_destination(NULL);
88
89 // Perform a depth-first traversal of the move graph to resolve
90 // dependencies. Any unperformed, unpending move with a source the same
91 // as this one's destination blocks this one so recursively perform all
92 // such moves.
93 for (int i = 0; i < moves_.length(); ++i) {
94 LMoveOperands other_move = moves_[i];
95 if (other_move.Blocks(destination) && !other_move.IsPending()) {
96 PerformMove(i);
97 // If there is a blocking, pending move it must be moves_[root_index_]
98 // and all other moves with the same source as moves_[root_index_] are
99 // sucessfully executed (because they are cycle-free) by this loop.
100 }
101 }
102
103 // We are about to resolve this move and don't need it marked as
104 // pending, so restore its destination.
105 moves_[index].set_destination(destination);
106
107 // The move may be blocked on a pending move, which must be the starting move.
108 // In this case, we have a cycle, and we save the source of this move to
109 // a scratch register to break it.
110 LMoveOperands other_move = moves_[root_index_];
111 if (other_move.Blocks(destination)) {
112 DCHECK(other_move.IsPending());
113 BreakCycle(index);
114 return;
115 }
116
117 // This move is no longer blocked.
118 EmitMove(index);
119 }
120
121
122 void LGapResolver::Verify() {
123 #ifdef ENABLE_SLOW_DCHECKS
124 // No operand should be the destination for more than one move.
125 for (int i = 0; i < moves_.length(); ++i) {
126 LOperand* destination = moves_[i].destination();
127 for (int j = i + 1; j < moves_.length(); ++j) {
128 SLOW_DCHECK(!destination->Equals(moves_[j].destination()));
129 }
130 }
131 #endif
132 }
133
134 #define __ ACCESS_MASM(cgen_->masm())
135
136 void LGapResolver::BreakCycle(int index) {
137 // We save in a register the value that should end up in the source of
138 // moves_[root_index]. After performing all moves in the tree rooted
139 // in that move, we save the value to that source.
140 DCHECK(moves_[index].destination()->Equals(moves_[root_index_].source()));
141 DCHECK(!in_cycle_);
142 in_cycle_ = true;
143 LOperand* source = moves_[index].source();
144 saved_destination_ = moves_[index].destination();
145 if (source->IsRegister()) {
146 __ mov(kLithiumScratchReg, cgen_->ToRegister(source));
147 } else if (source->IsStackSlot()) {
148 __ lw(kLithiumScratchReg, cgen_->ToMemOperand(source));
149 } else if (source->IsDoubleRegister()) {
150 __ mov_d(kLithiumScratchDouble, cgen_->ToDoubleRegister(source));
151 } else if (source->IsDoubleStackSlot()) {
152 __ ldc1(kLithiumScratchDouble, cgen_->ToMemOperand(source));
153 } else {
154 UNREACHABLE();
155 }
156 // This move will be done by restoring the saved value to the destination.
157 moves_[index].Eliminate();
158 }
159
160
161 void LGapResolver::RestoreValue() {
162 DCHECK(in_cycle_);
163 DCHECK(saved_destination_ != NULL);
164
165 // Spilled value is in kLithiumScratchReg or kLithiumScratchDouble.
166 if (saved_destination_->IsRegister()) {
167 __ mov(cgen_->ToRegister(saved_destination_), kLithiumScratchReg);
168 } else if (saved_destination_->IsStackSlot()) {
169 __ sw(kLithiumScratchReg, cgen_->ToMemOperand(saved_destination_));
170 } else if (saved_destination_->IsDoubleRegister()) {
171 __ mov_d(cgen_->ToDoubleRegister(saved_destination_),
172 kLithiumScratchDouble);
173 } else if (saved_destination_->IsDoubleStackSlot()) {
174 __ sdc1(kLithiumScratchDouble,
175 cgen_->ToMemOperand(saved_destination_));
176 } else {
177 UNREACHABLE();
178 }
179
180 in_cycle_ = false;
181 saved_destination_ = NULL;
182 }
183
184
185 void LGapResolver::EmitMove(int index) {
186 LOperand* source = moves_[index].source();
187 LOperand* destination = moves_[index].destination();
188
189 // Dispatch on the source and destination operand kinds. Not all
190 // combinations are possible.
191
192 if (source->IsRegister()) {
193 Register source_register = cgen_->ToRegister(source);
194 if (destination->IsRegister()) {
195 __ mov(cgen_->ToRegister(destination), source_register);
196 } else {
197 DCHECK(destination->IsStackSlot());
198 __ sw(source_register, cgen_->ToMemOperand(destination));
199 }
200 } else if (source->IsStackSlot()) {
201 MemOperand source_operand = cgen_->ToMemOperand(source);
202 if (destination->IsRegister()) {
203 __ lw(cgen_->ToRegister(destination), source_operand);
204 } else {
205 DCHECK(destination->IsStackSlot());
206 MemOperand destination_operand = cgen_->ToMemOperand(destination);
207 if (in_cycle_) {
208 if (!destination_operand.OffsetIsInt16Encodable()) {
209 // 'at' is overwritten while saving the value to the destination.
210 // Therefore we can't use 'at'. It is OK if the read from the source
211 // destroys 'at', since that happens before the value is read.
212 // This uses only a single reg of the double reg-pair.
213 __ lwc1(kLithiumScratchDouble, source_operand);
214 __ swc1(kLithiumScratchDouble, destination_operand);
215 } else {
216 __ lw(at, source_operand);
217 __ sw(at, destination_operand);
218 }
219 } else {
220 __ lw(kLithiumScratchReg, source_operand);
221 __ sw(kLithiumScratchReg, destination_operand);
222 }
223 }
224
225 } else if (source->IsConstantOperand()) {
226 LConstantOperand* constant_source = LConstantOperand::cast(source);
227 if (destination->IsRegister()) {
228 Register dst = cgen_->ToRegister(destination);
229 Representation r = cgen_->IsSmi(constant_source)
230 ? Representation::Smi() : Representation::Integer32();
231 if (cgen_->IsInteger32(constant_source)) {
232 __ li(dst, Operand(cgen_->ToRepresentation(constant_source, r)));
233 } else {
234 __ li(dst, cgen_->ToHandle(constant_source));
235 }
236 } else if (destination->IsDoubleRegister()) {
237 DoubleRegister result = cgen_->ToDoubleRegister(destination);
238 double v = cgen_->ToDouble(constant_source);
239 __ Move(result, v);
240 } else {
241 DCHECK(destination->IsStackSlot());
242 DCHECK(!in_cycle_); // Constant moves happen after all cycles are gone.
243 Representation r = cgen_->IsSmi(constant_source)
244 ? Representation::Smi() : Representation::Integer32();
245 if (cgen_->IsInteger32(constant_source)) {
246 __ li(kLithiumScratchReg,
247 Operand(cgen_->ToRepresentation(constant_source, r)));
248 } else {
249 __ li(kLithiumScratchReg, cgen_->ToHandle(constant_source));
250 }
251 __ sw(kLithiumScratchReg, cgen_->ToMemOperand(destination));
252 }
253
254 } else if (source->IsDoubleRegister()) {
255 DoubleRegister source_register = cgen_->ToDoubleRegister(source);
256 if (destination->IsDoubleRegister()) {
257 __ mov_d(cgen_->ToDoubleRegister(destination), source_register);
258 } else {
259 DCHECK(destination->IsDoubleStackSlot());
260 MemOperand destination_operand = cgen_->ToMemOperand(destination);
261 __ sdc1(source_register, destination_operand);
262 }
263
264 } else if (source->IsDoubleStackSlot()) {
265 MemOperand source_operand = cgen_->ToMemOperand(source);
266 if (destination->IsDoubleRegister()) {
267 __ ldc1(cgen_->ToDoubleRegister(destination), source_operand);
268 } else {
269 DCHECK(destination->IsDoubleStackSlot());
270 MemOperand destination_operand = cgen_->ToMemOperand(destination);
271 if (in_cycle_) {
272 // kLithiumScratchDouble was used to break the cycle,
273 // but kLithiumScratchReg is free.
274 MemOperand source_high_operand =
275 cgen_->ToHighMemOperand(source);
276 MemOperand destination_high_operand =
277 cgen_->ToHighMemOperand(destination);
278 __ lw(kLithiumScratchReg, source_operand);
279 __ sw(kLithiumScratchReg, destination_operand);
280 __ lw(kLithiumScratchReg, source_high_operand);
281 __ sw(kLithiumScratchReg, destination_high_operand);
282 } else {
283 __ ldc1(kLithiumScratchDouble, source_operand);
284 __ sdc1(kLithiumScratchDouble, destination_operand);
285 }
286 }
287 } else {
288 UNREACHABLE();
289 }
290
291 moves_[index].Eliminate();
292 }
293
294
295 #undef __
296
297 } // namespace internal
298 } // namespace v8
OLDNEW
« no previous file with comments | « src/mips/lithium-gap-resolver-mips.h ('k') | src/mips/lithium-mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698