move-optimizer.h 2.23 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_
#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 13 14 15

namespace v8 {
namespace internal {
namespace compiler {

16
class V8_EXPORT_PRIVATE MoveOptimizer final {
17 18
 public:
  MoveOptimizer(Zone* local_zone, InstructionSequence* code);
19 20 21
  MoveOptimizer(const MoveOptimizer&) = delete;
  MoveOptimizer& operator=(const MoveOptimizer&) = delete;

22 23 24
  void Run();

 private:
25 26
  using MoveOpVector = ZoneVector<MoveOperands*>;
  using Instructions = ZoneVector<Instruction*>;
27 28 29 30

  InstructionSequence* code() const { return code_; }
  Zone* local_zone() const { return local_zone_; }
  Zone* code_zone() const { return code()->zone(); }
31
  MoveOpVector& local_vector() { return local_vector_; }
32

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  // Consolidate moves into the first gap.
  void CompressGaps(Instruction* instr);

  // Attempt to push down to the last instruction those moves that can.
  void CompressBlock(InstructionBlock* block);

  // Consolidate moves into the first gap.
  void CompressMoves(ParallelMove* left, MoveOpVector* right);

  // Push down those moves in the gap of from that do not change the
  // semantics of the from instruction, nor the semantics of the moves
  // that remain behind.
  void MigrateMoves(Instruction* to, Instruction* from);

  void RemoveClobberedDestinations(Instruction* instruction);

mtrofin's avatar
mtrofin committed
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 56

  Zone* const local_zone_;
  InstructionSequence* const code_;
57
  MoveOpVector local_vector_;
58

59 60 61 62
  // Reusable buffers for storing operand sets. We need at most two sets
  // at any given time, so we create two buffers.
  ZoneVector<InstructionOperand> operand_buffer1;
  ZoneVector<InstructionOperand> operand_buffer2;
63 64 65 66 67 68
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

69
#endif  // V8_COMPILER_BACKEND_MOVE_OPTIMIZER_H_