| 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 struct MoveKey { | 13 struct MoveKey { |
| 14 InstructionOperand source; | 14 InstructionOperand source; |
| 15 InstructionOperand destination; | 15 InstructionOperand destination; |
| 16 }; | 16 }; |
| 17 | 17 |
| 18 struct MoveKeyCompare { | 18 struct MoveKeyCompare { |
| 19 bool operator()(const MoveKey& a, const MoveKey& b) const { | 19 bool operator()(const MoveKey& a, const MoveKey& b) const { |
| 20 if (a.source.EqualsCanonicalized(b.source)) { | 20 if (a.source.EqualsCanonicalized(b.source)) { |
| 21 return a.destination.CompareCanonicalized(b.destination); | 21 return a.destination.CompareCanonicalized(b.destination); |
| 22 } | 22 } |
| 23 return a.source.CompareCanonicalized(b.source); | 23 return a.source.CompareCanonicalized(b.source); |
| 24 } | 24 } |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 struct OperandCompare { | |
| 28 bool operator()(const InstructionOperand& a, | |
| 29 const InstructionOperand& b) const { | |
| 30 return a.CompareCanonicalized(b); | |
| 31 } | |
| 32 }; | |
| 33 | |
| 34 typedef ZoneMap<MoveKey, unsigned, MoveKeyCompare> MoveMap; | 27 typedef ZoneMap<MoveKey, unsigned, MoveKeyCompare> MoveMap; |
| 35 typedef ZoneSet<InstructionOperand, CompareOperandModuloType> OperandSet; | 28 typedef ZoneSet<InstructionOperand, CompareOperandModuloType> OperandSet; |
| 36 | 29 |
| 37 | 30 |
| 38 int FindFirstNonEmptySlot(const Instruction* instr) { | 31 int FindFirstNonEmptySlot(const Instruction* instr) { |
| 39 int i = Instruction::FIRST_GAP_POSITION; | 32 int i = Instruction::FIRST_GAP_POSITION; |
| 40 for (; i <= Instruction::LAST_GAP_POSITION; i++) { | 33 for (; i <= Instruction::LAST_GAP_POSITION; i++) { |
| 41 ParallelMove* moves = instr->parallel_moves()[i]; | 34 ParallelMove* moves = instr->parallel_moves()[i]; |
| 42 if (moves == nullptr) continue; | 35 if (moves == nullptr) continue; |
| 43 for (MoveOperands* move : *moves) { | 36 for (MoveOperands* move : *moves) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } | 124 } |
| 132 } | 125 } |
| 133 } | 126 } |
| 134 | 127 |
| 135 void MoveOptimizer::MigrateMoves(Instruction* to, Instruction* from) { | 128 void MoveOptimizer::MigrateMoves(Instruction* to, Instruction* from) { |
| 136 if (from->IsCall()) return; | 129 if (from->IsCall()) return; |
| 137 | 130 |
| 138 ParallelMove* from_moves = from->parallel_moves()[0]; | 131 ParallelMove* from_moves = from->parallel_moves()[0]; |
| 139 if (from_moves == nullptr || from_moves->empty()) return; | 132 if (from_moves == nullptr || from_moves->empty()) return; |
| 140 | 133 |
| 141 ZoneSet<InstructionOperand, OperandCompare> dst_cant_be(local_zone()); | 134 OperandSet dst_cant_be(local_zone()); |
| 142 ZoneSet<InstructionOperand, OperandCompare> src_cant_be(local_zone()); | 135 OperandSet src_cant_be(local_zone()); |
| 143 | 136 |
| 144 // If an operand is an input to the instruction, we cannot move assignments | 137 // If an operand is an input to the instruction, we cannot move assignments |
| 145 // where it appears on the LHS. | 138 // where it appears on the LHS. |
| 146 for (size_t i = 0; i < from->InputCount(); ++i) { | 139 for (size_t i = 0; i < from->InputCount(); ++i) { |
| 147 dst_cant_be.insert(*from->InputAt(i)); | 140 dst_cant_be.insert(*from->InputAt(i)); |
| 148 } | 141 } |
| 149 // If an operand is output to the instruction, we cannot move assignments | 142 // If an operand is output to the instruction, we cannot move assignments |
| 150 // where it appears on the RHS, because we would lose its value before the | 143 // where it appears on the RHS, because we would lose its value before the |
| 151 // instruction. | 144 // instruction. |
| 152 // Same for temp operands. | 145 // Same for temp operands. |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 static_cast<Instruction::GapPosition>(1), code_zone()); | 471 static_cast<Instruction::GapPosition>(1), code_zone()); |
| 479 slot_1->AddMove(group_begin->destination(), load->destination()); | 472 slot_1->AddMove(group_begin->destination(), load->destination()); |
| 480 load->Eliminate(); | 473 load->Eliminate(); |
| 481 } | 474 } |
| 482 loads.clear(); | 475 loads.clear(); |
| 483 } | 476 } |
| 484 | 477 |
| 485 } // namespace compiler | 478 } // namespace compiler |
| 486 } // namespace internal | 479 } // namespace internal |
| 487 } // namespace v8 | 480 } // namespace v8 |
| OLD | NEW |