Emily Bernier | 958fae7 | 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 | |
Rubin Xu | 2894c6a | 2019-02-07 16:01:35 +0000 | [diff] [blame] | 5 | #ifndef V8_COMPILER_MOVE_OPTIMIZER_H_ |
| 6 | #define V8_COMPILER_MOVE_OPTIMIZER_H_ |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 7 | |
| 8 | #include "src/compiler/instruction.h" |
Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame] | 9 | #include "src/globals.h" |
Ben Murdoch | f3b273f | 2017-01-17 12:11:28 +0000 | [diff] [blame] | 10 | #include "src/zone/zone-containers.h" |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 11 | |
| 12 | namespace v8 { |
| 13 | namespace internal { |
| 14 | namespace compiler { |
| 15 | |
Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame] | 16 | class V8_EXPORT_PRIVATE MoveOptimizer final { |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 17 | public: |
| 18 | MoveOptimizer(Zone* local_zone, InstructionSequence* code); |
| 19 | void Run(); |
| 20 | |
| 21 | private: |
| 22 | typedef ZoneVector<MoveOperands*> MoveOpVector; |
Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 23 | typedef ZoneVector<Instruction*> Instructions; |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 24 | |
| 25 | InstructionSequence* code() const { return code_; } |
| 26 | Zone* local_zone() const { return local_zone_; } |
| 27 | Zone* code_zone() const { return code()->zone(); } |
Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | MoveOpVector& local_vector() { return local_vector_; } |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 29 | |
Ben Murdoch | 109988c | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 30 | // Consolidate moves into the first gap. |
| 31 | void CompressGaps(Instruction* instr); |
| 32 | |
| 33 | // Attempt to push down to the last instruction those moves that can. |
| 34 | void CompressBlock(InstructionBlock* block); |
| 35 | |
| 36 | // Consolidate moves into the first gap. |
| 37 | void CompressMoves(ParallelMove* left, MoveOpVector* right); |
| 38 | |
| 39 | // Push down those moves in the gap of from that do not change the |
| 40 | // semantics of the from instruction, nor the semantics of the moves |
| 41 | // that remain behind. |
| 42 | void MigrateMoves(Instruction* to, Instruction* from); |
| 43 | |
| 44 | void RemoveClobberedDestinations(Instruction* instruction); |
| 45 | |
Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 46 | const Instruction* LastInstruction(const InstructionBlock* block) const; |
Ben Murdoch | 109988c | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 47 | |
Rubin Xu | 2894c6a | 2019-02-07 16:01:35 +0000 | [diff] [blame] | 48 | // Consolidate common moves appearing across all predecessors of a block. |
Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | void OptimizeMerge(InstructionBlock* block); |
| 50 | void FinalizeMoves(Instruction* instr); |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 51 | |
| 52 | Zone* const local_zone_; |
| 53 | InstructionSequence* const code_; |
Ben Murdoch | 014dc51 | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 54 | MoveOpVector local_vector_; |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 55 | |
Ben Murdoch | c8c1d9e | 2017-03-08 14:04:23 +0000 | [diff] [blame] | 56 | // Reusable buffers for storing operand sets. We need at most two sets |
| 57 | // at any given time, so we create two buffers. |
| 58 | ZoneVector<InstructionOperand> operand_buffer1; |
| 59 | ZoneVector<InstructionOperand> operand_buffer2; |
| 60 | |
Emily Bernier | 958fae7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 61 | DISALLOW_COPY_AND_ASSIGN(MoveOptimizer); |
| 62 | }; |
| 63 | |
| 64 | } // namespace compiler |
| 65 | } // namespace internal |
| 66 | } // namespace v8 |
| 67 | |
Rubin Xu | 2894c6a | 2019-02-07 16:01:35 +0000 | [diff] [blame] | 68 | #endif // V8_COMPILER_MOVE_OPTIMIZER_H_ |