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_BACKEND_MOVE_OPTIMIZER_H_ 6 #define V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_ 7 8 #include "src/common/globals.h" 9 #include "src/compiler/backend/instruction.h" 10 #include "src/zone/zone-containers.h" 11 12 namespace v8 { 13 namespace internal { 14 namespace compiler { 15 16 class V8_EXPORT_PRIVATE MoveOptimizer final { 17 public: 18 MoveOptimizer(Zone* local_zone, InstructionSequence* code); 19 MoveOptimizer(const MoveOptimizer&) = delete; 20 MoveOptimizer& operator=(const MoveOptimizer&) = delete; 21 22 void Run(); 23 24 private: 25 using MoveOpVector = ZoneVector<MoveOperands*>; 26 using Instructions = ZoneVector<Instruction*>; 27 code()28 InstructionSequence* code() const { return code_; } local_zone()29 Zone* local_zone() const { return local_zone_; } code_zone()30 Zone* code_zone() const { return code()->zone(); } local_vector()31 MoveOpVector& local_vector() { return local_vector_; } 32 33 // Consolidate moves into the first gap. 34 void CompressGaps(Instruction* instr); 35 36 // Attempt to push down to the last instruction those moves that can. 37 void CompressBlock(InstructionBlock* block); 38 39 // Consolidate moves into the first gap. 40 void CompressMoves(ParallelMove* left, MoveOpVector* right); 41 42 // Push down those moves in the gap of from that do not change the 43 // semantics of the from instruction, nor the semantics of the moves 44 // that remain behind. 45 void MigrateMoves(Instruction* to, Instruction* from); 46 47 void RemoveClobberedDestinations(Instruction* instruction); 48 49 const Instruction* LastInstruction(const InstructionBlock* block) const; 50 51 // Consolidate common moves appearing across all predecessors of a block. 52 void OptimizeMerge(InstructionBlock* block); 53 void FinalizeMoves(Instruction* instr); 54 55 Zone* const local_zone_; 56 InstructionSequence* const code_; 57 MoveOpVector local_vector_; 58 59 // Reusable buffers for storing operand sets. We need at most two sets 60 // at any given time, so we create two buffers. 61 ZoneVector<InstructionOperand> operand_buffer1; 62 ZoneVector<InstructionOperand> operand_buffer2; 63 }; 64 65 } // namespace compiler 66 } // namespace internal 67 } // namespace v8 68 69 #endif // V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_ 70