| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/move-optimizer.h" | 5 #include "src/compiler/move-optimizer.h" |
| 6 | 6 |
| 7 namespace v8 { | 7 namespace v8 { |
| 8 namespace internal { | 8 namespace internal { |
| 9 namespace compiler { | 9 namespace compiler { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 typedef std::pair<InstructionOperand, InstructionOperand> MoveKey; | 13 typedef std::pair<InstructionOperand, InstructionOperand> MoveKey; |
| 14 | 14 |
| 15 struct MoveKeyCompare { | 15 struct MoveKeyCompare { |
| 16 bool operator()(const MoveKey& a, const MoveKey& b) const { | 16 bool operator()(const MoveKey& a, const MoveKey& b) const { |
| 17 if (a.first.EqualsModuloType(b.first)) { | 17 if (a.first.EqualsCanonicalized(b.first)) { |
| 18 return a.second.CompareModuloType(b.second); | 18 return a.second.CompareCanonicalized(b.second); |
| 19 } | 19 } |
| 20 return a.first.CompareModuloType(b.first); | 20 return a.first.CompareCanonicalized(b.first); |
| 21 } | 21 } |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 typedef ZoneMap<MoveKey, unsigned, MoveKeyCompare> MoveMap; | 24 typedef ZoneMap<MoveKey, unsigned, MoveKeyCompare> MoveMap; |
| 25 typedef ZoneSet<InstructionOperand, CompareOperandModuloType> OperandSet; | 25 typedef ZoneSet<InstructionOperand, CompareOperandModuloType> OperandSet; |
| 26 | 26 |
| 27 | 27 |
| 28 bool GapsCanMoveOver(Instruction* instr) { return instr->IsNop(); } | 28 bool GapsCanMoveOver(Instruction* instr) { return instr->IsNop(); } |
| 29 | 29 |
| 30 | 30 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 | 239 |
| 240 namespace { | 240 namespace { |
| 241 | 241 |
| 242 bool IsSlot(const InstructionOperand& op) { | 242 bool IsSlot(const InstructionOperand& op) { |
| 243 return op.IsStackSlot() || op.IsDoubleStackSlot(); | 243 return op.IsStackSlot() || op.IsDoubleStackSlot(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 | 246 |
| 247 bool LoadCompare(const MoveOperands* a, const MoveOperands* b) { | 247 bool LoadCompare(const MoveOperands* a, const MoveOperands* b) { |
| 248 if (!a->source().EqualsModuloType(b->source())) { | 248 if (!a->source().EqualsCanonicalized(b->source())) { |
| 249 return a->source().CompareModuloType(b->source()); | 249 return a->source().CompareCanonicalized(b->source()); |
| 250 } | 250 } |
| 251 if (IsSlot(a->destination()) && !IsSlot(b->destination())) return false; | 251 if (IsSlot(a->destination()) && !IsSlot(b->destination())) return false; |
| 252 if (!IsSlot(a->destination()) && IsSlot(b->destination())) return true; | 252 if (!IsSlot(a->destination()) && IsSlot(b->destination())) return true; |
| 253 return a->destination().CompareModuloType(b->destination()); | 253 return a->destination().CompareCanonicalized(b->destination()); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace | 256 } // namespace |
| 257 | 257 |
| 258 | 258 |
| 259 // Split multiple loads of the same constant or stack slot off into the second | 259 // Split multiple loads of the same constant or stack slot off into the second |
| 260 // slot and keep remaining moves in the first slot. | 260 // slot and keep remaining moves in the first slot. |
| 261 void MoveOptimizer::FinalizeMoves(Instruction* instr) { | 261 void MoveOptimizer::FinalizeMoves(Instruction* instr) { |
| 262 auto loads = temp_vector_0(); | 262 auto loads = temp_vector_0(); |
| 263 DCHECK(loads.empty()); | 263 DCHECK(loads.empty()); |
| 264 // Find all the loads. | 264 // Find all the loads. |
| 265 for (auto move : *instr->parallel_moves()[0]) { | 265 for (auto move : *instr->parallel_moves()[0]) { |
| 266 if (move->IsRedundant()) continue; | 266 if (move->IsRedundant()) continue; |
| 267 if (move->source().IsConstant() || IsSlot(move->source())) { | 267 if (move->source().IsConstant() || IsSlot(move->source())) { |
| 268 loads.push_back(move); | 268 loads.push_back(move); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 if (loads.empty()) return; | 271 if (loads.empty()) return; |
| 272 // Group the loads by source, moving the preferred destination to the | 272 // Group the loads by source, moving the preferred destination to the |
| 273 // beginning of the group. | 273 // beginning of the group. |
| 274 std::sort(loads.begin(), loads.end(), LoadCompare); | 274 std::sort(loads.begin(), loads.end(), LoadCompare); |
| 275 MoveOperands* group_begin = nullptr; | 275 MoveOperands* group_begin = nullptr; |
| 276 for (auto load : loads) { | 276 for (auto load : loads) { |
| 277 // New group. | 277 // New group. |
| 278 if (group_begin == nullptr || | 278 if (group_begin == nullptr || |
| 279 !load->source().EqualsModuloType(group_begin->source())) { | 279 !load->source().EqualsCanonicalized(group_begin->source())) { |
| 280 group_begin = load; | 280 group_begin = load; |
| 281 continue; | 281 continue; |
| 282 } | 282 } |
| 283 // Nothing to be gained from splitting here. | 283 // Nothing to be gained from splitting here. |
| 284 if (IsSlot(group_begin->destination())) continue; | 284 if (IsSlot(group_begin->destination())) continue; |
| 285 // Insert new move into slot 1. | 285 // Insert new move into slot 1. |
| 286 auto slot_1 = instr->GetOrCreateParallelMove( | 286 auto slot_1 = instr->GetOrCreateParallelMove( |
| 287 static_cast<Instruction::GapPosition>(1), code_zone()); | 287 static_cast<Instruction::GapPosition>(1), code_zone()); |
| 288 slot_1->AddMove(group_begin->destination(), load->destination()); | 288 slot_1->AddMove(group_begin->destination(), load->destination()); |
| 289 load->Eliminate(); | 289 load->Eliminate(); |
| 290 } | 290 } |
| 291 loads.clear(); | 291 loads.clear(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace compiler | 294 } // namespace compiler |
| 295 } // namespace internal | 295 } // namespace internal |
| 296 } // namespace v8 | 296 } // namespace v8 |
| OLD | NEW |