| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // |
| 3 // Copyright IBM Corp. 2012, 2013. All rights reserved. |
| 4 // |
| 2 // Use of this source code is governed by a BSD-style license that can be | 5 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 6 // found in the LICENSE file. |
| 4 | 7 |
| 5 #include "src/v8.h" | 8 #include "src/v8.h" |
| 6 | 9 |
| 7 #include "src/mips/lithium-codegen-mips.h" | 10 #include "src/ppc/lithium-codegen-ppc.h" |
| 8 #include "src/mips/lithium-gap-resolver-mips.h" | 11 #include "src/ppc/lithium-gap-resolver-ppc.h" |
| 9 | 12 |
| 10 namespace v8 { | 13 namespace v8 { |
| 11 namespace internal { | 14 namespace internal { |
| 12 | 15 |
| 16 static const Register kSavedValueRegister = { 11 }; |
| 17 |
| 13 LGapResolver::LGapResolver(LCodeGen* owner) | 18 LGapResolver::LGapResolver(LCodeGen* owner) |
| 14 : cgen_(owner), | 19 : cgen_(owner), moves_(32, owner->zone()), root_index_(0), in_cycle_(false), |
| 15 moves_(32, owner->zone()), | 20 saved_destination_(NULL) { } |
| 16 root_index_(0), | |
| 17 in_cycle_(false), | |
| 18 saved_destination_(NULL) {} | |
| 19 | 21 |
| 20 | 22 |
| 21 void LGapResolver::Resolve(LParallelMove* parallel_move) { | 23 void LGapResolver::Resolve(LParallelMove* parallel_move) { |
| 22 ASSERT(moves_.is_empty()); | 24 ASSERT(moves_.is_empty()); |
| 23 // Build up a worklist of moves. | 25 // Build up a worklist of moves. |
| 24 BuildInitialMoveList(parallel_move); | 26 BuildInitialMoveList(parallel_move); |
| 25 | 27 |
| 26 for (int i = 0; i < moves_.length(); ++i) { | 28 for (int i = 0; i < moves_.length(); ++i) { |
| 27 LMoveOperands move = moves_[i]; | 29 LMoveOperands move = moves_[i]; |
| 28 // Skip constants to perform them last. They don't block other moves | 30 // Skip constants to perform them last. They don't block other moves |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 void LGapResolver::BreakCycle(int index) { | 140 void LGapResolver::BreakCycle(int index) { |
| 139 // We save in a register the value that should end up in the source of | 141 // We save in a register the value that should end up in the source of |
| 140 // moves_[root_index]. After performing all moves in the tree rooted | 142 // moves_[root_index]. After performing all moves in the tree rooted |
| 141 // in that move, we save the value to that source. | 143 // in that move, we save the value to that source. |
| 142 ASSERT(moves_[index].destination()->Equals(moves_[root_index_].source())); | 144 ASSERT(moves_[index].destination()->Equals(moves_[root_index_].source())); |
| 143 ASSERT(!in_cycle_); | 145 ASSERT(!in_cycle_); |
| 144 in_cycle_ = true; | 146 in_cycle_ = true; |
| 145 LOperand* source = moves_[index].source(); | 147 LOperand* source = moves_[index].source(); |
| 146 saved_destination_ = moves_[index].destination(); | 148 saved_destination_ = moves_[index].destination(); |
| 147 if (source->IsRegister()) { | 149 if (source->IsRegister()) { |
| 148 __ mov(kLithiumScratchReg, cgen_->ToRegister(source)); | 150 __ mr(kSavedValueRegister, cgen_->ToRegister(source)); |
| 149 } else if (source->IsStackSlot()) { | 151 } else if (source->IsStackSlot()) { |
| 150 __ lw(kLithiumScratchReg, cgen_->ToMemOperand(source)); | 152 __ LoadP(kSavedValueRegister, cgen_->ToMemOperand(source)); |
| 151 } else if (source->IsDoubleRegister()) { | 153 } else if (source->IsDoubleRegister()) { |
| 152 __ mov_d(kLithiumScratchDouble, cgen_->ToDoubleRegister(source)); | 154 __ fmr(kScratchDoubleReg, cgen_->ToDoubleRegister(source)); |
| 153 } else if (source->IsDoubleStackSlot()) { | 155 } else if (source->IsDoubleStackSlot()) { |
| 154 __ ldc1(kLithiumScratchDouble, cgen_->ToMemOperand(source)); | 156 __ lfd(kScratchDoubleReg, cgen_->ToMemOperand(source)); |
| 155 } else { | 157 } else { |
| 156 UNREACHABLE(); | 158 UNREACHABLE(); |
| 157 } | 159 } |
| 158 // This move will be done by restoring the saved value to the destination. | 160 // This move will be done by restoring the saved value to the destination. |
| 159 moves_[index].Eliminate(); | 161 moves_[index].Eliminate(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 | 164 |
| 163 void LGapResolver::RestoreValue() { | 165 void LGapResolver::RestoreValue() { |
| 164 ASSERT(in_cycle_); | 166 ASSERT(in_cycle_); |
| 165 ASSERT(saved_destination_ != NULL); | 167 ASSERT(saved_destination_ != NULL); |
| 166 | 168 |
| 167 // Spilled value is in kLithiumScratchReg or kLithiumScratchDouble. | 169 // Spilled value is in kSavedValueRegister or kSavedDoubleValueRegister. |
| 168 if (saved_destination_->IsRegister()) { | 170 if (saved_destination_->IsRegister()) { |
| 169 __ mov(cgen_->ToRegister(saved_destination_), kLithiumScratchReg); | 171 __ mr(cgen_->ToRegister(saved_destination_), kSavedValueRegister); |
| 170 } else if (saved_destination_->IsStackSlot()) { | 172 } else if (saved_destination_->IsStackSlot()) { |
| 171 __ sw(kLithiumScratchReg, cgen_->ToMemOperand(saved_destination_)); | 173 __ StoreP(kSavedValueRegister, cgen_->ToMemOperand(saved_destination_)); |
| 172 } else if (saved_destination_->IsDoubleRegister()) { | 174 } else if (saved_destination_->IsDoubleRegister()) { |
| 173 __ mov_d(cgen_->ToDoubleRegister(saved_destination_), | 175 __ fmr(cgen_->ToDoubleRegister(saved_destination_), kScratchDoubleReg); |
| 174 kLithiumScratchDouble); | |
| 175 } else if (saved_destination_->IsDoubleStackSlot()) { | 176 } else if (saved_destination_->IsDoubleStackSlot()) { |
| 176 __ sdc1(kLithiumScratchDouble, | 177 __ stfd(kScratchDoubleReg, cgen_->ToMemOperand(saved_destination_)); |
| 177 cgen_->ToMemOperand(saved_destination_)); | |
| 178 } else { | 178 } else { |
| 179 UNREACHABLE(); | 179 UNREACHABLE(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 in_cycle_ = false; | 182 in_cycle_ = false; |
| 183 saved_destination_ = NULL; | 183 saved_destination_ = NULL; |
| 184 } | 184 } |
| 185 | 185 |
| 186 | 186 |
| 187 void LGapResolver::EmitMove(int index) { | 187 void LGapResolver::EmitMove(int index) { |
| 188 LOperand* source = moves_[index].source(); | 188 LOperand* source = moves_[index].source(); |
| 189 LOperand* destination = moves_[index].destination(); | 189 LOperand* destination = moves_[index].destination(); |
| 190 | 190 |
| 191 // Dispatch on the source and destination operand kinds. Not all | 191 // Dispatch on the source and destination operand kinds. Not all |
| 192 // combinations are possible. | 192 // combinations are possible. |
| 193 | 193 |
| 194 if (source->IsRegister()) { | 194 if (source->IsRegister()) { |
| 195 Register source_register = cgen_->ToRegister(source); | 195 Register source_register = cgen_->ToRegister(source); |
| 196 if (destination->IsRegister()) { | 196 if (destination->IsRegister()) { |
| 197 __ mov(cgen_->ToRegister(destination), source_register); | 197 __ mr(cgen_->ToRegister(destination), source_register); |
| 198 } else { | 198 } else { |
| 199 ASSERT(destination->IsStackSlot()); | 199 ASSERT(destination->IsStackSlot()); |
| 200 __ sw(source_register, cgen_->ToMemOperand(destination)); | 200 __ StoreP(source_register, cgen_->ToMemOperand(destination)); |
| 201 } | 201 } |
| 202 } else if (source->IsStackSlot()) { | 202 } else if (source->IsStackSlot()) { |
| 203 MemOperand source_operand = cgen_->ToMemOperand(source); | 203 MemOperand source_operand = cgen_->ToMemOperand(source); |
| 204 if (destination->IsRegister()) { | 204 if (destination->IsRegister()) { |
| 205 __ lw(cgen_->ToRegister(destination), source_operand); | 205 __ LoadP(cgen_->ToRegister(destination), source_operand); |
| 206 } else { | 206 } else { |
| 207 ASSERT(destination->IsStackSlot()); | 207 ASSERT(destination->IsStackSlot()); |
| 208 MemOperand destination_operand = cgen_->ToMemOperand(destination); | 208 MemOperand destination_operand = cgen_->ToMemOperand(destination); |
| 209 if (in_cycle_) { | 209 if (in_cycle_) { |
| 210 if (!destination_operand.OffsetIsInt16Encodable()) { | 210 __ LoadP(ip, source_operand); |
| 211 // 'at' is overwritten while saving the value to the destination. | 211 __ StoreP(ip, destination_operand); |
| 212 // Therefore we can't use 'at'. It is OK if the read from the source | |
| 213 // destroys 'at', since that happens before the value is read. | |
| 214 // This uses only a single reg of the double reg-pair. | |
| 215 __ lwc1(kLithiumScratchDouble, source_operand); | |
| 216 __ swc1(kLithiumScratchDouble, destination_operand); | |
| 217 } else { | |
| 218 __ lw(at, source_operand); | |
| 219 __ sw(at, destination_operand); | |
| 220 } | |
| 221 } else { | 212 } else { |
| 222 __ lw(kLithiumScratchReg, source_operand); | 213 __ LoadP(kSavedValueRegister, source_operand); |
| 223 __ sw(kLithiumScratchReg, destination_operand); | 214 __ StoreP(kSavedValueRegister, destination_operand); |
| 224 } | 215 } |
| 225 } | 216 } |
| 226 | 217 |
| 227 } else if (source->IsConstantOperand()) { | 218 } else if (source->IsConstantOperand()) { |
| 228 LConstantOperand* constant_source = LConstantOperand::cast(source); | 219 LConstantOperand* constant_source = LConstantOperand::cast(source); |
| 229 if (destination->IsRegister()) { | 220 if (destination->IsRegister()) { |
| 230 Register dst = cgen_->ToRegister(destination); | 221 Register dst = cgen_->ToRegister(destination); |
| 231 Representation r = cgen_->IsSmi(constant_source) | |
| 232 ? Representation::Smi() : Representation::Integer32(); | |
| 233 if (cgen_->IsInteger32(constant_source)) { | 222 if (cgen_->IsInteger32(constant_source)) { |
| 234 __ li(dst, Operand(cgen_->ToRepresentation(constant_source, r))); | 223 cgen_->EmitLoadIntegerConstant(constant_source, dst); |
| 235 } else { | 224 } else { |
| 236 __ li(dst, cgen_->ToHandle(constant_source)); | 225 __ Move(dst, cgen_->ToHandle(constant_source)); |
| 237 } | 226 } |
| 238 } else if (destination->IsDoubleRegister()) { | 227 } else if (destination->IsDoubleRegister()) { |
| 239 DoubleRegister result = cgen_->ToDoubleRegister(destination); | 228 DoubleRegister result = cgen_->ToDoubleRegister(destination); |
| 240 double v = cgen_->ToDouble(constant_source); | 229 double v = cgen_->ToDouble(constant_source); |
| 241 __ Move(result, v); | 230 __ LoadDoubleLiteral(result, v, ip); |
| 242 } else { | 231 } else { |
| 243 ASSERT(destination->IsStackSlot()); | 232 ASSERT(destination->IsStackSlot()); |
| 244 ASSERT(!in_cycle_); // Constant moves happen after all cycles are gone. | 233 ASSERT(!in_cycle_); // Constant moves happen after all cycles are gone. |
| 245 Representation r = cgen_->IsSmi(constant_source) | |
| 246 ? Representation::Smi() : Representation::Integer32(); | |
| 247 if (cgen_->IsInteger32(constant_source)) { | 234 if (cgen_->IsInteger32(constant_source)) { |
| 248 __ li(kLithiumScratchReg, | 235 cgen_->EmitLoadIntegerConstant(constant_source, kSavedValueRegister); |
| 249 Operand(cgen_->ToRepresentation(constant_source, r))); | |
| 250 } else { | 236 } else { |
| 251 __ li(kLithiumScratchReg, cgen_->ToHandle(constant_source)); | 237 __ Move(kSavedValueRegister, |
| 238 cgen_->ToHandle(constant_source)); |
| 252 } | 239 } |
| 253 __ sw(kLithiumScratchReg, cgen_->ToMemOperand(destination)); | 240 __ StoreP(kSavedValueRegister, cgen_->ToMemOperand(destination)); |
| 254 } | 241 } |
| 255 | 242 |
| 256 } else if (source->IsDoubleRegister()) { | 243 } else if (source->IsDoubleRegister()) { |
| 257 DoubleRegister source_register = cgen_->ToDoubleRegister(source); | 244 DoubleRegister source_register = cgen_->ToDoubleRegister(source); |
| 258 if (destination->IsDoubleRegister()) { | 245 if (destination->IsDoubleRegister()) { |
| 259 __ mov_d(cgen_->ToDoubleRegister(destination), source_register); | 246 __ fmr(cgen_->ToDoubleRegister(destination), source_register); |
| 260 } else { | 247 } else { |
| 261 ASSERT(destination->IsDoubleStackSlot()); | 248 ASSERT(destination->IsDoubleStackSlot()); |
| 262 MemOperand destination_operand = cgen_->ToMemOperand(destination); | 249 __ stfd(source_register, cgen_->ToMemOperand(destination)); |
| 263 __ sdc1(source_register, destination_operand); | |
| 264 } | 250 } |
| 265 | 251 |
| 266 } else if (source->IsDoubleStackSlot()) { | 252 } else if (source->IsDoubleStackSlot()) { |
| 267 MemOperand source_operand = cgen_->ToMemOperand(source); | 253 MemOperand source_operand = cgen_->ToMemOperand(source); |
| 268 if (destination->IsDoubleRegister()) { | 254 if (destination->IsDoubleRegister()) { |
| 269 __ ldc1(cgen_->ToDoubleRegister(destination), source_operand); | 255 __ lfd(cgen_->ToDoubleRegister(destination), source_operand); |
| 270 } else { | 256 } else { |
| 271 ASSERT(destination->IsDoubleStackSlot()); | 257 ASSERT(destination->IsDoubleStackSlot()); |
| 272 MemOperand destination_operand = cgen_->ToMemOperand(destination); | 258 MemOperand destination_operand = cgen_->ToMemOperand(destination); |
| 273 if (in_cycle_) { | 259 if (in_cycle_) { |
| 274 // kLithiumScratchDouble was used to break the cycle, | 260 // kSavedDoubleValueRegister was used to break the cycle, |
| 275 // but kLithiumScratchReg is free. | 261 // but kSavedValueRegister is free. |
| 262 #if V8_TARGET_ARCH_PPC64 |
| 263 __ ld(kSavedValueRegister, source_operand); |
| 264 __ std(kSavedValueRegister, destination_operand); |
| 265 #else |
| 276 MemOperand source_high_operand = | 266 MemOperand source_high_operand = |
| 277 cgen_->ToHighMemOperand(source); | 267 cgen_->ToHighMemOperand(source); |
| 278 MemOperand destination_high_operand = | 268 MemOperand destination_high_operand = |
| 279 cgen_->ToHighMemOperand(destination); | 269 cgen_->ToHighMemOperand(destination); |
| 280 __ lw(kLithiumScratchReg, source_operand); | 270 __ lwz(kSavedValueRegister, source_operand); |
| 281 __ sw(kLithiumScratchReg, destination_operand); | 271 __ stw(kSavedValueRegister, destination_operand); |
| 282 __ lw(kLithiumScratchReg, source_high_operand); | 272 __ lwz(kSavedValueRegister, source_high_operand); |
| 283 __ sw(kLithiumScratchReg, destination_high_operand); | 273 __ stw(kSavedValueRegister, destination_high_operand); |
| 274 #endif |
| 284 } else { | 275 } else { |
| 285 __ ldc1(kLithiumScratchDouble, source_operand); | 276 __ lfd(kScratchDoubleReg, source_operand); |
| 286 __ sdc1(kLithiumScratchDouble, destination_operand); | 277 __ stfd(kScratchDoubleReg, destination_operand); |
| 287 } | 278 } |
| 288 } | 279 } |
| 289 } else { | 280 } else { |
| 290 UNREACHABLE(); | 281 UNREACHABLE(); |
| 291 } | 282 } |
| 292 | 283 |
| 293 moves_[index].Eliminate(); | 284 moves_[index].Eliminate(); |
| 294 } | 285 } |
| 295 | 286 |
| 296 | 287 |
| 297 #undef __ | 288 #undef __ |
| 298 | 289 |
| 299 } } // namespace v8::internal | 290 } } // namespace v8::internal |
| OLD | NEW |