Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_COMPILER_MOVE_OPTIMIZER_ |
| 6 | #define V8_COMPILER_MOVE_OPTIMIZER_ |
| 7 | |
| 8 | #include "src/compiler/instruction.h" |
| 9 | #include "src/zone-containers.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | namespace compiler { |
| 14 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 15 | class MoveOptimizer final { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 16 | public: |
| 17 | MoveOptimizer(Zone* local_zone, InstructionSequence* code); |
| 18 | void Run(); |
| 19 | |
| 20 | private: |
| 21 | typedef ZoneVector<MoveOperands*> MoveOpVector; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 22 | typedef ZoneVector<Instruction*> Instructions; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 23 | |
| 24 | InstructionSequence* code() const { return code_; } |
| 25 | Zone* local_zone() const { return local_zone_; } |
| 26 | Zone* code_zone() const { return code()->zone(); } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | MoveOpVector& local_vector() { return local_vector_; } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 28 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 29 | // Consolidate moves into the first gap. |
| 30 | void CompressGaps(Instruction* instr); |
| 31 | |
| 32 | // Attempt to push down to the last instruction those moves that can. |
| 33 | void CompressBlock(InstructionBlock* block); |
| 34 | |
| 35 | // Consolidate moves into the first gap. |
| 36 | void CompressMoves(ParallelMove* left, MoveOpVector* right); |
| 37 | |
| 38 | // Push down those moves in the gap of from that do not change the |
| 39 | // semantics of the from instruction, nor the semantics of the moves |
| 40 | // that remain behind. |
| 41 | void MigrateMoves(Instruction* to, Instruction* from); |
| 42 | |
| 43 | void RemoveClobberedDestinations(Instruction* instruction); |
| 44 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 45 | const Instruction* LastInstruction(const InstructionBlock* block) const; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 46 | |
| 47 | // Consolidate common moves appearing accross all predecessors of a block. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | void OptimizeMerge(InstructionBlock* block); |
| 49 | void FinalizeMoves(Instruction* instr); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 50 | |
| 51 | Zone* const local_zone_; |
| 52 | InstructionSequence* const code_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 53 | MoveOpVector local_vector_; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(MoveOptimizer); |
| 56 | }; |
| 57 | |
| 58 | } // namespace compiler |
| 59 | } // namespace internal |
| 60 | } // namespace v8 |
| 61 | |
| 62 | #endif // V8_COMPILER_MOVE_OPTIMIZER_ |